﻿// ================================================= //
// ================================================= //
// Common functionality for all pages.
// Loaded by the master template.xslt

// ================================================= //
// ================================================= //
// FLASH Detection 

// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;

function detectFlash() {
    // Uses AC_OETags.js to detect the falsh version
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (hasReqestedVersion) return true;
    else return false;
}

// ================================================= //
// ================================================= //

function PrintPage() {
    window.print();
}

function ExpandCollapse(sName) {
    if (document.getElementById('div_' + sName).style.display == 'none') {
        document.getElementById('div_' + sName).style.display = 'block';
        document.getElementById('img_' + sName).src = 'images/expanded.gif';
    } else {
        document.getElementById('div_' + sName).style.display = 'none';
        document.getElementById('img_' + sName).src = 'images/collapsed.gif';
    }
};

// find all elements id starting with div_
// set the display to show
function expandAll() {
    var matches = [];
    var searchEles = document.getElementsByTagName('*');
    for (var i = 0; i < searchEles.length; i++) {
        if (searchEles[i].id) {
            if (searchEles[i].id.slice(0, 4) == 'div_') {               
                document.getElementById(searchEles[i].id).style.display = 'block';
                document.getElementById(searchEles[i].id.replace('div_', 'img_')).src = 'images/expanded.gif';

            }
        }
    }
}
// find all elements id starting with div_
// set the display to hide
function collapseAll() {
    var matches = [];
    var searchEles = document.getElementsByTagName('*');
    for (var i = 0; i < searchEles.length; i++) {
        if (searchEles[i].id) {
            if (searchEles[i].id.slice(0, 4) == 'div_') {               
                document.getElementById(searchEles[i].id).style.display = 'none';
                document.getElementById(searchEles[i].id.replace('div_', 'img_')).src = 'images/collapsed.gif';
            }
        }
    }
}

// ================================================= //
// ================================================= //

//function CreateVideoPlayer(_strVideoName, _bAutoPlay, _strElementID, _nWidth, _nHeight) {

//    var nAutoPlay = (_bAutoPlay == true) ? 1 : 0;
//    var strWidth = _nWidth + "px";
//    var strHeight = _nHeight + "px";
//    var strVideoURL = "https://bcmea.s3.amazonaws.com/" + _strVideoName;

//    var strSelector = '#' + _strElementID;
//    $(strSelector).css('height', strHeight);
//    $(strSelector).css('width', strWidth);
//        
//    flowplayer(_strElementID,
//        {
//            src: "video-player/flowplayer.commercial-3.2.7.swf",
//            wmode: 'opaque'
//        }, 
//        {
//        key: '#@525c9d77f61f82ee1ec',
//        clip: {
//            autoPlay: true,
//            autoBuffering: true,
//            url: strVideoURL
//        }
//    }).load();
//  
//};

// ================================================= //
// ================================================= //

function CreateVideoPlayer(_strVideoName, _bAutoPlay, _strElementID, _nWidth, _nHeight) {

    var nAutoPlay = (_bAutoPlay == true) ? 1 : 0;
    var strWidth = _nWidth + "px";
    var strHeight = _nHeight + "px";
    var strVideoURL = "https://bcmea.s3.amazonaws.com/" + _strVideoName;

    var strSelector = '#' + _strElementID;
    var strSelectorTable = '#' + _strElementID + " table";

    if ($(strSelector).length > 0 && $(strSelectorTable).length > 0) {
        $(strSelectorTable).fadeOut(400, function() {
            $(strSelector).animate({ height: strHeight }, 600, function() {

                flowplayer(_strElementID, { src: "video-player/flowplayer.commercial-3.2.7.swf", wmode: 'opaque' }, {
                    key: '#@525c9d77f61f82ee1ec',
                    clip: {
                        autoPlay: true,
                        autoBuffering: true,
                        url: strVideoURL
                    }
                }).load();

            });

        });
    }
    else if ($(strSelector).length > 0 && $(strSelectorTable).length == 0) {

        $(strSelector).css('height', strHeight);
        $(strSelector).css('width', strWidth);

        flowplayer(_strElementID,
            {
                src: "video-player/flowplayer.commercial-3.2.7.swf",
                wmode: 'opaque'
            },
            {
                key: '#@525c9d77f61f82ee1ec',
                clip: {
                    autoPlay: true,
                    autoBuffering: true,
                    url: strVideoURL
                }
            }).load();

    }

};

// ================================================= //
// ================================================= //
