﻿var tcMinimized = false;
var MoviePlays = false;
var prePlayTimer;
var isDiningLanding = false;

/* these two are used for the gallery */
function BodyContentMin() {
    if (location.pathname != "/" && location.pathname != "/default.aspx") {
        $("#tc-bg").animate({ opacity: 0.5 });
    }
    $("#tc-body").animate({ "height": "475px" }, 100);
    $("#LeftNavMasterContainer").animate({ "height": "475px" }, 100);
    $("#ContentLeftBorder").css("visibility", "visible");
    $("#LeftNavMasterContainer").css("visibility", "visible");
    $("#tc-body").css("visibility", "visible");
    $("#tc-body-content-minmax-image").replaceWith("<img src='/media/body/minimize.png' id='tc-body-content-minmax-image' alt='-' />");
    tcMinimized = false;
    if (isDiningLanding) {
        PlayDiningMovies()
    }
    
}

function BodyContentMax() {
    $("#tc-bg").animate({ opacity: 1 });
    $("#tc-body").animate({ "height": "25px" }, 100);
    $("#LeftNavMasterContainer").animate({ "height": "25px" }, 100);
    $("#ContentLeftBorder").css("visibility", "hidden");
    $("#tc-body").css("visibility", "hidden");
    $("#LeftNavMasterContainer").css("visibility", "hidden");
    $("#tc-body-content-minmax-image").replaceWith("<img src='/media/body/maximize.png' id='tc-body-content-minmax-image' alt='+' />");
    tcMinimized = true;
    if (isDiningLanding) {
        PauseDiningMovies()
    }
}
/* used for the toggle button in the upper right of the body content */
function TCMinMax() {
    if (tcMinimized == false) {
        $("#tc-bg").animate({ opacity: 1 });
        $("#tc-body").animate({ "height": "25px" }, 100);
        $("#LeftNavMasterContainer").animate({ "height": "25px" }, 100);
        $("#ContentLeftBorder").css("visibility", "hidden");
        //if (document.all && !document.querySelector) {
        $("#tc-body").css("visibility", "hidden");
        $("#LeftNavMasterContainer").css("visibility", "hidden");
        //}
        $("#tc-body-content-minmax-image").replaceWith("<img src='/media/body/maximize.png' id='tc-body-content-minmax-image' alt='+' />");
        tcMinimized = true;
        if (isDiningLanding) {
            PauseDiningMovies()
        }


    }
    else {
        if (location.pathname != "/" && location.pathname != "/default.aspx") {
            $("#tc-bg").animate({ opacity: 0.5 });
        }
        $("#tc-body").animate({ "height": "475px" }, 100);
        $("#LeftNavMasterContainer").animate({ "height": "475px" }, 100);
        $("#ContentLeftBorder").css("visibility", "visible");
        //if (document.all && !document.querySelector) {
        $("#LeftNavMasterContainer").css("visibility", "visible")
        $("#tc-body").css("visibility", "visible");
        //}
        //        $("#tc-body h1").animate({ "font-size": "24px", "margin-top": "30px" }, 150);
        //        $("#tc-body h2").animate({ "font-size": "20px", "margin-top": "10px" }, 150);
        tcMinimized = false;
        if (isDiningLanding) {
            PlayDiningMovies()
        }
        $("#tc-body-content-minmax-image").replaceWith("<img src='/media/body/minimize.png' id='tc-body-content-minmax-image' alt='-' />");
    }
}

//Close Button Click
//This handles closing the movie when user clicks close button
//resets elements, clears timers and ***does set mediablockpostion***
//Only called by clicking the movie close button
function CloseMovie() {
    if (MoviePlays) {
        clearTimeout(prePlayTimer);
        clearTimeout(galleryItemRotateTimer);
        clearTimeout(backupMovieTimer);
        $(".movie-close-button").hide();
        $(".tc-media-block-1-swf").animate({ opacity: 0 }, 0);
        $(".tc-media-block-1-img").animate({ opacity: 1 }, 300);
        $f("mediaBlock1Movie").stop();
        $f("mediaBlock1Movie").unload();
        MoviePlays = false;
        

        if (tcMinimized) {
            TCMinMax();
        }
        if (currentIndex == 1) {
            $(".galleryItem1").css("background-image", moviethumb1_bw);
            $(".gallery-top-1").attr("src", moviethumb1);
        }
        else if (currentIndex == 2) {
            $(".galleryItem1").css("background-image", moviethumb2_bw);
            $(".gallery-top-1").attr("src", moviethumb2);
        }

        if (isHomePage) {
            CreateAudio();
        }
        mediaBlockPosition = 1;
        show_hide_Image(mediaBlockArray, mediaBlockPosition);
    }
}

