// JQuery JavaScript Document
$(document).ready(function(){

	/*
	 * Global vars
	 */
	 var s = 0;
	 var n = $(".home-thumb-list ul li").length;
	 $(".home-thumb-list ul li").bind("mouseenter",hoverItem); 
	 $("#thumb-select").click(function () {
	 	window.location = $(".home-thumb-list ul li:eq("+s+") > a").attr("href");
	 });

	/*
	* function mouse enter Motion
	*/
	function hoverItem(){
		clearInterval(gallery_interval);
		s = $(".home-thumb-list ul li").index(this);
		showItem();
	}
	
	function showItem(){
		var yPos = s*64;
		$("#thumb-select").animate({top: yPos}, "fast");
		
		// hide unselected main content and show selection
		if( $(".home-content-list ul li:eq("+s+")").css("display") == "none") {
			for(var i=0; i<n; i++){
				if(i != s){
					hideHeader(i);
					$(".home-content-list ul li:eq("+i+")").fadeOut("slow", function () {
						$(".home-content-list ul li:eq("+s+")").fadeIn("slow", toggleHeader);
					});
				}
			}
		}
	}
	
	 /* 
	 * function galleryTimer
	 * this timer cycles through the images
	 */
	 function galleryTimer() {
		//hideHeader(s);
		if(s < n-1) {
			s++;
		} else {
			s=0;
		}
		showItem();
	 }
	 
	 /* 
	 * function showHeader
	 * reveal animation to display the H2 header
	 */
	 function toggleHeader() {
		var hdr = $(".home-content-list ul li:eq(" + s + ") > h2");
		if(hdr.css("display") == "none") {
			$(hdr).animate({opacity: 0.9}, "slow");
			$(hdr).show("slow");
		}
	 }
	
	
	 /* 
	 * function hideHeader
	 * hide the H2 header
	 */
	 function hideHeader(n) {
		var hdr = $(".home-content-list ul li:eq(" + n + ") > h2");
		if(hdr.css("display") != "none") {
			$(hdr).hide();
		}
	 }
	 
	/* 
	 * function selectThumbnail
	 * hide the H2 header
	 */
	 function clickItem() {
		window.location=$(this).find("a").attr("href"); return false;
	 }
	 
	 /*
	 * Initialize script
	 */
	 showItem();
	 gallery_interval = setInterval(galleryTimer,7000);
 
 });	