// JavaScript Document
//Author: Jeff Mulder

//when documents loaded
jQuery(document).ready(function(){
	var imgWidth = jQuery("ul#home_banner_images li").width();
	var imgNumber = jQuery("#home_banner_images li").length;	
	var bannerWidth = imgWidth * imgNumber;
	
	//add a thumb for each image
	jQuery("ul#home_banner_images li").each(function() {
		jQuery('ul#home_banner_thumbs').append('<li></li>');
	});
	//addClass active to first thumb
	jQuery('#home_banner_thumbs li:first').addClass("active");
	
	
	//set home_banner_images width to bannerWidth
	jQuery("ul#home_banner_images").css({width: bannerWidth});
	//selecting first video link and addClass active 
	jQuery(".video_link_home:first").addClass("active");	
	//selecing all other video links and fadeOut
	jQuery(".video_link_home:not(.active)").fadeOut(0);
	
	jQuery("ul#home_banner_thumbs li").bind({							  
		click: function() {	
			var listIndex = jQuery(this).index('#home_banner_thumbs li');
			
			animateHomeBanner(listIndex);
		},
		mouseenter: function() {
			
		},
		mouseleave: function() {
			
		}
	});

	//----------------------------------Home Timer------------------------------------------------//
	
	
	jQuery("#home_banner").hover(function() {
		jQuery("#home_banner").stopTime();
	}, function () {
		activateBannerTimer();
	});

	//activatBannerTimer(); is being called from the index.php page.  It was causing errors here.  
  		
	
});



function activateBannerTimer() {
		jQuery('#home_banner').everyTime("5s", function() {
			var listIndex = jQuery('#home_banner_thumbs li.active').next('li').index('#home_banner_thumbs li');
			if(listIndex<=0)
				listIndex = 0;
											   
			animateHomeBanner(listIndex);
		});
	}
	
function animateHomeBanner(listIndex) {
	//fade out video links
	jQuery(".video_link_home:not(.active)").stop().fadeOut(0);			
	
	//set new left value
	var newLeftValue = (-(listIndex) * 960);
	
	jQuery('#home_banner_images').stop().animate({left: newLeftValue + "px"}, 1500, function(){
																																															
		jQuery(".video_link_home").removeClass("active");																																								 
		jQuery("#home_banner_images li").eq(listIndex).find(".video_link_home").addClass("active").stop().fadeIn(1000);																															 
	});
	jQuery('#home_banner_thumbs li').removeClass('active');
	jQuery('#home_banner_thumbs li').eq(listIndex).addClass('active');
}
