var tideCarousel = function() {
	
	// private variables
	var staticPanels = new Array();
	var activePanelID;
	
	return {
		
		/*
		 * getStaticPanelsHTML
		 * loads the static <li> HTML content from tje staticCarousel list
		 * 	into an array for later processing. Subsequently removes the
		 * 	staticCarousel list from the DOM
		*/
		getStaticPanelsHTML : function (panelArray){
			$.each (
				panelArray,
				function( intIndex, panel  ){
					staticPanels[intIndex] = panel.innerHTML;
				}
			);
			$("#staticCarousel").remove();
		},
		
		/*
		 * itemVisibleInCallback
		 * handles carousel display when an item moves into view
		*/
		itemVisibleInCallback : function(carousel, item, i, state, evt) {
			
			// The index() method calculates the index from a
			// given index who is out of the actual item range.
			
			var idx = carousel.index(i, staticPanels.length);
			carousel.add(i, staticPanels[idx - 1]);
		},
		
		/*
		 * itemVisibleOutCallback
		 * handles carousel display when an item moves out of view
		*/
		itemVisibleOutCallback : function(carousel, item, i, state, evt) {
			carousel.remove(i);
		},
		
		/*
		 * radomizeQuotes
		 * randomizes and displays the quotes associated with 
		 *	the active carousel item.
		*/
		radomizeQuotes : function(){
		
			if(typeof(activePanelID)=="undefined"){ 
				activePanelID = "panel_1";
			}
			
			shuffle = function(o){
	   			for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	   			return o;
	   		};
	   		
	   		$("#"+activePanelID+"-text").show();
	   		
	   		/* front-end randomization
	   		// shuffle the quote index array
	   		// 9 quotes are expected 
	   		var shuffledIdx = shuffle([0,1,2,3,4,5,6,7,8])
			
			// ... loop thru the array and display the first 3 quotes
			for (i=0; i<3; i++){
				var quoteToShowIndex = shuffledIdx[i];
				$("#"+activePanelID+"-text .quote-list-item:eq("+quoteToShowIndex+")").show();
				$("#"+activePanelID+"-text .quote-list-item:eq("+quoteToShowIndex+") span").show();
			}
			*/
		},
		
		/*
		 * activateSlot
		 * enlarges the images moved into the first position within the carousel 
		*/
		activateSlot : function(slotIndex){
		
			activePanelID = $("#dynamicCarousel").children("li")[slotIndex].firstChild.firstChild.id	
				
			// shrink any previously enlarged images
			$(".active").animate({ 
				height: "120px",
				width: "50px",
				marginTop:"40px"
			}, 150 );
			
			// remove class any previous active images
			$(".active").removeClass("active")
			
			// enlarge the active image
			$("#"+activePanelID).animate({ 
				height: "210px",
				width: "88px",
				marginTop:"0px"
			}, 500 );
		
			// set class of the active image
			$("#"+activePanelID).addClass("active");
		}
	};
}();

function initSlot(){
	 // enlarge the 1st active image
	$("#panel_1").animate({ 
		height: "210px",
		width: "88px",
		marginTop:"0px"
	}, 500 );
	$("#panel_1").addClass("active");
	
	$('ul#dynamicCarousel A[rel*="event"]').click( function() {
		var ary = this.name.split("~");
		var section = "";
		var subsection = "";
		var event = "";
		if(ary[0] != undefined)
			section = ary[0];
		if(ary[1] != undefined)
			subsection = ary[1];
		if(ary[2] != undefined)
			event = ary[2];
			
        trackEvent(section, subsection, event);
	});
}

jQuery(document).ready(function() {

	// get the html from the staticCarousel
    tideCarousel.getStaticPanelsHTML($("#staticCarousel").children());
    
    // create the dynamicCarousel
    var ul = document.createElement('ul');
    ul.setAttribute('id',"dynamicCarousel");
    document.getElementById("carouselContainer").appendChild(ul);
    
    // set up the carousel
    jQuery('#dynamicCarousel').jcarousel({
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: tideCarousel.itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: tideCarousel.itemVisibleOutCallback}
    });
    
    var initSlot1 = setTimeout ( initSlot, 1000 );
    
    $("#actionbutton").attr("src","/images/"+localPath+"/_global/search-action.png")
    
        

});








