$(document).ready(function() {
	var currentTime = new Date();
	var year = currentTime.getFullYear();
	$('.year').empty().append(year);
});
home = (function($){	
	_carousel = function(){
   var pageNumberColor_on   = "url(image/common/icons/carousel_dot_sprite.gif) no-repeat", 
   	   pageNumberColor_off  = "url(image/common/icons/carousel_dot_sprite.gif) no-repeat",
       maxItemsInCarousel   = 18;
   var listItems = $(".carousel_content li");
    //Set onLoad styles...
 	for (var i=1;i<=3;i++) {
		$(".p"+i).css({ "background" : pageNumberColor_off, "background-position" : "0 -30px" });
	} 
 		$(".p1").css({ "background" : pageNumberColor_on, "background-position" : "0 -70px" });
   //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",
	  auto: 5000,
      scroll    : 1,
      visible   : 7,
      speed     : 700,
      btnGo: [
         ".pagination .p1", "null", "null",
         ".pagination .p2", "null", "null"
      ],
      beforeStart : function(item, isAutoScroll){
         $(".pagination a").css({ "background" : pageNumberColor_off, "background-position" : "0 -30px" });
      },
      afterEnd : function(item, isAutoScroll){
         var itemsPerPage = 7; //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);
         $(".pagination .p"+page).css({ "background" : pageNumberColor_on, "background-position" : "0 -70px" });
      }
   });
   // Hover button change.
 	$(".prev").hover(
      function(){ $(this).css({ "background-position" :"0 -276px" }); },
      function(){ $(this).css({ "background-position" :"0 -184px" }); }
   );
   $(".next").hover(
      function(){ $(this).css({ "background-position" :"0 -92px" }); },
      function(){ $(this).css({ "background-position" :"0 0px" }); }
   );
},
		
	_self = {
		init: function(){		
			_carousel();		
		}	
	}	
	return _self;
})(jQuery);
$(function() { home.init(); });
