$(window).load(function() {
	
	//Variables I need...
	var counter	=	1;
	var timerSecond= 6000;
	var playStatus = 1;
	
	//Prepare the board
	$('#slides li:gt(0)').hide();
	
	//Fade in controls
	//$('#controls').css('filter', 'none');
	//$('#controls').hide().fadeIn(1000);
	 
	$('#spinner').css("display", "none");
	$('#slides').css("display", "block");
	
	//Slide Timing and Playing
	function slider(){
			//alert(counter);
			if (playStatus != 0 ){
			$('#slides .intro1-text').hide();
			
			$('#slides .intro2-side').hide();
			$('#slides .intro2-side').css('right','-316px');
			
			$('#slides .intro3-side').hide();
			$('#slides .intro3-side').css('right','-319px');
			
			$('#slides .intro4-side').hide();
			$('#slides .intro4-side').css('right','-316px');
			
			$('#slides .eco1-text').hide();
			
			$('#slides .eco2-leaf').hide();
			
			$('#slides .eco2-side').hide();
			$('#slides .eco2-side').css('right','-322px');
			
			$('#slides .myphyscap1-text').hide();
			
			$('#slides .myphyscap2-text').hide();
			$('#slides .myphyscap2-text').css({'marginLeft':'0', 'opacity':'0'});
			
			$('#slides .myphyscap3-text').hide();
			$('#slides .myphyscap3-text').css({'marginLeft':'0', 'opacity':'0'})
			
			$('#slides .myphyscap4-text').hide();
			$('#slides .myphyscap4-text').css({'marginLeft':'0', 'opacity':'0'})
		
			$('#slides .myphyscap5-text').hide();
			$('#slides .myphyscap5-text').css({'marginLeft':'0', 'opacity':'0'});
			
			$('#slides .path1-text').hide();
			$('#slides .path1-text').css({'marginLeft':'0', 'opacity':'0'});
			}
		play = setInterval(function(){
			//alert("counter: " + counter);
		
			if(counter == 5)
			{
				clearInterval(play);
				timerSecond = 9000;	
				slider();
			}
			else 
			{
				clearInterval(play);
				timerSecond = 6000;	
				slider();
			}
			
			$('#slides li:first-child').fadeOut().next('li').fadeIn().end().appendTo('#slides');
		
		//Counter incrimenting
			
			if(counter < $('#slides li').size()) {
				
				counter++;
			}
			else {
				counter = 1;
			}
			
			
			//alert("second: "+timerSecond);
			//alert("counter: " + counter);
		//Run Animations one slide change
		animations();
		//alert(timerSecond);
		},timerSecond);
	};
	


	function animations(){
	
		if(counter == 1){
			//alert("slide1");
			$('#slides .intro1-text').hide().delay(500).fadeIn('slow');
		}
		if(counter == 2){
			//alert("slide2");
			$('#slides .intro2-side').show();
			$('#slides .intro2-side').css('right','-316px').delay(1000).animate({right:'0'}, 1000, 'swing');
		}
		if(counter == 3){
			$('#slides .intro3-side').show();
			$('#slides .intro3-side').css('right','-319px')
				.delay(1000)
				.animate({right:'0'}, 1000, 'swing');
		}
		if(counter == 4){
			$('#slides .intro4-side').show();
			$('#slides .intro4-side').css('right','-316px')
				.delay(1000)
				.animate({right:'0'}, 1000, 'swing');
		}
		if(counter == 5){
			
			$('#slides .eco1-text').hide()
				.delay(500)
				.fadeIn('slow');
		}
		if(counter == 6){
			
			$('#slides .eco2-leaf').hide()
				.delay(500)
				.fadeIn('slow');
			$('#slides .eco2-side').show();	
			$('#slides .eco2-side').css('right','-322px')
				.delay(1000)
				.animate({right:'0'}, 1000, 'swing');
		}
		if(counter == 7){
			
			$('#slides .myphyscap1-text').hide()
				.delay(500)
				.fadeIn('slow');
		}
		if(counter == 8){
			$('#slides .myphyscap2-text').show();
			$('#slides .myphyscap2-text').css({'marginLeft':'-100px', 'opacity':'0'})
				.delay(500)
				.animate({marginLeft:'0', opacity:'1'}, 500);
		}
		if(counter == 9){
			$('#slides .myphyscap3-text').show();
			$('#slides .myphyscap3-text').css({'marginLeft':'-100px', 'opacity':'0'})
				.delay(500)
				.animate({marginLeft:'0', opacity:'1'}, 500);
		}
		if(counter == 10){
			$('#slides .myphyscap4-text').show();
			$('#slides .myphyscap4-text').css({'marginLeft':'-100px', 'opacity':'0'})
				.delay(500)
				.animate({marginLeft:'0', opacity:'1'}, 500);
		}
		if(counter == 11){
			$('#slides .myphyscap5-text').show();
			$('#slides .myphyscap5-text').css({'marginLeft':'-50px', 'opacity':'0'})
				.delay(500)
				.animate({marginLeft:'0', opacity:'1'}, 500);
		}
		if(counter == 12){
			$('#slides .path1-text').show();
			$('#slides .path1-text').css({'marginLeft':'-50px', 'opacity':'0'})
				.delay(500)
				.animate({marginLeft:'0', opacity:'1'}, 500);
		}

	}

	
	//Pause Button
	$('#controls .pause').click(
		function(){
			clearInterval(play);
			playStatus =0;
			$(this).hide();
			$('#controls .play').show();
		}
	);
	
	//Play Button
	$('#controls .play').click(
		function(){
			
			slider();
			playStatus =1;
			$(this).hide();
			$('#controls .pause').show();
		}
	);
	
	//Next Button
	$('#controls .next').click(
		function(){
			clearInterval(play);
			$('#slides li:first-child').fadeOut().next('li').fadeIn().end().appendTo('#slides');

			if(counter < $('#slides li').size()) {
				
				counter++;
			}
			else {
				counter = 1;
			}
			
			//Resume playing only if not paused
			if($('#controls .play').is(':hidden')){
				slider();
			}			
			animations();

		}
	);
	
	//Prev Button
	$('#controls .prev').click(
		function(){
			clearInterval(play);
			$('#slides li:first-child').fadeOut();
			$('#slides li:last-child').fadeIn().prependTo('#slides');
		
			counter--;
			
			if(counter < 1 ){
				counter = $('#slides li').size();
			}
		
			//Resume playing only if not paused
			if($('#controls .play').is(':hidden')){
				slider();
			}
			animations();

		}
	);
	

	//Star the slider
	slider();
	//Run animations the first time...
	animations();
	

});