//Gallery Click
//Clears timers, resets elements and unloads the elements
//***DOES NOT SET MEDIABLOCKPOSITION*** -- this is used when the user
//clicks a gallery item other than the movie
function KillMovie() {
    if (MoviePlays) {
        $(".movie-close-button").hide();
        clearTimeout(prePlayTimer);
        clearTimeout(galleryItemRotateTimer);
        clearTimeout(backupMovieTimer);
        $(".tc-media-block-1-swf").animate({ opacity: 0 }, 0);
        $(".tc-media-block-1-img").animate({ opacity: 1 }, 300);
        $f("mediaBlock1Movie").stop();
        $f("mediaBlock1Movie").unload();
        MoviePlays = false;


        if (tcMinimized) {
            TCMinMax();
        }
        if (currentIndex == 1) {
            $(".galleryItem1").css("background-image", moviethumb1_bw);
            $(".gallery-top-1").attr("src", moviethumb1);
        }
        else if (currentIndex == 2) {
            $(".galleryItem1").css("background-image", moviethumb2_bw);
            $(".gallery-top-1").attr("src", moviethumb2);
        }

        if (isHomePage) {
            CreateAudio();
        }
    }
}
//
//Play Movie
//Includes functions playMovie1 and playMovie2 defined in Movies.js
//Uses Variable currentIndex from Movie.js
function LiveMovie() {
    if (!isDiningLanding) {
        if (!(MoviePlays)) {
            if (isHomePage) {
                $('#SongPlayer').html("<b></b>");
            }


            if (currentIndex == 2) {
                $(".gallery-top-1").attr("src", moviethumb2);
                $(".galleryItem1").css("background-image", moviethumb2_bw);
                playMove(moviepath2);
                currentIndex = 1;
            }
            else if (currentIndex == 1) {
                $(".gallery-top-1").attr("src", moviethumb1);
                $(".galleryItem1").css("background-image", moviethumb1_bw);
                playMove(moviepath1);
                currentIndex = 2;
            }
            MoviePlays = true;

            clearTimeout(prePlayTimer);
            clearTimeout(galleryItemRotateTimer);
            clearTimeout(backupMovieTimer);
            backupMovieTimer = setTimeout("show_hide_Image(mediaBlockArray, 1);", 50000);
            $("#MovieBlockContainer").css("display", "block");
            $(".movie-close-button").show();
            $(".tc-media-block-1-swf, .movie-close-button").animate({ opacity: 1 }, 0);
            $(".tc-media-block-1-img").animate({ opacity: 0.5 }, 300);
            prePlayTimer = setTimeout('$f("mediaBlock1Movie").play();', 3500);
        }
    }
    else {
        setTimeout("show_hide_Image(mediaBlockArray, 1);", 500);
    }
}
function DocumentReadyBody() {

    if (location.pathname != "/" && location.pathname != "/default.aspx") {
        $("#tc-bg").animate({ opacity: 0.5 });
        $("#tc-body-content-minmax").show();
    }

    if (location.pathname == "/dining/" || location.pathname == "/dining/default.aspx") {
        isDiningLanding = true;
    }
    tcMinimized = false;
    var movieIsAlive = true;
    $("#tc-body-content-minmax").click(function() {
        TCMinMax();
    });
}
$(document).ready(function() {
    DocumentReadyHeader();
    DocumentReadyBackground();
    DocumentReadyBody();
    DocumentReadyPromotions();
    DocumentReadyGallery();
    DocReadyMovies();
});
