﻿$(document).ready(function(){

        $("#fadeout").show().delay(500,function(){
            $("#fadeout").fadeOut(1000);
        });
        
        // Show homepage flash if JS on
        $("#homepageFlash").show();
        
        $("#the_range_product_shot").css('overflow','hidden');//*For no-script purposes
        $("#nestle_confectionary_product_shot").css('overflow','hidden');//*For no-script purposes
        $("#the_game_shots").css('overflow','hidden');
        // Playlist settings - Javascript enabled
        $("#playlist_Scroll").css({'overflow':'hidden', 'height':'370px'});
        $(".playlist_buttons").show();
        $("#game_next").show();
        $("#game_prev").show();
        $(".playlist_tracks a").hide();
        
	    //To switch directions up/down and left/right just place a "-" in front of the top/left attribute
		
		//After Eight Wrapper Links
        $(".after_eight_range_wrapper").hover(function(){
            $(".the_range_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".the_range_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
    
        $(".after_eight_confectionary_wrapper").hover(function(){
            $(".confectionary_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".confectionary_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
	
        $(".eight_dos_wrapper").hover(function(){
            $(".eight_dos_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".eight_dos_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
	
        $(".eight_donts_wrapper").hover(function(){
            $(".eight_donts_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".eight_donts_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
	
        $(".music_wrapper").hover(function(){
            $(".music_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".music_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
	
        $(".recipes_wrapper").hover(function(){
            $(".recipes_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".recipes_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
        
        $(".do_donts_wrapper").hover(function(){
            $(".do_donts_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".do_donts_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
        
        $(".party_games_wrapper").hover(function(){
            $(".party_games_inner_slot").animate({"top": "-50px"},{queue:false,duration:160});
         }, function() {
	        $(".party_games_inner_slot").animate({"top": "0px"},{queue:false,duration:160});
        });
        
        // Music - Playlist
        $(".music_main_nav li").each(function(i) {
            $(this).hover(function(){
                $(this).find('.music_cd_inner_slot').animate({marginLeft: "40px"}, 250 ); //.animate({"Mright": "-1px"},{queue:false,duration:160});
            }, function() {
	            $(this).find('.music_cd_inner_slot').animate({marginLeft: "10px"}, 250 ); //.animate({"right": "30px"},{queue:false,duration:160});
            });
        });

	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_nestle_confectionery.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_Confect.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_story.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_story.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px'},{queue:false,duration:160});
	    });
	   
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_visit_site.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_VisitSite.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_itunes_purchase.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_trivia.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_story.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_range.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_ad_campaign.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_Nestle_Confectionery.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'26px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_games.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_music.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_deserts.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_meet_jim.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	     //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_ProductRange.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //Full Caption Sliding (Hidden to Visible)
	    $('.boxgrid_after_eight_Jims_Place.captionfull').hover(function(){
		    $(".cover", this).stop().animate({top:'0px', left: '0px'},{queue:false,duration:160});
	    }, function() {
		    $(".cover", this).stop().animate({top:'27px', left: '0px'},{queue:false,duration:160});
	    });
	    
	    //visit website
        $(".visitbutton").hover(function(){
            $(".visitBtnImg").animate({"top": "-27px"},{queue:false,duration:160});
         }, function() {
	        $(".visitBtnImg").animate({"top": "0px"},{queue:false,duration:160});
        });
        
        /* Product Gallery */
        var pos=new Array(0,-944,-1888, -2832, -3776, -4720, -5664, -6608, -7602, -8546);
        var defaultPos = 0;
        var productSelected;
        var slide = "Down";
        var itunes = new Array(346530267, 347282062, 347287013, 347287197, 347051417, 347003754, 347004139, 347276805);
        var playlist = 0; 
        var showInfoActive = -1;    
        //Full path = http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewIMix?id=347287013    
        
        $(".product_thumbs a").each(function(i) {
            $(this).click(function(){
                $("#showInfo").animate({'top':'0px'}).delay(500,function(){
                    
                    $(".product").animate({marginLeft: + pos[i] +"px"}, 750 );
                    var productImage = "url(../images/layout/nutrition_info_" + i + ".png)";
                    $("#showInfo").css("background-image", productImage);
                    
					showInfoActive = i; 
					
                    // Hide all info tables
                    $("#nutInfo0").hide();
                    $("#nutInfo1").hide();
                    $("#nutInfo2").hide();
                    $("#nutInfo3").hide();
                    $("#nutInfo4").hide();
                    
                    // Show selected info table
                    var showNutTable = "#nutInfo" + i;
                    $(showNutTable).show();
                    
                    // Reset slide
                    slide = "Down";
                });
            });
        });
        
       // Show Info
       $("#showInfoButton").click(function(){
            if (slide == "Down")
            {
				if (showInfoActive == -1)
				{
					$("#showInfo").css("background-image", "url(../images/layout/nutrition_info_0.png)");
				}
					$("#showInfo").animate({'top':'340px'});
					slide = "Up";
					$("#showInfo_up_arrow").show();
				
            }
            else
            {
                $("#showInfo").animate({'top':'0px'});
                slide = "Down";
                $("#showInfo_up_arrow").hide();
            }
       });
       
       // Hide Info
       $(".hideInfoButton").click(function(){
            $("#showInfo").animate({'top':'0px'});
            slide = "Down";
       });
       
       
       // Nestle Confectionery
         $(".nestle_confectionary_thumbs a").each(function(i) {
            $(this).click(function(){
                    $(".nc_product").animate({marginLeft: + pos[i] +"px"}, 750 );
            });
        });
       
       
       // games
        $(".game_thumbs a").each(function(i) {
            $(this).click(function(){
                    $(".game_steps").animate({marginLeft: + pos[i] +"px"}, 750 );
                    defaultPos = pos[i];
                    var productImage = "url(../images/nutrition_info_" + i + ".jpg)";
                    
                    // hide up arrow
                    $("#showInfo_up_arrow").hide();
            });
        });
        
        $("#game_prev").hide();
        
        $("#game_next").click(function(){
            defaultPos -= 944;
            
            if (defaultPos == -6608)
            {
                $("#game_next").fadeOut("slow");
                $("#game_prev").fadeIn("slow").css({"height":"62px"});
            }
            else
            {
                $("#game_next").fadeIn("slow");
                $("#game_prev").fadeIn("slow").css({"height":"62px"});
            }
            // games scroll
            $(".game_steps").animate({marginLeft: defaultPos + "px"}, 750 );
            // Playlist scroll
            $(".playlist").animate({marginLeft: defaultPos + "px"}, 750 );
            // Playlist itunes link
            playlist +=1;
            $("a.hidden_itunes_purchase").attr("href", "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewIMix?id=" + itunes[playlist]);
            
        });
        
        
        $("#game_prev").click(function(){
            defaultPos += 944;
            if (defaultPos == 0)
            {
                $("#game_prev").fadeOut("slow");
                $("#game_next").fadeIn("slow");
            }
            else
            {
                $("#game_next").fadeIn("slow");
                $("#game_prev").fadeIn("slow");
            }
            // games Scroll
            $(".game_steps").animate({marginLeft: defaultPos + "px"}, 750 );
            // Playlist scroll
            $(".playlist").animate({marginLeft: defaultPos + "px"}, 750 );
            // Playlist itunes link
            playlist -=1;
            $("a.hidden_itunes_purchase").attr("href", "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewIMix?id=" + itunes[playlist]);
            
        });
        
        // Display correct playlist after click
            $(".music_main_nav a").each(function(i) { 
                 $(this).click(function() {
                    $.session("CD", "");
                    $.session("CD", i);
                    //alert(i);
                 });

             });
       
       // CD Playlist pass through
        var selectedPlaylist = $.session("CD");
               
        if (selectedPlaylist > 0)
        {
            //alert(selectedPlaylist); 
            $("#game_prev").fadeIn("slow");
            defaultPos = -944 * selectedPlaylist;
            
            $(".playlist").animate({marginLeft: defaultPos + "px"}, 750 );
           $.session("CD", "-1");
           
           if (selectedPlaylist == 7)
                $("#game_next").fadeOut("slow");
        }
        else
        {
            //alert("0");
            defaultPos = 0;
            $(".playlist").animate({marginLeft: "0px"}, 750 );
        }
        
});

