/*
	Created By: Aaron Tennyson @ BT Solutions, LLC
	Date: May 11, 2010
	Copyright 2010 BT Solutions, LLC
*/	

function changeImage3(){
	$('#slide1').css('background-image', 'url(imgs/title-1-off.png)');
	$('#slide2').css('background-image', 'url(imgs/title-2-off.png)');
	$('#slide3').css('background-image', 'url(imgs/title-3-on.png)');
}
function changeImage2(){
	$('#slide1').css('background-image', 'url(imgs/title-1-off.png)');
	$('#slide2').css('background-image', 'url(imgs/title-2-on.png)');
	$('#slide3').css('background-image', 'url(imgs/title-3-off.png)');
}
function changeImage1(){
	$('#slide1').css('background-image', 'url(imgs/title-1-on.png)');
	$('#slide2').css('background-image', 'url(imgs/title-2-off.png)');
	$('#slide3').css('background-image', 'url(imgs/title-3-off.png)');
}

var s0, s1, s2, s3;

function accordionslide0(rate,autodelay){
			
	$('#box2').animate({width:0},{duration:10});
	$('#box3').animate({width:0},{duration:10});
	$('#box1').animate({width:840},{duration:350});
	
	//change out tab image
	changeImage1();
	s0 = setTimeout(function(){accordionslide1()}, 4000);

}
function accordionslide1(rate,autodelay){
	clearTimeout(s0);
	clearTimeout(s2);
	clearTimeout(s3);
	$('#box2').animate({width:0},{duration:350});
	$('#box3').animate({width:0},{duration:350});
	$('#box1').animate({width:840},{duration:350});
	
	
	//change out tab image
	changeImage1();
	s1 = setTimeout(function(){accordionslide2()}, 4000);
}

function accordionslide2(rate,autodelay){
	clearTimeout(s0);
	clearTimeout(s1); 
	clearTimeout(s3);
	//alert('slide2');
	//var xx=2;
	//var curSlide="#slide1";
	//var tab = $('#slide1').find('h3'),
	//visible = $('box2');
	//alert(width);
	//hide all but first panel, set width to zero for animate function to work
	//$('#slide1').css({display:'none', width:0});
	
	$('#box1').animate({width:0},{duration:350});
	$('#box2').animate({width:840},{duration:350});
	$('#box3').animate({width:0},{duration:350});
	
	//change out tab image
	changeImage2();
	s2 = setTimeout(function(){accordionslide3()}, 4000);
}

function accordionslide3(rate,autodelay){
	clearTimeout(s0);
	clearTimeout(s1); 
	clearTimeout(s2);
	//alert('slide2');
	//var xx=2;
	//var curSlide="#slide2";
	//var tab = $('#slide2').find('h3'),
	//visible = $('box3');
	//alert(width);
	//hide all but first panel, set width to zero for animate function to work
	//$('#slide1').css({display:'none', width:0});
	
	$('#box1').animate({width:0},{duration:350});
	$('#box2').animate({width:0},{duration:350});
	$('#box3').animate({width:840},{duration:350});
	
	//change out tab image
	changeImage3();
	s3 = setTimeout(function(){accordionslide1()}, 4000);
}

function accordion(rate,autodelay){
	var xx=2;
	var curSlide="#slide";
	var tab = $('#sliderWrapper').find('h3'),
	visible = tab.next().filter(':last'),
	width = visible.outerWidth();
		
		//hide all but first panel, set width to zero for animate function to work
		tab.next().filter(':not(:last)').css({display:'none', width:0});
		
		//attach click handler
		tab.click(function(){
			//clearTimeout(timeout);		   
			if(visible.prev()[0] == this){
				return;
			}
			visible.animate({width:0},{duration:rate});
			visible = $(this).next().animate({width:width},{duration:rate});
			//alert(visible.id);//2
			// change out background of xx and xx+1
			if(xx==1){
				//alert(curSlide+xx);
				xy=3;
				$(curSlide+xx).css('background-image', 'url(imgs/title-' + xx + '-on.png)');
				$(curSlide+xy).css('background-image', 'url(imgs/title-' + xy + '-off.png)');
				
			}else{
				//alert(curSlide+xx);
				xy=xx-1;
				$(curSlide+xx).css('background-image', 'url(imgs/title-' + xx + '-on.png)');
				$(curSlide+xy).css('background-image', 'url(imgs/title-' + xy + '-off.png)');
			}
			//$('#slide1').css('background-color', '#000');
			//var timeout = setTimeout(function(){
//				if(xx==4){xx=1}; //reset counter to show slide 1
//				$(curSlide+xx).triggerHandler('click');
//				xx=xx+1; // show next slide
//				
//			}, 4000);				
								
		});
		
		//Wait for 5 seconds for movies to load before setting the interval
		setTimeout(function(){
				//$('#slide2').triggerHandler('click');		
				//xx=xx+1;
			setInterval(function(){
				if(xx==4){xx=1}; //reset counter to show slide 1
				var curSlide="#slide";
				$(curSlide+xx).triggerHandler('click');
				xx=xx+1; // show next slide
			},autodelay);
//			
		}, 4000);
		//}, 2000);
		
};

$(document).ready(function(){
	//accordion(350,4000);
	accordionslide0(350,4000);
});
