﻿window.onload = function() {
    var boxIds = new Array("FlashObject");
    for (i = 0; i < boxIds.length; i++) {
        if (boxIds[i]) {
            setDiv(boxIds[i]);
        }
    }
    cookieValue = readCookie('FlashObject');
    if (cookieValue == null || cookieValue == '') {
        setCookie('FlashObject', 'BlindDown', 1);
    }
    HideQuickLinksByDefault();
    SetupQuickLinksExpander();
}
function setDiv(id) {
    cookieValue = readCookie(id);
    if (cookieValue == 'BlindUp') {
        document.getElementById('FlashObject').style.display = "none";
        setCookie(id, 'BlindUp', 1);
    } else if (cookieValue == 'BlindDown') {
        setCookie(id, 'BlindDown', 1);
    } 
}
function showToggleText(state,color) {
    if (state == 'up') {
        document.getElementById('state').innerHTML = 'Show +';
    } if (state == 'down') {
        document.getElementById('state').innerHTML = 'Hide -';
        new Effect.Opacity('FlashToggleLink', { from: 0, to: 1, duration: 1 });
    }
}
function doFlashToggle(color) {
    document.write("<a id=\"FlashToggleLink\"><div id=\"state\">Hide -</div></a>");
    
    cookieValue = readCookie('FlashObject');
    if (cookieValue == 'BlindDown') {
        showToggleText('down',color)
    } else if (cookieValue == 'BlindUp') {
        showToggleText('up',color)
        document.getElementById('FlashToggle').style.background = color;
    }
    var ft = document.getElementById('FlashToggleLink');
    if (ft != null) {
        ft.href = "javascript:FlashToggle('FlashObject','" + color + "')";
    }
    
}


function FlashToggle(id, color) {
    cookieValue = readCookie(id);
    if (cookieValue == 'BlindDown') {
        new Effect.SlideUp(id);
            new Effect.Opacity('FlashToggle', { from: 0, to: 1, duration: 2 });
            document.getElementById('FlashToggle').style.background = color;
            new Effect.Opacity('FlashToggleLink', { from: 0, to: 1, duration: 2, afterFinish: showToggleText('up', color) });
            
        setCookie(id, 'BlindUp', 1);
    } else if (cookieValue == 'BlindUp') {
    
    
    
    
            new Effect.SlideDown(id);
            document.getElementById('FlashToggle').style.background = "transparent";
            new Effect.Opacity('FlashToggleLink', { from: 0, to: 1, duration: 2, afterFinish: showToggleText('down',color) });

            setCookie(id, 'BlindDown', 1);
        
    }
}







function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = ";expires=" + date.toGMTString();
    } else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + ";path=/";
}
function readCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}














function ToggleQuickLinks ()
{
    Effect.toggle('ExploreExpanded', 'blind');
    var titleBar = document.getElementById('ExploreLink');
    if (titleBar != null)
    {
        if (titleBar.style.backgroundImage=="url(/images/common/explore-minus.gif)")
        {
            titleBar.style.backgroundImage = "url(/images/common/explore-plus.gif)"
            titleBar.style.color = "#818386";
        }
        else
        {
            titleBar.style.backgroundImage = "url(/images/common/explore-minus.gif)"
            titleBar.style.color = "#ffffff";
        }
    }
}
function SetupQuickLinksExpander ()
{
    var ql = document.getElementById('ExploreLink');
    if (ql != null)
    {
        ql.href="javascript:ToggleQuickLinks()";
    }
}

function HideQuickLinksByDefault ()
{
    var qlc = document.getElementById('ExploreExpanded');
    if (qlc != null)
    {
        qlc.style.display="none";
    } 
}

