if (window.Prototype) {
    Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5)) == 6;
    Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5)) == 7;
    Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;
}

function createXMLHTTP() {
    var xmlhttp;
    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();
    else if (window.ActiveXObject)
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    return xmlhttp;
}

function addVideoFav(url) {
    var xmlhttp = createXMLHTTP();
    var result;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.responseText.indexOf('success'))
                alert('This video has been added to your favorites.'); //showPopUp('confirm', 'This video has been added to your favorites.');
            else if (xmlhttp.responseText.indexOf('exists'))
                alert('This video is laready in your favorites.'); //showPopUp('confirm', 'This video is already in your favorites.');
            //if (xmlhttp.responseXML.childNodes[0].childNodes[0].nodeValue == 'SUCCESS' || xmlhttp.responseXML.childNodes[0].childNodes[0].nodeValue.substring(0, 1) == 'A')
            //    alert('This video has been added to your favorites.');
        }
    }
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
}

function removeLesson(url) {
    var xmlhttp = createXMLHTTP();
    var result;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.responseText.indexOf('success')) {
                //location.reload(true);
                raiseAsyncPostback();
                //alert('This lesson has been removed.');//showPopUp('confirm', 'This video has been removed from lesson.');
            }
            else
                alert('This lesson has NOT been removed.');
        }
    }
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
}

function refreshMyLessonPlan() {
    if (jQuery == null || jQuery('#mlpContainer').Length <= 0) {
        return;
    }
    var ajaxUri = '/scripts/drive.ashx?function=refreshMyLessonPlan';
    var selectedPlan = jQuery('#MyLessonPlanList').val();
    if (selectedPlan != null && selectedPlan != '') {
        ajaxUri += '&lessonPlanKey=' + selectedPlan;
    }
    jQuery('#mlpContainer').load(ajaxUri);
}

function loginMyLessonPlan() {
    jQuery("#MlpLoginSubmit").attr("disabled", "disabled");
    jQuery('#mlpContainer').load(
        '/scripts/drive.ashx?function=loginMyLessonPlan&email=' + jQuery('#MlpLoginEmail').val() + '&pass=' + jQuery('#MlpLoginPassword').val(),
        null,
        function() { jQuery("#MlpLoginSubmit").attr("disabled", ""); });
}

function stopPageRefresh() {
    if (window.tPageRefresh) {
        window.clearTimeout(window.tPageRefresh);
    }
}

function thisMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

