var globalQuotes     = ["&quot;With boost here or there, dial-up endures&quot;",
                        "&quot;Propel Software creates faster Web experience -- at a good price.&quot;",
                        "&quot;Web Accelerators -- speed without broadband&quot;",
                        "&quot;In some cases, pages displayed more swiftly than on a high-speed DSL.&quot;",
                        "&quot;Unlike many programs that claim to speed-up Web surfing, this one actually works...&quot;",
                        "&quot;Propel is by far the best solution.&quot;"];
var globalAuthors    = ["Hiawatha Bray - Boston Globe",
                        "Jon Fort - San Jose Mercury News",
                        "Eric Auchard - CNN",
                        "Daniel Tynan - CNET Review",
                        "Larry Magid - CBS News",
                        "Sid, Garrison - New York"];
var globalTimeout    = 5000;
var globalIndex      = 0;
var globalDemoWidth  = 600;
var globalDemoHeight = 400;
var globalDemoStartX = 0;
var globalDemoStartY = 120;

var imageIndex       = 0;
var imageArray       = ["url(res/images/test_bg.jpg):left bottom"];

function myGetElementById(elementId) {
    var element;
    if (document.all) {
        element = document.all[elementId];
    } else {
        element = document.getElementById(elementId);
    }
    return element;
}

function highlightItems() {
    var fieldIds = ["mainNav-hid", "mainNavInner-hid", "subNav-hid", "subNavInner-hid"];
    for (var i = 0; i < fieldIds.length; i++) {
        var field = myGetElementById(fieldIds[i]);
        if (field) {
            var itemId = field.value;
            //window.alert("itemId = " + itemId);
            var item = myGetElementById(itemId);
            if (item) {
                item.className = "highlight";
            }
        }
    }
}

function alternateQuotes() {
    //var idx = Math.floor(Math.random() *  globalQuotes.length);
    //window.alert("idx = " + idx);
    var quote = myGetElementById("bottomQuote");
    var author = myGetElementById("bottomAuthor");
    if (quote && author) {
        quote.innerHTML = globalQuotes[globalIndex];
        author.innerHTML = globalAuthors[globalIndex];
        globalIndex = (globalIndex + 1) % globalQuotes.length;
        window.setTimeout("alternateQuotes()", globalTimeout);
    }
}

function doPageLoaded() {
    highlightItems();
    alternateQuotes();
}

function displayDemo(display) {
    var demo = myGetElementById("demo");
    if (demo) {
        if (display) {
            var posX = (f_clientWidth() - globalDemoWidth) / 2;
            var posY = (f_clientHeight() - globalDemoHeight) / 2;
            if (posX < globalDemoStartX) { posX = globalDemoStartX; }
            if (posY < globalDemoStartY) { posY = globalDemoStartY; }
            demo.style.left = posX + "px";
            demo.style.top = posY + "px";
            demo.style.visibility = "visible";
            demo.innerHTML = getDemoHTML();
        } else {
            demo.style.visibility = "hidden";
            demo.innerHTML = "";
        }
    }
}

function f_clientWidth() {
    return f_filterResults(
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
		
    );
}

function f_clientHeight() {
    return f_filterResults(
       window.innerHeight ? window.innerHeight : 0,
       document.documentElement ? document.documentElement.clientHeight : 0,
        document.body ? document.body.clientHeight : 0
		
    );
}

function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function getDemoHTML() {
    return "<p class=\"alignRight\">[ <a href=\"javascript:displayDemo(false);\">Close Demo</a> ]</p>"
         + "<object width=\"560\" height=\"340\">"
         + "  <param name=\"movie\" value=\"http://www.youtube.com/v/zUoBXpmX6FE&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999\"></param>"
         + "  <param name=\"allowFullScreen\" value=\"true\"></param>"
         + "  <param name=\"allowscriptaccess\" value=\"always\"></param>"
         + "  <embed src=\"http://www.youtube.com/v/zUoBXpmX6FE&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed>"
         + "</object>";
}

