var large_ad_rot = new Class({
	initialize: function(container, selectors, time, dir){
		var root = this;
		this.container = $(container); //ID of container element
		this.selectors = $(selectors); //ID of selectors container element
		this.time = time; //transition time in milliseconds
		this.dir = dir; //base path for images
		this.width = 604;
		this.current_ad = 0;
		this.ads = this.container.getElements('img');
		var i = 0;
		this.ads.each(function(el){
			if(i == 0){
				el.setStyle('margin-left', '0px');
			}else{
				el.setStyle('display', 'none');
			}
			el.number = i;
			var selector  = new Element('div', {id: container + '_selector' + i});
			selector.addClass('selector');
			selector.set({html: '<span>' + (i+1) + '</span>'});
			selector.inject(root.selectors);
			selector.number = i;
			if(i==0){selector.morph('.large_ad_rot_selector_current');}
			selector.addEvent('mouseenter', function(e){if(root.current_ad != selector.number){selector.morph('.large_ad_rot_selector_over')}});
			selector.addEvent('mouseleave', function(e){if(root.current_ad != selector.number){selector.morph('.large_ad_rot_selector_normal')}});
			selector.addEvent('click', function(e){if(root.current_ad != selector.number){root.slide_left(selector.number)}else{root.reset_timer();}});
			i++;
		});
		this.show_next = this.slide_left.delay(this.time, this, 1);
	},
	slide_left: function(el_num){		if(this.ads.length < 2){ return false; };
		this.show_next = $clear(this.show_next);
		var cs = $(this.container.id + '_selector' + this.current_ad); //grab the current ad's selector div
		cs.morph('.large_ad_rot_selector_normal');
		var dur = 1000;
		var sel_el = this.ads[el_num]; //element to show
		var c_el = this.ads[this.current_ad]; //element to hide
		c_el.set('tween', {duration: dur*.8, transition: Fx.Transitions.Quad.easeInOut, onComplete: function(e){c_el.setStyle('display', 'none')}});
		c_el.tween('margin-left', this.width * -1 + 'px');
		sel_el.setStyle('margin-left', this.width + 'px');
		sel_el.setStyle('display', 'block');
		sel_el.set('tween', {duration: dur, transition: Fx.Transitions.Quad.easeInOut});
		sel_el.tween('margin-left', '0px');
		$(this.container.id + '_selector' + el_num).morph('.large_ad_rot_selector_current');
		this.current_ad = sel_el.number;
		this.show_next = this.slide_left.delay(this.time, this, (this.current_ad == this.ads.length-1) ? 0: this.current_ad+1);
	},
	reset_timer: function(){
		this.show_next = $clear(this.show_next);
		this.show_next = this.slide_left.delay(this.time, this, (this.current_ad == this.ads.length-1) ? 0: this.current_ad+1);
	}
});
