/*===================================================================
// =Includes responseHTML (c) 2007-2008 xul.fr	Licence Mozilla 1.1
// Oh and I hacked the $#!^ out of this code, I mean its ugly, like your sister.
//===================================================================*/
var greyed = false;
function checkMoz() {
    var browRes = false;
    var agt = navigator.userAgent.toLowerCase();
    var is_gecko = ((!is_khtml) && (navigator.product) && (navigator.product.toLowerCase() == "gecko")) ? true: false;
    var is_gver = 0;
    var is_konq = false;
    var kqPos = agt.indexOf('konqueror');
    if (kqPos != -1) {
        is_konq = true;
        is_minor = parseFloat(agt.substring(kqPos + 10, agt.indexOf(';', kqPos)));
        is_major = parseInt(is_minor);
    }
    var is_getElementById = (document.getElementById) ? "true": "false";
    // 001121-abk
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true": "false";
    // 001127-abk
    var is_documentElement = (document.documentElement) ? "true": "false";
    // 001121-abk
    var is_safari = ((agt.indexOf('safari') != -1) && (agt.indexOf('mac') != -1)) ? true: false;
    var is_khtml = (is_safari || is_konq);
    if (is_gecko) is_gver = navigator.productSub;
    var is_fb = ((agt.indexOf('mozilla/5') != -1) && (agt.indexOf('spoofer') == -1) &&
    (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) &&
    (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1) &&
    (is_gecko) && (navigator.vendor == "Firebird"));
    var is_fx = ((agt.indexOf('mozilla/5') != -1) && (agt.indexOf('spoofer') == -1) &&
    (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) &&
    (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1) &&
    (is_gecko) && ((navigator.vendor == "Firefox") || (agt.indexOf('firefox') != -1)));
    var is_moz = ((agt.indexOf('mozilla/5') != -1) && (agt.indexOf('spoofer') == -1) &&
    (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) &&
    (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1) &&
    (is_gecko) && (!is_fb) && (!is_fx) &&
    ((navigator.vendor == "") || (navigator.vendor == "Mozilla") || (navigator.vendor == "Debian")));
    if ((is_moz) || (is_fb) || (is_fx)) {
        browRes = true;
    }
	return browRes;
}
var dontJS = checkMoz();


function doPopups() {
    if (document.getElementsByTagName && dontJS != true) {
        var links = document.getElementsByTagName("a");
        for (var i = 0; i < links.length; i++) {
            if (links[i].getAttribute("class") == "overlay" || links[i].getAttribute("class") == "overlay video" || links[i].getAttribute("class") == "video" || links[i].className == "overlay" || links[i].className == "overlay video") {
                links[i].onclick = function() {
                    //window.open(this.getAttribute("href"));
                    loadWholePage(this.getAttribute("href"))
                    return false;
                };
            }
        }
    }
}
function dontPopups() {
    if (document.getElementsByTagName && dontJS != true) {
        var links = document.getElementsByTagName("a");
        for (var i = 0; i < links.length; i++) {
            if (links[i].getAttribute("class") == "hidePop") {
                links[i].onclick = function() {
                    //window.open(this.getAttribute("href"));
                    hideVid();
                    loadWholePage("blank.html")
                    return false;
                };
            }
        }
    }
}


