// -----------------------------------------------------------------------------
// Globals

// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 115;

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);
// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

// Mootools Defines
var hidePlayerBarSlide;
var videoPlayerSlide;
// -----------------------------------------------------------------------------

var versionChecked = false;

function checkFlash(playerWidth, playerHeight) {
    if (!versionChecked) {
        if (hasProductInstall && !hasRequestedVersion) {
            putPlayerProductInstall(playerWidth, playerHeight);
        }

        versionChecked = true;
    }
}

function putPlayerProductInstall(playerWidth, playerHeight) {
    // DO NOT MODIFY THE FOLLOWING FOUR LINES
    // Location visited after installation is complete if installation is required
    var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
    var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

    AC_FL_RunContent(
        "src", "http://www.foxsports.com.au/swf/playerProductInstall",
        "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
        "width", playerWidth,
        "height", playerHeight,
        "align", "middle",
        "id", "VideomModule",
        "quality", "high",
        "bgcolor", "#FFFFFF",
        "name", "VideomModule",
        "wmode", "opaque",
        "allowFullScreen", "true",
        "allowScriptAccess","sameDomain",
        "type", "application/x-shockwave-flash",
        "pluginspage", "http://www.adobe.com/go/getflashplayer");
}

function toggleVideoItem(disable) {
    var whichLayer =  "fsInStoryPlayer";
    var elem, vis;


    if( document.getElementById ) // this is the way the standards work
        elem = document.getElementById( whichLayer );
    else if( document.all ) // this is the way old msie versions work
        elem = document.all[whichLayer];
    else if( document.layers ) // this is the way nn4 works
        elem = document.layers[whichLayer];


    vis = elem.style;
    // if the style.display value is blank we try to figure it out here

    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

    //vis.display = (vis.display==''||vis.display=='block')?'none':'block';

    if(!disable) {
        //var hidePlayerBar = document.getElementById("hidePlayerBar");
        //hidePlayerBar.style.display = (vis.display == "none") ? "block" : "none";

        if(hidePlayerBarSlide && videoPlayerSlide) {
            hidePlayerBarSlide.toggle();
            videoPlayerSlide.toggle();
        }
    } else {
        var hidePlayerBar = $('hidePlayerBar');
        var videoPlayer = $('fsVideoPlayerDiv');

        if(hidePlayerBar && videoPlayer) {
            hidePlayerBar.style.display = "none";
            videoPlayer.style.display = "none";

            hidePlayerBar.parentNode.style.marginBottom = "0px";
            videoPlayer.parentNode.style.marginBottom = "0px";
        }

        leadPicToggle();
    }
}

function leadPicToggle() {
    $$(".video-player-hide").each(function(element){element.removeClass("video-player-hide")});
}

function changeVideoModuleSize(size,id) {
    var obj = document.getElementById(id);
    if (obj) {
        if(size == null || size == undefined) {
            size = 0;
        }

        // Ensuring this works across ff and ie
        obj.setAttribute("height", size);
        obj.style.height = size + "px";
    
        if(size == 0) {
            obj.parentNode.style.marginBottom = "0px";
        } else {
            obj.parentNode.style.marginBottom = "15px";
        }
    }
}

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != "function"){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}
addLoadEvent(initSliders);

function initSliders()
{
    var hidePlayerBar = $('hidePlayerBar');
    var videoPlayer = $('fsVideoPlayerDiv');

    if(hidePlayerBar && videoPlayer) {
        hidePlayerBarSlide = new Fx.Slide(hidePlayerBar);
        videoPlayerSlide = new Fx.Slide(videoPlayer);

        hidePlayerBarSlide.hide(); // Hide the bar
        hidePlayerBar.style.display = "block"; // Allow the bar to be displayed (still hidden)
        videoPlayer.style.display = "block";
    }
}
