var panelSlideDelay = 1;
var panelSlideInc = 10;
var marqueeDelay = 75;
var marqueeInc = 1;

window.onload = function() {
    startMarquee();
}

function SwapImage(imageID, url) {
    var imgObj = document.getElementById(imageID);
    if (imgObj != null) {
        var img = new Image();
        img.src = url;
        imgObj.src = img.src;
    }
}

function toggleSizeStylesheet(title) 
{
    var d = document;
    for (i = 0; (a = d.getElementsByTagName("link")[i]); i++) 
    {
        if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title"))
            a.disabled = true;
        if(a.getAttribute("title") == title) 
            a.disabled = false;
    }
}

function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 240,top = 100');");
}

function togglePanel(text,link,namestart)
{
    var textE=document.getElementById(text);
    var linkE=document.getElementById(link);
    if(!textE || !linkE)
        return;

    if(textE.style.display!="block")
    {
        textE.style.display="block";
        //beginSlideOut(text);
        linkE.style.background = "url('/images/" + namestart + "_down.gif')";
        linkE.style.backgroundRepeat = "no-repeat";
    }
    else
    {
        textE.style.display="none";
        //beginSlideIn(text);
        linkE.style.background = "url('/images/" + namestart + ".gif')";
        linkE.style.backgroundRepeat = "no-repeat";
    }
}

function beginSlideIn(element)
{
    var func = 'updateHeight("' + element + '", 199, -panelSlideInc, panelSlideDelay)';
    setTimeout(func, panelSlideDelay);
}

function beginSlideOut(element)
{
    var func = 'updateHeight("' + element + '", 1, panelSlideInc, panelSlideDelay)';
    setTimeout(func, panelSlideDelay);
}

function updateHeight(element, height, heightInc, timestep)
{
    var textE=document.getElementById(element);
    if (!textE)
        return;

    if(height<=0)
        textE.style.height = "0px";
    else if(height>=200)
        textE.style.height = "200px";
    else
    {
        textE.style.height = height + "px";
        var func = 'updateHeight("' + element + '", ' + (height + heightInc) + ', ' + heightInc + ', panelSlideDelay)';
        setTimeout(func, timestep);
    }
}

function ajax(url, vars, callback) {
    var oXMLHttpRequest = new XMLHttpRequest;
    oXMLHttpRequest.open("POST", url, true);
    oXMLHttpRequest.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");

    oXMLHttpRequest.onreadystatechange = function() {
        if (this.readyState == /*XMLHttpRequest.DONE*/4) {
            callback(this.responseText);
        }
    }

    oXMLHttpRequest.send(vars);
}

function startMarquee() {
    ajax("/MarqueeText.ashx", null, updateMarquee);
    marqueeScroll(0,-4000);
}

function updateMarquee(content) {
    var marqueeObj = document.getElementById('marqueeText');
    if (!marqueeObj)
        return;
    marqueeObj.innerHTML = content;
    marqueeScroll(0, -4000);
}

function marqueeScroll(leftVal,stopVal)
{
    if (!leftVal)
        leftVal = 0;
    //grab some new content for the marquee
    if (leftVal <= stopVal) {
        ajax("/MarqueeText.ashx", null, updateMarquee);
        return;
    }

    var marqueeObj = document.getElementById('marqueeText');
    if (!marqueeObj)
        return;
    marqueeObj.style.left = leftVal + 'px';

    var func = 'marqueeScroll(' + (leftVal - marqueeInc) + ','+stopVal+')';
    setTimeout(func, marqueeDelay);
}