function changeHomeImage(forward) {
    var homeBackground = myGetElementById("homeBackground");
    if (forward) {
        imageIndex = (imageIndex + 1 + imageArray.length) % imageArray.length;
    } else {
        imageIndex = (imageIndex - 1 + imageArray.length) % imageArray.length;
    }
    var imageStyles = imageArray[imageIndex].split(":");
    homeBackground.style.backgroundImage = imageStyles[0];
    homeBackground.style.backgroundPosition = imageStyles[1];
}

function toggleObject(objId, method) {
    var objBody = myGetElementById("body-" + objId);
    var objHead = myGetElementById("head-" + objId);
    var objFlag = myGetElementById("flag-" + objId);
    if (objBody) {
        if (method == "expand" || (method == "toggle" && objBody.style.display == "none")) {
            objBody.style.display = "";
            if (objHead) {
                objHead.className = "toggleHeadOn";
            }
            if (objFlag) {
                objFlag.innerHTML = objFlag.innerHTML.replace("+", "-").replace("Expand", "Collapse");
            }
        } else if (method == "collapse" || (method == "toggle" && objBody.style.display != "none")) {
            objBody.style.display = "none";
            if (objHead) {
                objHead.className = "toggleHeadOff";
            }
            if (objFlag) {
                objFlag.innerHTML = objFlag.innerHTML.replace("-", "+").replace("Collapse", "Expand");
            }
        }
    }
}

function toggleObjectsInRange(prefix, start, end, method) {
    for (var i = start; i <= end; i++) {
        var objId = prefix;
        if (i < 10) {
            objId += "0" + i;
        } else {
            objId += "" + i;
        }
        toggleObject(objId, method);
    }
}

function toggleObjectsInList(objIds, method) {
    for (var i = 0; i < objIds.length; i++) {
        toggleObject(objIds[i], method);
    }
}

function hideObject(objId) {
    var obj = myGetElementById(objId);
    if (obj) {
        obj.style.display = "none";
    }
}
// function to scroll automatically to the top of the page
function jumpScroll() {
   	window.scroll(0,0); // horizontal and vertical scroll targets
}

function displayPropelDemo(display) {
    var demo = myGetElementById("demo");
    if (demo) {
        if (display) {
            var posX = (f_clientWidth() - globalDemoWidth) / 2;
            var posY = (f_clientHeight() - globalDemoHeight) / 2;
            if (posX < globalDemoStartX) { posX = globalDemoStartX; }
            if (posY < globalDemoStartY) { posY = globalDemoStartY; }
           demo.style.left = posX + "px";
            demo.style.top = posY + "px";
			f_clientWidth();
		    jumpScroll();// scroll to the top of the page
            demo.style.visibility = "visible";
            demo.innerHTML = getPropelDemoHTML();
        } else {
            demo.style.visibility = "hidden";
            demo.innerHTML = "";
        }
    }
}

function getPropelDemoHTML() {
    return "<p class=\"alignRight\">[ <a href=\"javascript:displayPropelDemo(false);\">Close Demo</a> ]</p>"
         + "<object id=\"player\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" name=\"player\" width=\"560\" height=\"340\">"
         + "  <param name=\"movie\" value=\"player.swf\" />"
         + "  <param name=\"allowfullscreen\" value=\"true\" />"
         + "  <param name=\"allowscriptaccess\" value=\"always\" />"
         + "  <param name=\"flashvars\" value=\"file=propel_accelerator_plus_demo.flv\" />"
         + "  <embed"
         + "    type=\"application/x-shockwave-flash\""
         + "    id=\"player2\""
         + "    name=\"player2\""
         + "    src=\"player.swf\""
         + "    width=\"560\""
         + "    height=\"340\""
         + "    allowscriptaccess=\"always\""
         + "    allowfullscreen=\"true\""
         + "    flashvars=\"file=propel_accelerator_plus_demo.flv\""
         + "  />"
         + "</object>";
}

