igloo = (function($){	
	_carousel = function(){
   var maxItemsInCarousel   = 20;
   var listItems = $(".carousel_content li");
    //Set onLoad styles...
   //Remove any extra li items
   if(listItems.length>maxItemsInCarousel){
      var extraListItems = listItems.slice(maxItemsInCarousel);
      extraListItems.each(function(){$(this).remove();});
   }
   //Init JCarousel Lite
   $(".carousel_content").jCarouselLite({
      btnPrev   : ".prev",
      btnNext   : ".next",
      scroll    : 1,
      visible   : 6,
      speed     : 350,
      afterEnd : function(item, isAutoScroll){
         var itemsPerPage = 6; //should be same as visible setting
         var allItems = $(item[0]).parent().children();
         var length = allItems.length;
         //get current itemNum using item array passed in which list all 
         //items currently displayed
         var itemNum = allItems.index(item[0])+1;
         // figure out what page is displayed this is tricky since this version
         // of JCarousel adds two extra pages to give the illusion of a true carousel
         itemNum = itemNum<=itemsPerPage
            ? length-itemNum-itemsPerPage*2
            : itemNum>=length-itemsPerPage
               ? itemNum-(length-itemsPerPage) 
               : itemNum-itemsPerPage;
         var page = parseInt(itemNum/itemsPerPage) + (itemNum%itemsPerPage ? 1 : 0);
      }
   });
   // Hover button change.
 	$(".prev").hover(
      function(){ $(this).css({ "background-position" :"0 -38px" }); },
      function(){ $(this).css({ "background-position" :"0 0" }); }
   );
   $(".next").hover(
      function(){ $(this).css({ "background-position" :"-66px -38px" }); },
      function(){ $(this).css({ "background-position" :"-66px 0px" }); }
   );
},
		
	_self = {
		init: function(){		
			_carousel();		
		}	
	}	
	return _self;			
})(jQuery);

videohighlight = (function($){	
	_videocarousel = function(){
	var carouselContainer = "#video_carousel";
   var pageNumberColor_on   = "url('/images/home/video_hl_indicator.gif') no-repeat", 
   	   pageNumberColor_off  = "url('/images/home/video_hl_indicator.gif') no-repeat";
   var maxItemsInCarousel   = 3;
   var listItems = $(".video_carousel_content li");
    //Set onLoad styles...
 	for (var i=1;i<=3;i++) {
		$(".p"+i).css({ "background" : pageNumberColor_off, "background-position" : "-15px 0" });
	} 
 		$(".p1").css({ "background" : pageNumberColor_on, "background-position" : "0 0" });
   //Remove any extra li items
   if(listItems.length>maxItemsInCarousel){
      var extraListItems = listItems.slice(maxItemsInCarousel);
      extraListItems.each(function(){$(this).remove();});
   }
   //Init JCarousel Lite
   $(".video_carousel_content").jCarouselLite({
      btnPrev   : ".v_prev",
      btnNext   : ".v_next",
      scroll    : 1,
      visible   : 1,
      speed     : 350,
      btnGo: [
         carouselContainer+" .pagination .p1",
         carouselContainer+" .pagination .p2",
         carouselContainer+" .pagination .p3"
      ],
      beforeStart : function(item, isAutoScroll){
         $(carouselContainer+" .pagination a").css({ "background" : pageNumberColor_off, "background-position" : "-15px 0" });
      },
      afterEnd : function(item, isAutoScroll){
         var itemsPerPage = 1; //should be same as visible setting
         var allItems = $(item[0]).parent().children();
         var length = allItems.length;
         //get current itemNum using item array passed in which list all 
         //items currently displayed
         var itemNum = allItems.index(item[0])+1;
         // figure out what page is displayed this is tricky since this version
         // of JCarousel adds two extra pages to give the illusion of a true carousel
         // figure out what page is displayed this is tricky since this version
         // of JCarousel adds two extra pages to give the illusion of a true carousel
		 // this page code is SPECIFIC for one item at a time, one item visible
		 var page = itemNum-itemsPerPage; //especially for 1 item at a time
		 if (page>maxItemsInCarousel) page = page-maxItemsInCarousel;
		 if (page<1) page = maxItemsInCarousel;
		 $(carouselContainer+" .pagination .p"+page).css({ "background" : pageNumberColor_on, "background-position" : "0 0" });
      }
   });
 	$(".v_prev").hover(
      function(){ $(this).css({ "background-position" :"0 -43px" });},
      function(){ $(this).css({ "background-position" :"0 -77px" }); }
   );
   $(".v_next").hover(
      function(){ $(this).css({ "background-position" :"0 -4px" }); },
      function(){ $(this).css({ "background-position" :"0 -111px" }); }
   );
},
		
	_self = {
		init: function(){		
			_videocarousel();		
		}	
	}	
	return _self;			
})(jQuery);

$(function() { igloo.init(); 
				videohighlight.init()});

