﻿var num = 0;

function top10Switch(num) {
	if (num == "0") {
		$("#top_10").removeClass().addClass("module").addClass("on-box_office");
	}
	if (num == "1") {
		$("#top_10").removeClass().addClass("module").addClass("on-fan_rated");
	}
}		

/* content spotlight */

var currFeature;
var newFeature = 0;
var FeatureCount = 0;

// "slideshowPlaying" value here determines whether slideshow starts on page load or not
var slideshowPlaying = true;
var slideshowTimerInterval = 8000;
var slideshowTimerPtr;

function slideshowTimer() {
    if (slideshowPlaying) {
        if (!isNaN(currFeature)) {
            var nextFeature = ((currFeature + 1) % 4);
            setFeature(nextFeature, true);
            FeatureCount = FeatureCount + 1;
            if(FeatureCount>7) {
                slideshowPlay(false)
                slideshowTimerPtr = clearTimeout(slideshowTimerInterval);
                FeatureCount = 0;
                return;
            }
        }        
        slideshowTimerPtr = setTimeout("slideshowTimer()", slideshowTimerInterval);
    }
}

function setFeature(newFeature, buttonOn) {

    // Set up button display
	$("ul#spotlight_nav > li").removeClass("on").eq(newFeature).addClass("on");
	
	// If click event, show new content
    if ((buttonOn) && (currFeature != newFeature)){
        // Load new content
	    $("ul#spotlight_nav > li").eq(currFeature).find(".spotlight_itemfeatures").removeClass("on");

	    $("ul#spotlight_nav > li").eq(newFeature).find(".spotlight_itemfeatures").addClass("on");
	    
        // Change image, link and alt text                
        $("#spotlight_itemcontent a img").hide();        
        $("#spotlight_itemcontent a img").attr("src", featureImages[newFeature]);
        $("#spotlight_itemcontent a img").fadeIn(400);       
        
		$("#spotlight_itemcontent a img").attr("alt", featureAltText[newFeature]);
		$("#spotlight_itemcontent a").attr("href", featureLinks[newFeature]);
		$("#spotlight_itemcontent a").attr("name", featureTrackingInfo[newFeature]);	
		
		$("#spotlight_nav li div p a").attr("href", featureLinks[newFeature]);
		$("#spotlight_nav li div h2 a").attr("href", featureLinks[newFeature]);
		
		// change the links
		$("#currently_featured").html($("ul#spotlight_nav > li").eq(newFeature).find(".spotlight_itemfeatures").clone());
        currFeature = newFeature;
	}
}

function slideshowPlay(newSlideshowState) {

    // Hide all controls
    $(".spotlight_slideshow_control").hide();
    clearTimeout(slideshowTimerPtr);
    
    if (!newSlideshowState) {
        // Pause the slideshow
        $("#spotlight_slideshow_control_paused").show();
    }
    else {
        // Play the slideshow
        $("#spotlight_slideshow_control_playing").show();
        slideshowTimerPtr = setTimeout("slideshowTimer()", slideshowTimerInterval);
    }
    
    slideshowPlaying = newSlideshowState;
}

$(document).ready(function() {
	// tab switcher
	$("#top_10 .tabs li a").each(function(i) {					
		$(this).click(function() {
			top10Switch(i);
			this.blur();
			return false;
		});
	});	
	
	$("#trailers_videoclips ul li a.image, #trailers_videoclips ul li a.action").hover(function() {
		$(this).siblings(".covermask").show();	
	}, function() {		
		$("#trailers_videoclips ul li .covermask").hover(function() {
			$(this).show();
		}, function() {
			$(this).hide();
		});
		$(this).siblings(".covermask").hide();
	});

    // Initialize default feature
    setFeature(newFeature, true); 
    
    // Set up button actions for hover and click
    $("ul#spotlight_nav > li").not(".spotlight_itemfeatures").each(function(i) {
	    $(this).hoverIntent(function(){
		    setFeature(i, true);
		    slideshowPlay(false);
		    window.status=featureLinks[i];  // Note: writing to status bar is turned OFF in Firefox by default - the user must manually enable it in "Preferences".
		}, function(){
		    setFeature(currFeature, false);
			 slideshowPlay(true);
		    window.status='';
	    });			 	
    });
	 
	 $("div#spotlight_itemcontent").hoverIntent(function() {
		    slideshowPlay(false);
		 }, function(){
			 slideshowPlay(true);
	    });			

    $("ul#spotlight_nav > li").each(function(i) {
	     	
	    $(this).click(function(){
		    // Build WSS parameters and fire the event
            buttonTitle = $("ul#spotlight_nav > li > h4").eq(i).text().replace(/ /g,"+");
            lid = "FArea4_Bu" + (i + 1) + "_" + buttonTitle;
            lpos = "FArea4_Bu" + (i + 1);
            _hbLink(lid, lpos)

            location.href=featureLinks[i];            
            // Returning true allows clicked element within the jquery element to process it's onclick event (e.g. hyperlinks work)
            return false;
	    });			
    });

    // Set up slideshow buttons
    $(".spotlight_slideshow_control").click(function(){

        // Record user action
        lid = "FArea4_" + (slideshowPlaying ? "Pause" : "Play") + "Button";
        _hbLink(lid, "");        
        slideshowPlay(!slideshowPlaying);        
        return false;
    });
    
    // Set up slideshow
    slideshowPlay(slideshowPlaying);

    if(featureImages) {
	var j = 0;
	var p = featureImages.length;
	var preBuffer = new Array();
	 
	for (i = 0; i < p; i++){
		preBuffer[i] = new Image();
		preBuffer[i].src = featureImages[i];
    }
}	

});

		
		

