﻿//  ***********************************************************************
//  movie.js
//  ***********************************************************************
//  Handles cookie creation and increment
//  Handles switch between movies on page refresh
//  ***********************************************************************
//  11/7/11 -- movie switch on play -- functionized movie creator -- created switch in tc2011.js
//
//All that needs to be changed to change the playing movie are these paths.
//At this time there is only support for 2 movies.
//****************************************************
// Changing these variables will update what movie plays and the thumbs that are shown
// 
//First Movie
// -- Path is location of first movie
// -- thumb1_bw is the location of the black and white thumbnail
// -- thumb1 is color thumb
var moviepath1 = "/media/gallery/monthly-promotion.flv";
var moviethumb1_bw = "url(/media/gallery/movie-1-bw.jpg)";
var moviethumb1 = "/media/gallery/movie-1-color.jpg";
//****************************************************
//****************************************************
//Second Movie
// -- Path is location of second movie
// -- thumb2_bw is the location of the black and white thumbnail
// -- thumb2 is color thumb
var moviepath2 = "/media/gallery/tulalip-casino.flv";
var moviethumb2_bw = "url(/media/gallery/movie-2-bw.jpg)";
var moviethumb2 = "/media/gallery/movie-2-color.jpg";
//****************************************************
//****************************************************
//This variable is rotated to show which movie is currently playing
// -- Updated on cookie read, and on plays of movie
var currentIndex = 1;
//****************************************************
//****************************************************
//Set cookie
function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : ";  expires=" + exdate.toUTCString()) + ";  path=/";
    document.cookie = c_name + "=" + c_value;
    //alert(c_name + " - " + c_value);
}
//****************************************************
//****************************************************
//Get Cookie
function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        //alert(x + " || " + y + " || " + ARRcookies);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function DocReadyMovies() {
    //****************************************************
    //******************************************************     
    //use of Cookie, Code
    var lastMovie = parseInt(getCookie("lastMovie"));
    if (isNaN(lastMovie)) {
        lastMovie = 1;
        setCookie("lastMovie", lastMovie, 1);
        $(".galleryItem1").css("background-image", moviethumb1_bw);
        $(".gallery-top-1").attr("src", moviethumb1);
    }
    else {
        if (lastMovie % 2 == 0) {
            currentIndex = 1;

            $(".galleryItem1").css("background-image", moviethumb1_bw);
            $(".gallery-top-1").attr("src", moviethumb1);
        }
        else {
            currentIndex = 2;

            $(".galleryItem1").css("background-image", moviethumb2_bw);
            $(".gallery-top-1").attr("src", moviethumb2);
        }

        lastMovie = lastMovie + 1;
        setCookie("lastMovie", lastMovie, 1);
    }
    //End Use of Cooke Code
    //******************************************************
}
//******************************************************
//Start Movie creation
function playMove(path) {
    $f("mediaBlock1Movie", { src: "/media/gallery/flowplayer-3.2.7.swf", wmode: "transparent" }, {
        clip: {
            url: path,
            autoBuffering: true,
            autoPlay: false
        },
        canvas: {
            backgroundGradient: "none"
        },
        plugins: {
            controls: null
        },
        onFinish: function() {
            MoviePlays = false;
            setTimeout("CloseActions();", 750);
            this.unload();
            //            clearTimeout(galleryItemRotateTimer);
            //            clearTimeout(backupMovieTimer);
            //            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);
        }
    });
}
//End Movie Creation
function CloseActions() {

    clearTimeout(galleryItemRotateTimer);
    clearTimeout(backupMovieTimer);
    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);


}
//***************************************************
//***************************************************
//Create Audio Function -- called from all 3 movie stops -- only called from homepage
//
//Creates a new audio object
//SHOULD ONLY BE CALLED WHEN ON HOMEPAGE
function CreateAudio() {
    $("#HomeAudioContainer").show();

    var so = new SWFObject("/media/audio/CasinoAudioPlayer-1.swf", "SongPlayer", "50", "47", "9", "#6e798e");
    //so.addVariable("flashVarText", "this is passed in via FlashVars for example only"); // this line is optional, but this example uses the variable and displays this text inside the flash movie
    so.addParam("wmode", "transparent");
    so.write("SongPlayer");

}
//***************************************************
//***************************************************

