﻿var bellHD_videoFile, bellHD_videoPosition, bellHD_autoPlay, bellHD_butImg, bellHD_butLeft, bellHD_butTop, bellHD_vSWFvar, bellHD_vDIVvar, bellHD_pSWFvar, bellHD_pDIVvar, bellHD_cDIVvar;
var bellHD_cookieVar, bellHD_butStart, bellHD_butLast;

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

function bellHD_addOnloadEvent(fnc) {
    if (typeof window.addEventListener != "undefined")
        window.addEventListener("load", fnc, false);
    else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onload", fnc);
    }
    else {
        if (window.onload != null) {
            var oldOnload = window.onload;
            window.onload = function(e) {
                oldOnload(e);
                window[fnc]();
            };
        }
        else
            window.onload = fnc;
    }
}

//Trace SWF action for play button, when clicked do something
function bellHD_playSWF_DoFSCommand(command, args) {
    if (command == "playMovie") {
        bellHD_playMovie();
    }
}

//Trace SWF actions for video
function bellHD_videoSWF_DoFSCommand(command, args) {
    if (command == "stopMovie") {
        bellHD_stopMovie();
    }
    if (command == "sendWidth") {
        bellHD_videoWidth = args;
    }
    if (command == "sendHeight") {
        bellHD_videoHeight = args;
        bellHD_updateVidDimensions();
    }
    if (command == "sendTime") {
        bellHD_sendTime(args);
    }

}

//COOKIE FUNCTIONS
function bellHD_createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function bellHD_readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function bellHD_eraseCookie(name) {
    bellHD_createCookie(name, "", -1);
}

function bellHD_initiatePlayer() {
    //Throw in a little padding, and offset video to correct position
    document.getElementById(bellHD_vDIVvar).style.marginBottom = '0px';
    document.getElementById(bellHD_pDIVvar).style.marginBottom = '5px';
    document.getElementById(bellHD_pDIVvar).style.marginLeft = '5px';

    //Set Button Style
    document.getElementById('bellHD_butImg').style.top = bellHD_butTop;
    document.getElementById('bellHD_butImg').style.left = bellHD_butLeft;

    //Create play button object
    var bellHD_playButtonSWF = new SWFObject("../flash/Clicksaya_play.swf", bellHD_pSWFvar, bellHD_playerWidth, bellHD_playerHeight, "9", "#F8f8f8");
    bellHD_playButtonSWF.addParam("wmode", "transparent");
    bellHD_playButtonSWF.addParam("swliveconnect", "true");
    bellHD_playButtonSWF.addParam("allowscriptaccess", "always");
    bellHD_playButtonSWF.addParam("menu", "false");
    bellHD_playButtonSWF.write(bellHD_pDIVvar);

    //Auto play movie
    if ((bellHD_autoPlay.toLowerCase() == 'yes') || (bellHD_autoPlay.toLowerCase() == 'playonce')) {
        if (((bellHD_autoPlay.toLowerCase() == 'playonce') && bellHD_cookieVar != '1') || (bellHD_autoPlay.toLowerCase() == 'yes')) {
            bellHD_playMovie();
        }
    }

}

//Update position based on bellHD_videoPosition variable
function bellHD_updatePosition() {
    if (bellHD_videoPosition == 'bottomleft') {
        document.getElementById(bellHD_cDIVvar).style.position = 'fixed';
        document.getElementById(bellHD_cDIVvar).style.bottom = '0px';
        document.getElementById(bellHD_cDIVvar).style.left = '0px';
    }
    else if (bellHD_videoPosition == 'bottomright') {
        document.getElementById(bellHD_cDIVvar).style.position = 'fixed';
        document.getElementById(bellHD_cDIVvar).style.bottom = '0px';
        document.getElementById(bellHD_cDIVvar).style.right = '0px';
    }
    else if (bellHD_videoPosition == 'topleft') {
        document.getElementById(bellHD_cDIVvar).style.position = 'fixed';
        document.getElementById(bellHD_cDIVvar).style.top = '0px';
        document.getElementById(bellHD_cDIVvar).style.left = '0px';
    }
    else if (bellHD_videoPosition == 'topright') {
        document.getElementById(bellHD_cDIVvar).style.position = 'fixed';
        document.getElementById(bellHD_cDIVvar).style.top = '0px';
        document.getElementById(bellHD_cDIVvar).style.right = '0px';
    }
    else if (bellHD_videoPosition == 'inlineA') {
        document.getElementById(bellHD_cDIVvar).style.position = 'relative';
        document.getElementById(bellHD_cDIVvar).style.top = '0px';
        document.getElementById(bellHD_cDIVvar).style.right = '0px';
    }
}