function openVideo(v, s, c, d) {
    if (v != undefined) vk = v; else vk = 0;
    if (s != undefined) sid = s; else sid = 0;
    if (c != undefined) ck = c; else ck = 0; //category / overridden subsection
    if (d != undefined) dk = d; else dk = 0; //subsection

    if (thisMovie('minidriveplayer') != null)
        thisMovie('minidriveplayer').xstop();

    window.open('/video/driveframe.aspx?mdl=' + vk + '&defaultID=' + ck + '&defaultSSection=' + dk + '&sid=' + sid, 'TheDrive', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=995,height=695');
}

function openVideoInMini(v) {
    thisMovie('minidriveplayer').playAVideo(v);
}

function changeMiniDCategory(ssection) {
    thisMovie('minidriveplayer').changeList(ssection);
}


var start;
var pk;
var loadTimer;
var gk;
var ck;

function openPhoto(p, g, c) {

    if (window.tPageRefresh) {
        window.clearTimeout(window.tPageRefresh);
    }
    var objPhoto = document.getElementById('divPhoto');

    if (p != undefined) pk = p; else pk = 0;
    if (c != undefined) ck = c; else ck = 0;
    if (g != undefined) gk = g; else gk = 0;

    if (objPhoto == null) objPhoto = top.document.getElementById('divPhoto');
    if (objPhoto == null) {
        var posx = 0;
        var posy = 0;

        var scrolly = (document.documentElement) ? document.documentElement.scrollTop : window.pageYOffset
        var scrollx = (document.documentElement) ? document.documentElement.scrollLeft : window.pageXOffset

        var myWidth = 0, myHeight = 0;

        if (typeof (window.innerWidth) == 'number') {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
        }

        posy = scrolly + ((myHeight - 608) / 2);
        posx = scrollx + ((myWidth - 830) / 2);

        //var popUpLayer = document.getElementById('photosHover');
        objPhoto = document.createElement('div');
        objPhoto.id = "photosHoverContainer";
        objPhoto.style.top = (posy == 0) ? posy + 80 + 'px' : posy + 0 + 'px';
        //objPhoto.style.top = '80px';	    
        objPhoto.style.left = posx + 'px';
        objPhoto.style.display = 'block';
        objPhoto.style.position = 'absolute';

        objPhoto.style.zIndex = 200000;
        grayOut(true);

        document.getElementsByTagName("body")[0].appendChild(objPhoto);

        objPhoto.innerHTML = '<iframe  allowtransparency="true" background-color="transparent" id="frmPhoto" name="frmPhoto" src="/photogallery/frame.aspx?pk=' + pk + '&gk=' + gk + '&ck=' + ck + '" width=830 height=620 scrolling=no frameborder=0 marginheight="0" marginwidth="0" hspace="0" vspace="0"></iframe>';
    } else {
        objPhoto.innerHTML = '<iframe  allowtransparency="true" background-color="transparent" id="frmPhoto" name="frmPhoto" src="/photogallery/frame.aspx?pk=' + pk + '&gk=' + gk + '&ck=' + ck + '" width=830 height=620 scrolling=no frameborder=0 marginheight="0" marginwidth="0" hspace="0" vspace="0"></iframe>';
    }
}

function closeLoader() {

    var objPhoto = document.getElementById('divPhoto');
    objPhoto.childNodes[0].style.display = 'none';
    clearInterval(loadTimer);
}

function closePhoto() {
    if (window.tPageRefreshTime) {
        tPageRefresh = setTimeout('refresh()', window.tPageRefreshTime);
    }
    var objPhoto = document.getElementById('photosHoverContainer');
    if (objPhoto.childNodes[0].contentDocument)
        objPhoto.childNodes[0].contentDocument.clear();
    else
        window.top.frmPhoto.document.clear();
    //start = setInterval('doSlide(false, -600)', 40);	
    objPhoto.style.display = 'none'; objPhoto.parentNode.removeChild(objPhoto);
    grayOut(false);
}

function doSlide(blnShow, intStop) {
    var objPhoto = document.getElementById('divPhoto');

    if ((blnShow & parseInt(objPhoto.style.left) < intStop) || (!blnShow & parseInt(objPhoto.style.left) > intStop))
        objPhoto.style.left = (blnShow) ? (parseInt(objPhoto.style.left) + 150).toString() + 'px' : parseInt(objPhoto.style.left) - 150 + 'px';
    else {
        if (blnShow) {
            objPhoto.innerHTML += '<iframe allowtransparency="true" background-color="transparent" id="frmPhoto" name="frmPhoto" src="/photogallery/frame.aspx?pk=' + pk + '&gk=' + gk + '&ck=' + ck + '" width=748 height=449 scrolling=no frameborder=0 marginheight="0" marginwidth="0" hspace="0" vspace="0"></iframe>';
        }
        clearInterval(start);
        if (!blnShow) { objPhoto.style.display = 'none'; objPhoto.parentNode.removeChild(objPhoto); }
    }
}


// IMAGE ROLLOVER FUNCTION
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

/* 
------------------------------------
Sets Date on Home Page
------------------------------------
*/
function get_date() {
    var monthNames = new Array("January", "February", "March", "April", "May", "June", "July",
                           "August", "September", "October", "November", "December");
    var dt = new Date();
    var y = dt.getYear();
    if (y < 1000) y += 1900;

    document.write(monthNames[dt.getMonth()] + " " + dt.getDate() + ", " + y);
}

/* 
------------------------------------
PVII Menu CSS Express Drop-Down Menu
by Project Seven Development
www.projectseven.com
------------------------------------
*/
function P7_ExpMenu() { //v1.1.0.2 by PVII-www.projectseven.com
    if (navigator.appVersion.indexOf("MSIE") == -1) { return; }
    var i, k, g, lg, r = /\s*p7hvr/, nn = '', c, cs = 'p7hvr', bv = 'p7menubar';
    for (i = 0; i < 10; i++) {
        g = document.getElementById(bv + nn); if (g) {
            lg = g.getElementsByTagName("LI"); if (lg) {
                for (k = 0; k < lg.length; k++) {
                    lg[k].onmouseover = function() {
                        c = this.className; cl = (c) ? c + ' ' + cs : cs;
                        this.className = cl;
                    }; lg[k].onmouseout = function() {
                        c = this.className;
                        this.className = (c) ? c.replace(r, '') : '';
                    };
                }
            }
        } nn = i + 1;
    }
}


/* 
------------------------------------
Sets Active Style on Home Page
------------------------------------
*/

function getElementsByClassName(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && document.all) ? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function settab(atab) { var myArray = getElementsByClassName(document, "li", "current_tip"); for (var i = 0, len = myArray.length; i < len; ++i) { myArray[i].className = 'inactive_tip'; } atab.className = 'current_tip'; }

function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}

function showdiv(id) {
    //safe function to show an element with a specified id

    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}

//instruction block
//Show hide divs for instruction - here you place the ids of every element you want.
var instrucids = new Array('pane1', 'pane2', 'pane3', 'pane4', 'pane5');

function switchidInstruc(id) {
    hideallidsInstruc();
    showdiv(id);
}

