/*
Note: the homepage pano pause functions live in scripts.js
    this is so the video player and other things can call
    them without error for non-existence
*/
var current_player_id;

$(document).ready(function(){
    /* start pano */
    if ($("#homePanoContainer").length == 1) {
        unpauseHomePano("javascript");

        $("#siteSubNavigation").hover(
            function(){ pauseHomePano("javascript"); },
            function(){ unpauseHomePano("javascript"); }
        ).mousemove(function(){ pauseHomePano("javascript"); });
    }

    $(".preview_img").click(function() {
        $(this).hide();
        //$(this).parent().find(".embed_video").show();

        current_player_id = getPlayerId($(this).parent().find(".embed_video object"));
        //alert(current_player_id);
        document.getElementById(current_player_id).playFlashPlayer();
    });
});

function getPlayerId(obj) {
    //alert($.browser.chrome);
    var is_chrome = false;
    if ($.browser.safari) {
        is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );
    }
    if (! ($.browser.msie || ($.browser.safari && ! is_chrome))) obj = obj.find("object");
    return obj.attr("id");
    }

/*** PANO FUNCTIONS ***/
var currentHomePanoSlide = 1,
    homePanoBgColors = ["#c8d9b2", "#cbedf5", "#f5e297", "#c3c6ce", "#fcae89"],
    homePanoTimer;

function changeHomePanoSlide(){
    var tempOldHomePanoSlide = currentHomePanoSlide;
	
    /* get next slide number */
    currentHomePanoSlide++;

    if (currentHomePanoSlide > homePanoBgColors.length) {
        currentHomePanoSlide = 1;
        }

    animateHomePanoSlides(tempOldHomePanoSlide, currentHomePanoSlide);
}

function jumpToHomePanoSlide(x){
	animateHomePanoSlides(currentHomePanoSlide, x);
	currentHomePanoSlide = x;
	
    return false;
}

function animateHomePanoSlides(oldNum, newNum){
	if (oldNum != newNum){
		/* change background color */
		$(".embed_video").each(function(){
			try{
				current_player_id = getPlayerId($(this).parent().find(".embed_video object"));
				document.getElementById(current_player_id).pauseFlashPlayer();
			}catch (ex){}
		});

		$("#siteSubNavigation").stop(true, false).animate({"backgroundColor" : homePanoBgColors[newNum - 1]}, 600, "swing", function() {
			if ($.browser.msie) $(".preview_img").show();
		});

		/* -- simpler version (has a block of commented out CSS to go with it) --
		// old slide out
		$("#homePanoSlide" + oldNum).css({ "display" : "none" });

		// new slide in
		$("#homePanoSlide" + newNum).css({ "display" : "block" });

		// update pano nav
		setTimeout(function(){
				$("#homePanoNavDot" + oldNum).attr("src", "/assets/images/homepage/pano-nav-dot-off.png");
				$("#homePanoNavDot" + newNum).attr("src", "/assets/images/homepage/pano-nav-dot-on.png");
		}, 150);
		*/

		/* -- fancier slide version -- */
		/* move old slide out, stage left */
		$("#homePanoSlide" + oldNum).stop(true, true).animate({"left" : "-960px"}, 700, "easeInOutCubic", function(){
			/* move back to the right, for the next time it slides left */
			$(this).css({ "left" : "" });
		});

		/* move new slide in from stage right */
		$("#homePanoSlide" + newNum).stop(true, true).animate({"left" : "10px"}, 700, "easeInOutCubic");

		/* update pano nav */
		setTimeout(function(){
                    $("#homePanoNavDot" + oldNum).attr("src", "/assets/images/homepage/pano-nav-dot-off.png");
                    $("#homePanoNavDot" + newNum).attr("src", "/assets/images/homepage/pano-nav-dot-on.png");
		}, 350);
	};
};