//resize video dimensions based on set variables (ie, when .flv loads and returns size)
function bellHD_updateVidDimensions() {
    document.getElementById(bellHD_vSWFvar).width = bellHD_videoWidth;
    document.getElementById(bellHD_vSWFvar).height = bellHD_videoHeight;
}

//Initiate video playback
function bellHD_playMovie() {
    document.getElementById(bellHD_vDIVvar).innerHTML = ''; //Clear existing movies if exist.
    var bellHD_videoSWF = new SWFObject("../flash/Clicksaya_video.swf", bellHD_vSWFvar, bellHD_videoWidth, bellHD_videoHeight, "9", "#F8f8f8");
    bellHD_videoSWF.addParam("wmode", "transparent");
    bellHD_videoSWF.addParam("swliveconnect", "true");
    bellHD_videoSWF.addParam("allowscriptaccess", "always");
    bellHD_videoSWF.addParam("menu", "false");

    //Send custom variables to flash video file
    bellHD_videoSWF.addVariable('_vidName', "../video/" + bellHD_videoFile);
    bellHD_videoSWF.addVariable('videoWidth', bellHD_videoWidth);
    bellHD_videoSWF.addVariable('videoHeight', bellHD_videoHeight);

    bellHD_videoSWF.write(bellHD_vDIVvar);
    //Hide play button, show Video
    document.getElementById(bellHD_pDIVvar).style.display = 'none';
    document.getElementById(bellHD_vDIVvar).style.display = '';

}

//Stop movie, bring back play button
function bellHD_stopMovie() {
    document.getElementById(bellHD_pDIVvar).style.display = '';
    document.getElementById(bellHD_vDIVvar).style.display = 'none';
}

function flipButton(to) {
    if (to == 'hide') {
        document.getElementById('bellHD_butImg').style.display = 'none';
    } else {
        document.getElementById('bellHD_butImg').style.display = '';
    }
}

function bellHD_sendTime(args) {
    if ((args >= bellHD_butStart) && (args <= (bellHD_butStart + bellHD_butLast))) {
        flipButton('show');
    } else {
        flipButton('hide');
    }
}

function bellHD_updateClass() { document.getElementById(bellHD_cDIVvar).className = 'bellHD_ieClass'; }

function ShowRole(filename, position) {
    bellHD_videoFile = filename + ".flv"; // (<-----------------*.flv)
    if (position == null || position == "") bellHD_videoPosition = 'bottomleft'; // (<-----------------'topleft', 'topright', 'bottomleft', 'bottomright', 'inline')
    else bellHD_videoPosition = position;
    bellHD_autoPlay = 'yes'; // (<----------------'Yes', 'No', 'playOnce')

    var bellHD_videoExists = 0;
    if (bellHD_videoExists == 0) {
        if ((bellHD_butImg == undefined) || (bellHD_butImg.length <= 3)) { bellHD_butImg = '../images/blank.gif'; }
        if ((bellHD_butLeft == undefined) || (bellHD_butLeft.length = 0)) { bellHD_butLeft = '0px'; }
        if ((bellHD_butTop == undefined) || (bellHD_butTop.length = 0)) { bellHD_butTop = '0px'; }


        //Div Containers
        bellHD_vSWFvar = 'bellHD_videoSWF';
        bellHD_vDIVvar = 'bellHD_avideoDiv';
        bellHD_pSWFvar = 'bellHD_playSWF';
        bellHD_pDIVvar = 'bellHD_aplayDiv';
        bellHD_cDIVvar = 'bellHD_acontainerDiv';


        //Dimensions (video will auto-resize based on .flv dimensions ;) )
        bellHD_videoWidth = 0; //not needed
        bellHD_videoHeight = 0; //not needed
        bellHD_playerWidth = 114;
        bellHD_playerHeight = 38;

        bellHD_initiatePlayer();

        //Call Update Position, Generic
        bellHD_updatePosition();

        //Update IE Class
        bellHD_updateClass();

        if (bellHD_readCookie('bellHD_view_' + bellHD_videoFile) == null) { bellHD_createCookie('bellHD_view_' + bellHD_videoFile, '1', 30); }
        else { bellHD_cookieVar = bellHD_readCookie('bellHD_view_' + bellHD_videoFile); }


        if (bellHD_butStart == undefined) { bellHD_butStart = 0; }
        if (bellHD_butLast == undefined) { bellHD_butLast = 0; }

        bellHD_videoExists = '1';
    }
}