function hideallidsInstruc() {
    //loop through the array and hide each element by id
    for (var i = 0; i < instrucids.length; i++) {
        hidediv(instrucids[i]);
    }
}

//features and commentary
//Show hide divs - here you place the ids of every element you want.
//var tuneinids= --written dynamically
var fcids;

function switchidFC(id) {
    hideallidsFC();
    showdiv(id);
}

function hideallidsFC() {
    //loop through the array and hide each element by id
    for (var i2 = 0; i2 < fcids.length; i2++) {
        hidediv(fcids[i2]);
    }
}

//tune in tonight
//Show hide divs - here you place the ids of every element you want.
//var tuneinids= --written dynamically
var tuneinids;
var tuneinactivepane = 1;
function switchidTunein(id) {
    hideallidsTunein();
    tuneinactivepane++;
    if (tuneinactivepane > tuneinids.length) tuneinactivepane = 1;
    showdiv('tuneinpane' + tuneinactivepane);
}

function hideallidsTunein() {
    //loop through the array and hide each element by id
    for (var i2 = 0; i2 < tuneinids.length; i2++) {
        hidediv(tuneinids[i2]);
    }
}

var btnActive = 'fcbtn1';
//feat & commentary images are written dynamically
//var fcimgids=new Array('btnNews','btnInstruction','btnEquipment','btnFitness');

function restoreImages(strId) {
    if (strId != btnActive) {
        document.getElementById(btnActive).src = eval(btnActive + 'imgs')[0];
        btnActive = strId;
        document.getElementById(strId).src = eval(strId + 'imgs')[1];
    }
}

/* BEGIN: IMPROVED window.onload
* 
* This hijacks the onload event so that we can use it for our ads.
* Other functions that need to be run at onLoad should be added here.
*/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
/* END: IMPROVED window.onload */

/* BEGIN: AD FUNCTIONS
* 
* These functions are used for iframe ads.
*/
var ary = new Array();
globalTileIndex = 1;

/* Function that defines our ad object.  This is what is stored in the array and passed for injection. */
function clsAd(strDivName, strAdURL, intAdWidth, intAdHeight) {
    this.DivName = strDivName;
    this.Url = strAdURL;
    this.Width = intAdWidth;
    this.Height = intAdHeight;
}

var ord = Math.floor(Math.random() * (10000000000000000000));

function InjectAd(objAd) {
    var adsURL = objAd.Url.replace("[ORD]", ord);
    if ($(objAd.DivName) != null) {
        $(objAd.DivName).innerHTML =
                    '<IFRAME WIDTH=' + objAd.Width + ' onLoad="LoadNextAd();" HEIGHT=' + objAd.Height +
                    ' id="iad_' + objAd.DivName + '" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO BORDERCOLOR=#FFFFFF ALLOWTRANSPARENCY=TRUE ' +
                    ' src="' + adsURL + '">' +
                    '</IFRAME>';
    } else {
        alert('skipped ' + globalTileIndex);
        LoadNextAd();
    }
}

function LoadNextAd() {
    if (globalTileIndex <= ary.length) {
        if (ary[globalTileIndex - 1] != undefined) { InjectAd(ary[globalTileIndex - 1]); globalTileIndex++; } else { globalTileIndex++; LoadNextAd(); }
    }
}
/* Calls the function that injects the ad into the div.  Note that Array.each() function
requires the prototype.js library.*/
function LoadAds() {
    var ord = Math.floor(Math.random() * (10000000000000000000));
    ary.each(
			function(objAd) {
			    InjectAdinGallery(objAd, ord);
			}

		);
}

function WaitForAds() {
    setTimeout(LoadNextAd, 250);
}

function handleEnterPrevent(evt) {
    if (evt.keyCode == Event.KEY_RETURN) {
        // do nothing
        Event.stop(evt);
    }
}

//document.observe('dom:loaded', WaitForAds);
//addLoadEvent(LoadNextAd);

//24/7 implementation
var OAS_url = 'http://oasc10010.247realmedia.com/';
if (window.location.protocol == 'https:')
    OAS_url = 'https://oasc10.247realmedia.com/';
var OAS_sitepage = '';
var OAS_listpos = '';
var OAS_query = '';
var OAS_target = '_top';
var OAS_version = 11;
var OAS_rn = new String(Math.random()); var OAS_rns = OAS_rn.substring(2, 11);
function OAS_NORMAL(pos) {
    document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + OAS_target + '>'); document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" BORDER=0></A>');
}

if ((navigator.userAgent.indexOf('Mozilla/3') != -1) || (navigator.userAgent.indexOf('Mozilla/4.0 webTV') != -1))
    OAS_version = 10;

function OAS_AD(pos) {
    if (OAS_version >= 11)
        OAS_RICH(pos);
    else
        OAS_NORMAL(pos);
}

/* END: AD FUNCTIONS */