// JavaScript Document
$(document).ready(function() {
		
		/* Form blur and focus */
		$(":input").focus(function(){
			var contents = $(this).val();
			$(this).val("");
			$(this).siblings("label").addClass("activeLabel");
		});
		
		$(":input").blur(function(){
			$(this).val(contents);
			$(this).siblings("label").removeClass("activeLabel");
		});

		/* Set up carousel */
		 var contents;
		 var listLength = $("ul.itemList li").length; // get the number of items in the list
		 var intervalID; 
		 var i = 0; // set the counter
		 
		 function playCarousel(){
		 	intervalID = setInterval(stepThrough, 8000); //triggers the stepThrough function every x seconds (divide the number by 1,000)
		 }
	  	 $("ul.itemList li").eq(i).addClass("active");
		 $(".content div").eq(i).addClass("active");
		 
         function stepThrough(){ 
		  	$("ul.itemList li").removeClass("active");
//			$(".content div").css({'opacity': '0'});
			$(".content div").removeClass("active");
		    if((Math.abs(i))<(listLength-1)){ // if the counter is less than the total # in list (ie not yet at the end)...
				  i++; // ... add 1 to i...
			} else {
			  	  i=0; // ...otherwise set i to 0 (which will make it go back to the start)
			}
			//alert(i);
			$("ul.itemList li").eq(i).addClass("active");
			$(".content div").eq(i).addClass("active");
//			$(".content div").eq(i).css({'opacity': '1'});
		 }
		 
		 $('a.forward').click(function(event) {		
			 stepThrough();
			 clearInterval(intervalID);
			 playCarousel();
		});
		$('a.back').click(function(event) {
			 if((Math.abs(i))==0){ // if the counter is at the first slide (remember the array is zero based)...
				 i=(listLength-2); // ... add 1 to i...
			} else {
			     i = i - 2; // ...otherwise set i back
			}
			
			stepThrough();
			clearInterval(intervalID);
			playCarousel();
		});

		$('ul.itemList li').mouseover(function(event) {
			 $("ul.itemList li").removeClass("active");
			 $(this).addClass("active");
//			 $(".content div").css({'opacity': '0'});
			 
			 $("ul.itemList li").each(function (e) {
					if($(this).attr('class') == "active"){
						i = e;
						$(".content div").removeClass("active");
			 			$(".content div").eq(e).addClass("active");
//						$(".content div").eq(e).css({'opacity': '1'});
					}
			});
			 clearInterval(intervalID);
			 //playCarousel();
		});
		
		$('ul.itemList li').mouseout(function(event) {
			 playCarousel();
		});
		playCarousel();

	/* youTube video API*/
	function onYouTubePlayerReady(playerId) {
 		ytplayer = document.getElementById("myytplayer");
 	}

	function stopVid() {
	 	if (ytplayer) {
	 		ytplayer.stopVideo();
	 	}
	} 
	
	/* Video open */
	$("#videoOpen").click(function(e){
		$("#videoHolder").toggleClass("hide");
		return false;
	});
	$("#videoHolder .background a, .videoPlayer").click(function(e){
		$("#videoHolder").toggleClass("hide");
		return false;
	});
 });