function createXHR() {
    var request = false;
    try {
        request = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch(err2) {
        try {
            request = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(err3) {
            try {
                request = new XMLHttpRequest();
            }
            catch(err1) {
                request = false;
            }
        }
    }
    return request;
}
function getBody(content) {
    test = content.toLowerCase();
    // to eliminate case sensitivity
    var x = test.indexOf("<div id=\"video\"");
    if (x == -1) return "";

    x = test.indexOf(">", x);
    if (x == -1) return "";

    var y = test.lastIndexOf("</div>");
    if (y == -1) y = test.lastIndexOf("</html>");
    if (y == -1) y = content.length;
    // If no HTML then just grab everything till end
    return content.slice(x + 1, y);
}
function loadHTML(url, fun, storage, param) {
    var xhr = createXHR();
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4)
        {
            //if(xhr.status == 200)
            {
                storage.innerHTML = getBody(xhr.responseText);
                fun(storage, param);
            }
        }
    };

    xhr.open("GET", url, true);
    xhr.send(null);

}
function processHTML(temp, target) {
    target.innerHTML = temp.innerHTML;
    popup.style.display = "block";
    if (greyed == false) {
        grayOut(true, {
            'zindex': '8'
        });
        greyed = true;
    } else {
        grayOut(false);
        greyed = false;
    }
}
function loadWholePage(url) {
    var y = document.getElementById("storage");
    var x = document.getElementById("displayed");
    loadHTML(url, processHTML, x, y);
}
function processByDOM(responseHTML, target) {
    target.innerHTML = "Extracted by id:<br />";
    // does not work with Chrome/Safari
    //var message = responseHTML.getElementsByTagName("div").namedItem("two").innerHTML;
    var message = responseHTML.getElementsByTagName("div").item(1).innerHTML;
    target.innerHTML += message;
    target.innerHTML += "<br />Extracted by name:<br />";
    message = responseHTML.getElementsByTagName("form").item(0);
    target.innerHTML += message.dyn.value;
}
function accessByDOM(url) {

    //var responseHTML = document.createElement("body");	// Bad for opera
    var responseHTML = document.getElementById("storage");
    var y = document.getElementById("displayed");
    loadHTML(url, processByDOM, responseHTML, y);
}
function makeDisplay() {
    var abody = document.getElementsByTagName("body")[0];
    var anode = document.createElement('div');
    // Create the layer.
    anode.id = 'displayed';
    // Name it so we can find it later
    abody.appendChild(tnode);
    // Add it to the web page
}
function grayOut(vis, options) {
    // Pass true to gray out screen, false to ungray
    // options are optional.  This is a JSON object with the following (optional) properties
    // opacity:0-100         // Lower number = less grayout higher = more of a blackout
    // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
    // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
    // in any order.  Pass only the properties you need to set.
    var options = options || {};
    var zindex = options.zindex || 50;
    var opacity = options.opacity || 70;
    var opaque = (opacity / 100);
    var bgcolor = options.bgcolor || '#000000';
    var dark = document.getElementById('grey');
    if (!dark) {
        // The dark layer doesn't exist, it's never been created.  So we'll
        // create it here and apply some basic styles.
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
        var tbody = document.getElementsByTagName("body")[0];
        var tnode = document.createElement('div');
        // Create the layer.
        tnode.style.position = 'absolute';
        // Position absolutely
        tnode.style.top = '0px';
        // In the top
        tnode.style.left = '0px';
        // Left corner of the page
        tnode.style.overflow = 'hidden';
        // Try to avoid making scroll bars
        tnode.style.display = 'none';
        // Start out Hidden
        tnode.id = 'grey';
        // Name it so we can find it later
        tbody.appendChild(tnode);
        // Add it to the web page
        dark = document.getElementById('grey');
        // Get the object.
    }
    if (vis) {
        // Calculate the page width and height
        if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
            var pageWidth = document.body.scrollWidth + 'px';
            var pageHeight = document.body.scrollHeight + 'px';
        } else if (document.body.offsetWidth) {
            var pageWidth = document.body.offsetWidth + 'px';
            var pageHeight = document.body.offsetHeight + 'px';
        } else {
            var pageWidth = '100%';
            var pageHeight = '100%';
        }
        //set the shader to cover the entire page and make it visible.
        dark.style.opacity = opaque;
        dark.style.MozOpacity = opaque;
        dark.style.filter = 'alpha(opacity=' + opacity + ')';
        dark.style.zIndex = zindex;
        dark.style.backgroundColor = bgcolor;
        dark.style.width = pageWidth;
        dark.style.height = pageHeight;
        dark.style.display = 'block';
    } else {
        dark.style.display = 'none';
    }
}
function hideVid() {
    grey.style.display = "none";
    popup.style.display = "none";
}
function reGrey() {
    if (greyed == true) {
        grayOut(true, {
            'zindex': '8'
        });
    }
}
/*===================================================================
// =Multiple onLoad handler
//===================================================================*/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
/*===================================================================
// =onLoad functions
//===================================================================*/
addLoadEvent(doPopups);
addLoadEvent(dontPopups);
