var stopScripts = true;

var Acc = new Class({
	options:{
		period:5000
	},
	initialize: function(main_id , handler_class , box_class){
		var $this = this;
		this.togglers = $$(handler_class);
		this.counter = 0;
		this.ac = new Accordion($(main_id), handler_class, box_class, {
			opacity:false,
			onActive: function(toggler, element){
				toggler.className = 'soTltH'
			},
			onBackground: function(toggler, element){
				toggler.className = 'soTlt';
				$this.counter = this.previous+1;
			}
		});
		this.accTimer = (function(){
			$this.fireDelay();
		}).periodical(this.options.period);
		$(main_id).addEvents({
			'mouseenter': function(){
				$clear($this.accTimer);
			},
			'mouseleave': function(e){
				ev = new Event(e);
				ev.stopPropagation();
				$this.accTimer = (function(){
					$this.fireDelay();
				}).periodical($this.options.period);
			}
		});
		this.makeEv();
	},
	makeEv: function(){
		var $this = this;
		this.togglers.each(function(item){
			item.addEvent('mouseenter',function(ev){
				$clear($this.accTimer);
				ev.stop();
				item.fireEvent('click');
			});
		})
	},
	fireDelay: function(){
		if(stopScripts)
			return;
		if(this.counter<this.togglers.length){
			this.togglers[this.counter].fireEvent('click');
			//this.counter++;
			return;
		}
		if(this.counter>=this.togglers.length){
			this.counter=0;
			this.togglers[this.counter].fireEvent('click');
			//this.counter++;
		}
	}
});
Acc.implement(new Options);

window.addEvent('domready', function(){
    var aa = new Acc('soPnlBdy','.soTlt','.soCnt',{period:5000});
    
    
	var slidetime = 5000; //3 seconds between changes
	var periodical;
	var activeItem;
	var started = 0;
	
	/*$('promoPnl').removeClass('noscript'); *///remove noscript class, for obvious reasons
	
	//get all the slideshow items
	var items = $('promoPnl').getElements('.slideshow-item');
	var itemsLength = items.length;
	
	for(var i=0; i<itemsLength; i++)
	{
		//if we're not on the first one, hide it
		if(i != itemsLength-1)
		{
			items[i].fade('hide');
		}
		else
		{
			activeItem = items[i].id;
		}
	}

	function rotate()
	{
		if(started == 1)
		{
			//get the number we're dealing with (item-#) so that we can work out whether the # is the last item or not
			var activeNumber = activeItem.split('-');
			activeNumber = activeNumber[1];
			
			if(activeNumber == itemsLength) //are we on the last item? if so start back at the beginning.
			{
				newItemNumber = 1;
			}
			else //otherwise just add 1 to the last active id
			{
				newItemNumber = (parseInt(activeNumber)+1);
			}
			
			$('item-'+newItemNumber).fade('in');
			$(activeItem).fade('out');
			activeItem = 'item-'+newItemNumber;
		}
		else
		{
			started = 1;
		}
		
		$clear(periodical); //clear the timer
		periodical = rotate.periodical(slidetime); //repeat!
	}

	rotate();    
});