$(document).ready(function(){

    // Open external links in new window
    $("a[href^='http:']").not("[href*='http://milliondollarquartet.com/']").attr('target','_blank');

    $("#homeCycle").cycle ({
	    timeout:       6000, 
        speed:         1000,
        fx: 'scrollLeft'
	});
    
    $("#aboutCycle").cycle ({
	    timeout:       6000, 
        speed:         2000,
        fx: 'fade'
	});
	
    /* Cast Members
    ------------------------------------------------------------------------ */
    	$("#rockwell-button").css({
    		opacity: 0.9
    	});

    	$("#mackie-button").css({
    		opacity: 0.9
    	});

    	$("#kazan-button").css({
    		opacity: 0.9
    	});

    	$("#castMenu div.castMember").click(function(){
		
    		$clicked = $(this);
		
    		// if the button is not already "transformed" AND is not animated
    		if ($clicked.css("opacity") != "1" && $clicked.is(":not(animated)")) {
			
    			$clicked.animate({
    				opacity: 1
    			}, 600 );
			
    			$clicked.css({
            		background: "url(img/cast-button-bg.png) no-repeat 0 0"            	});
			
    			// each button div MUST have a "xx-button" and the target div must have an id "xx" 
    			var idToLoad = $clicked.attr("id").split('-');
			
    			//we search trough the content for the visible div and we fade it out
    			$("#castContent").find("div:visible").fadeOut("fast", function(){
    				//once the fade out is completed, we start to fade in the right div
    				$(this).parent().find("#"+idToLoad[0]).fadeIn();
    			})
    		}
		
    		//we reset the other buttons to default style
    		$clicked.siblings(".castMember").animate({
    			opacity: 0.9
    		}, 600 );

    		$clicked.siblings(".castMember").css({
        		background: "none"
        	});
		
    	});	

        /* Creative Members
        ------------------------------------------------------------------------ */
        	$("#crowley-button").css({
        		opacity: 0.9
        	});

        	$("#macdevitt-button").css({
        		opacity: 0.9
        	});
        	
        	$("#tieghem-button").css({
        		opacity: 0.9
        	});
        	
        	$("#pask-button").css({
        		opacity: 0.9
        	});
        	
        	$("#creativeMenu div.castMember").click(function(){

        		$clicked = $(this);

        		// if the button is not already "transformed" AND is not animated
        		if ($clicked.css("opacity") != "1" && $clicked.is(":not(animated)")) {

        			$clicked.animate({
        				opacity: 1
        			}, 600 );

        			$clicked.css({
                		background: "url(img/cast-button-bg.png) no-repeat 0 0"
                	});

        			// each button div MUST have a "xx-button" and the target div must have an id "xx" 
        			var idToLoad = $clicked.attr("id").split('-');

        			//we search trough the content for the visible div and we fade it out
        			$("#creativeContent").find("div:visible").fadeOut("fast", function(){
        				//once the fade out is completed, we start to fade in the right div
        				$(this).parent().find("#"+idToLoad[0]).fadeIn();
        			})
        		}

        		//we reset the other buttons to default style
        		$clicked.siblings(".castMember").animate({
        			opacity: 0.9
        		}, 600 );

        		$clicked.siblings(".castMember").css({
            		background: "none"
            	});

        	});


        /* Video player
        ------------------------------------------------------------------------ */
        
        $(".videoFancyBox").fancybox({
            frameWidth: 450,
            frameHeight: 350,
            padding: 1,
            hideOnContentClick: false,
            overlayShow: true,
            overlayOpacity: 0.8
    	});

        $(".videoTitles li").click(function(){
            $(".videoTitles ul li").removeClass("selected");
            $(this).addClass("selected");
            return false;
    	});


        $(".video001").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><object type="application/x-shockwave-flash" style="width:390px; height:316px;" data="http://www.youtube.com/v/AJDx3H_hvI8&hl=en&fs=1&rel=0&autoplay=1"><param name="movie" value="http://www.youtube.com/v/AJDx3H_hvI8&hl=en&fs=1&rel=0&autoplay=1" /><param name="wmode" value="transparent" /></object></div><h4>Christopher Walken reads Lady Gaga&rsquo;s "Poker Face"</h4>').remove();
    	return false;
        });

        $(".video002").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><embed id="fl20172813" width="390" height="310" align="top" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" allowscriptaccess="always" seamlesstabbing="true" allowfullscreen="true" wmode="window" devicefont="false" menu="false" name="fl20172813" mayscript="" salign="tl" scale="noborder" quality="Best" bgcolor="#000000" loop="true" play="true" swliveconnect="TRUE" src="http://msnbcmedia.msn.com/i/MSNBC/Components/Video/_Player/swfs/embedPlayer/EmbeddedPlayer11252009B.swf?domain=www.msnbc.msn.com&settings=22425448&useProxy=true&wbDomain=www.msnbc.msn.com&launch=34938217&sw=1680&sh=1050&EID=oVPEFC&playerid=22425001"/></div><h4>Today Show: <em>Hurt Locker&rsquo;s</em> Anthony Mackie on good-guy role.</h4></div>').remove();
    	return false;
        });
        
        $(".video003").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><object type="application/x-shockwave-flash" style="width:390px; height:316px;" data="http://www.youtube.com/v/LbP0Bq4wQKE&hl=en&fs=1&rel=0&autoplay=1"><param name="movie" value="http://www.youtube.com/v/LbP0Bq4wQKE&hl=en&fs=1&rel=0&autoplay=1" /><param name="wmode" value="transparent" /></object></div><h4>New TV Commercial</h4>').remove();
    	return false;
        });

        $(".video004").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><object id="flashObj" width="390" height="316" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,47,0"><param name="movie" value="http://c.brightcove.com/services/viewer/federated_f9/22792485001?isVid=1&publisherID=1372165866" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="videoId=65627772001&playerID=22792485001&domain=embed&" /><param name="base" value="http://admin.brightcove.com" /><param name="seamlesstabbing" value="false" /><param name="allowFullScreen" value="true" /><param name="swLiveConnect" value="true" /><param name="allowScriptAccess" value="always" /><embed src="http://c.brightcove.com/services/viewer/federated_f9/22792485001?isVid=1&publisherID=1372165866" bgcolor="#FFFFFF" flashVars="videoId=65627772001&playerID=22792485001&domain=embed&" base="http://admin.brightcove.com" name="flashObj" width="390" height="316" seamlesstabbing="false" type="application/x-shockwave-flash" allowFullScreen="true" swLiveConnect="true" allowScriptAccess="always" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object></div><h4>Broadway.comm Press Event Coverage</h4>').remove();
    	return false;
        });

        $(".video005").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><object type="application/x-shockwave-flash" style="width:390px; height:316px;" data="http://www.youtube.com/v/Y5MMgH4Nht0&hl=en&fs=1&rel=0&autoplay=1"><param name="movie" value="http://www.youtube.com/v/Y5MMgH4Nht0&hl=en&fs=1&rel=0&autoplay=1" /><param name="wmode" value="transparent" /></object></div><h4><em>A BEHANDING IN SPOKANE</em> Press Event</h4>').remove();
    	return false;
        });

        $(".video006").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><object type="application/x-shockwave-flash" style="width:390px; height:316px;" data="http://www.youtube.com/v/fgy6k0Tqyv4&hl=en&fs=1&rel=0&autoplay=1"><param name="movie" value="http://www.youtube.com/v/fgy6k0Tqyv4&hl=en&fs=1&rel=0&autoplay=1" /><param name="wmode" value="transparent" /></object></div><h4><em>A BEHANDING IN SPOKANE</em> Press Event</h4>').remove();
    	return false;
        });
        
        $(".video007").click(function(){
        $("#videoBox").after('<div id="videoBox"><div id="videoDisplay"><object type="application/x-shockwave-flash" style="width:390px; height:316px;" data="http://www.youtube.com/v/uK1I40yKNTw&hl=en&fs=1&rel=0&autoplay=1"><param name="movie" value="http://www.youtube.com/v/uK1I40yKNTw&hl=en&fs=1&rel=0&autoplay=1" /><param name="wmode" value="transparent" /></object></div><h4><em>A BEHANDING IN SPOKANE</em> Teaser #1</h4>').remove();
    	return false;
        });
        
        $(".contestTitles a").click(function(){
            $(".contestTitles ul li").removeClass("selected");
            $(this).parent().addClass("selected");
            var i = $(this).attr("rel");
            var m = $(this).attr("title");
            $("#videoBox").html('<div id="videoDisplay"><object type="application/x-shockwave-flash" style="width:390px; height:316px;" data="' + i + '&hl=en&fs=1&rel=0&autoplay=1"><param name="movie" value="' + i + '&hl=en&fs=1&rel=0&autoplay=1" /><param name="wmode" value="transparent" /></object></div><h4>' + m + '</h4>');
        return false;
        });
            
        
        /* Gallery
        ------------------------------------------------------------------------ */
        
        $(".photowFancyBox").fancybox({
            frameWidth: 750,
            frameHeight: 525,
            padding: 1,
            hideOnContentClick: false,
            overlayShow: true,
            overlayOpacity: 0.8
    	});

        $(".photolFancyBox").fancybox({
            frameWidth: 500,
            frameHeight: 700,
            padding: 1,
            hideOnContentClick: false,
            overlayShow: true,
            overlayOpacity: 0.8
    	});


        /* Ecard
        ------------------------------------------------------------------------ */

           $("#ecard").submit(function(){
               
            var card = $("#card").val();
           	var name = $("#yourName").val();
           	var email = $("#yourEmail").val();
           	var recipient = $("#recipient").val();
           	var message = $("#message").val();
           	
           	if ((name == "") || (email == "") || (recipient == "") || (message == "")) {
           		$("#status").html("<p>PLEASE FILL OUT ALL FIELDS.</p>");
           		return false;
           	}
           	
           	$('#status').html('<p><img src="img/ajax-loader.gif" alt=""></p>');    
           	$.post("connect.html",{card: card, yourName: name, yourEmail: email, recipient: recipient, message: message},function() {
               		$("#card, #yourName, #yourEmail, #recipient, #message").val("");
               		var i = '$("#status").html("<p><strong>Your ecard has been sent.</strong></p>")';
               		setTimeout(i, 2000)
               	}
           	);
               	
           	return false;
           });
           
           
           // Create Preview
           $("#popPreview").click(function() {
               $('.overlay').css({
                   "height": $(document).height()
               });
               var i = $("#message").val();
               $("#ecardMessage").html(i)
               
               var j = $("#card").val();
               $("#ecardImage").attr("src", "http://spotcoqa.com/behanding-new/img/ecard-left.jpg")
               $("#ecardPreview").show();
               $(".overlay").show();
               return false;
           })
           // Kill Preview
           $("#closePreview").click(function(){
               $(".overlay").hide();
               $("#ecardPreview").hide();
               $("#ecardImage").attr("src", "");
           });
           

        /* Sub Navs
        ------------------------------------------------------------------------ */    	

        $("#creativeSub").hide();
    	$(".castSub").css({
        	background: "transparent url(img/subnav-cast.png) no-repeat scroll 0 -42px"
    	});    	

        $(".creativeSub").click(function(){
            $("#castSub").hide();
            $("#creativeSub").show();
        	$(".castSub").css({
            	background: "transparent url(img/subnav-cast.png) no-repeat scroll 0 0"
        	});    	
        	$(".creativeSub").css({
            	background: "transparent url(img/subnav-creative.png) no-repeat scroll 0 -42px"
        	});    	
            return false;
        });

        $(".castSub").click(function(){
            $("#creativeSub").hide();
            $("#castSub").show();
        	$(".castSub").css({
            	background: "transparent url(img/subnav-cast.png) no-repeat scroll 0 -42px"
        	});    	
        	$(".creativeSub").css({
            	background: "transparent url(img/subnav-creative.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });

        $("#reviewsSub").hide();
        $(".newsSub").css({
        	background: "transparent url(img/subnav-news.png) no-repeat scroll 0 -42px"
        });    	

        $(".reviewsSub").click(function(){
            $("#newsSub").hide();
            $("#reviewsSub").show();
        	$(".newsSub").css({
            	background: "transparent url(img/subnav-news.png) no-repeat scroll 0 0"
        	});    	
        	$(".reviewsSub").css({
            	background: "transparent url(img/subnav-reviews.png) no-repeat scroll 0 -42px"
        	});    	
            return false;
        });

        $(".newsSub").click(function(){
            $("#reviewsSub").hide();
            $("#newsSub").show();
        	$(".newsSub").css({
            	background: "transparent url(img/subnav-news.png) no-repeat scroll 0 -42px"
        	});    	
        	$(".reviewsSub").css({
            	background: "transparent url(img/subnav-reviews.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });

        $("#downloadsSub").hide();
        $("#ecardSub").hide();
        $(".connectSub").css({
        	background: "transparent url(img/subnav-connect.png) no-repeat scroll 0 -42px"
        });    	

        $(".downloadsSub").click(function(){
            $("#connectSub").hide();
            $("#ecardSub").hide();
            $("#downloadsSub").show();
        	$(".connectSub").css({
            	background: "transparent url(img/subnav-connect.png) no-repeat scroll 0 0"
        	});    	
        	$(".ecardSub").css({
            	background: "transparent url(img/subnav-ecard.png) no-repeat scroll 0 0"
        	});    	
        	$(".downloadsSub").css({
            	background: "transparent url(img/subnav-downloads.png) no-repeat scroll 0 -42px"
        	});    	
        	$(".partnersSub").css({
            	background: "transparent url(img/subnav-partners.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });

        $(".connectSub").click(function(){
            $("#downloadsSub").hide();
            $("#ecardSub").hide();
            $("#connectSub").show();
        	$(".connectSub").css({
            	background: "transparent url(img/subnav-connect.png) no-repeat scroll 0 -42px"
        	});    	
        	$(".ecardSub").css({
            	background: "transparent url(img/subnav-ecard.png) no-repeat scroll 0 0"
        	});    	
        	$(".downloadsSub").css({
            	background: "transparent url(img/subnav-downloads.png) no-repeat scroll 0 0"
        	});    	
        	$(".partnersSub").css({
            	background: "transparent url(img/subnav-partners.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });

        $(".ecardSub").click(function(){
            $("#downloadsSub").hide();
            $("#connectSub").hide();
            $("#ecardSub").show();
        	$(".ecardSub").css({
            	background: "transparent url(img/subnav-ecard.png) no-repeat scroll 0 -42px"
        	});    	
        	$(".connectSub").css({
            	background: "transparent url(img/subnav-connect.png) no-repeat scroll 0 0"
        	});	
        	$(".downloadsSub").css({
            	background: "transparent url(img/subnav-downloads.png) no-repeat scroll 0 0"
        	});    	
        	$(".partnersSub").css({
            	background: "transparent url(img/subnav-partners.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });


        $(".partnersSub").click(function(){
            $("#downloadsSub").hide();
            $("#connectSub").hide();
            $("#ecardSub").hide();
            $("#partnersSub").show();
        	$(".partnersSub").css({
            	background: "transparent url(img/subnav-partners.png) no-repeat scroll 0 -42px"
        	});
        	$(".ecardSub").css({
            	background: "transparent url(img/subnav-ecard.png) no-repeat scroll 0 0"
        	});    	
        	$(".connectSub").css({
            	background: "transparent url(img/subnav-connect.png) no-repeat scroll 0 0"
        	});    	
        	$(".downloadsSub").css({
            	background: "transparent url(img/subnav-downloads.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });


        $(".contestsSub").click(function(){
            $("#downloadsSub").hide();
            $("#connectSub").hide();
            $("#ecardSub").hide();
            $("#partnersSub").hide();
            $("#contestsSub").show();
        	$(".contestsSub").css({
            	background: "transparent url(img/subnav-contests.png) no-repeat scroll 0 -42px"
        	});
        	$(".partnersSub").css({
            	background: "transparent url(img/subnav-partners.png) no-repeat scroll 0 0"
        	});
        	$(".ecardSub").css({
            	background: "transparent url(img/subnav-ecard.png) no-repeat scroll 0 0"
        	});    	
        	$(".connectSub").css({
            	background: "transparent url(img/subnav-connect.png) no-repeat scroll 0 0"
        	});    	
        	$(".downloadsSub").css({
            	background: "transparent url(img/subnav-downloads.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });
        
        $("#photosSub").hide();
        $(".videosSub").css({
        	background: "transparent url(img/subnav-videos.png) no-repeat scroll 0 -42px"
        });    	

        $(".photosSub").click(function(){
            $("#videosSub").hide();
            $("#photosSub").show();
        	$(".videosSub").css({
            	background: "transparent url(img/subnav-videos.png) no-repeat scroll 0 0"
        	});    	
        	$(".photosSub").css({
            	background: "transparent url(img/subnav-photos.png) no-repeat scroll 0 -42px"
        	});    	
            return false;
        });

        $(".videosSub").click(function(){
            $("#photosSub").hide();
            $("#videosSub").show();
        	$(".videosSub").css({
            	background: "transparent url(img/subnav-videos.png) no-repeat scroll 0 -42px"
        	});    	
        	$(".photosSub").css({
            	background: "transparent url(img/subnav-photos.png) no-repeat scroll 0 0"
        	});    	
            return false;
        });

});


// Load jscrollPane after everything else
$(window).load(function(){
    $(".scrollPane").jScrollPane({
        scrollbarWidth: 12,
        showArrows: true,
        arrowSize: 10
    });
});