var scrOfX = 0,
scrOfY = 0;
windowOpen = 0;
var myWidth = 0,
myHeight = 0;
function lighterwindowclose() {
    windowOpen = 0;
    myframe = document.getElementById('iframecontent');
    myframe.innerHTML = '&nbsp;';
    document.getElementById('floater').style.display = 'none';
    document.getElementById('iframeholder').style.display = 'none';
}
function getScrollXY() {

    if (typeof(window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    // return [ scrOfX, scrOfY ];
}


function SetOpacity(elem, opacityAsInt)
 {
    var opacityAsDecimal = opacityAsInt;

    if (opacityAsInt > 100)
    opacityAsInt = opacityAsDecimal = 100;
    else if (opacityAsInt < 0)
    opacityAsInt = opacityAsDecimal = 0;

    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
    opacityAsInt = 1;
    // IE7 bug, text smoothing cuts out if 0
    elem.style.opacity = opacityAsDecimal;
    elem.style.filter = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
 {
    var steps = Math.ceil(fps * (time / 1000));
    var delta = (toOpacity - fromOpacity) / steps;

    FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
 {
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
    setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum + 1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}

window.onresize = function(event) {
    if (windowOpen == 1) {
        //lighterwindow(lastVal);
        getWidthHeight();
        document.getElementById('ifrm').width = myWidth - 100;
        document.getElementById('ifrm').height = myHeight - 100;
    }
}

function getWidthHeight() {

    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;
    }

}
function lighterwindow(myVal) {
    lastVal = myVal;
    windowOpen = 1;
    if (typeof document.body.style.maxHeight != "undefined") {
        isIE6 = 0;
    } else {
        isIE6 = 1;
    }

    myObj = document.getElementById('floater');
    getWidthHeight();
    getScrollXY();
    myObj.style.height = (scrOfY + myHeight) + "px";
    myframe = document.getElementById('iframecontent');
    myframe.style.top = scrOfY + "px";
    myframe.innerHTML = '<iframe id="ifrm" border="0" frameborder="0" width="' + (myWidth - 20) + '" height="' + (myHeight - 30) + '" src="' + myVal + '"></iframe>';
    myObj.style.display = 'block';
    ifholder = document.getElementById('iframeholder');

    ifholder.style.display = 'block';
    ifholder.style.left = "10px";
    if (isIE6) {
        ifholder.style.position = "absolute";
        ifholder.style.top = (scrOfY + 10) + "px"
    } else {
        ifholder.style.top = "10px";
    }
    FadeOpacity("floater", 0, 70, 600, 30);

    return false;

}
function initlighterwindow() {
    myObj = document.getElementById('lighterwindow');
    myObj.innerHTML = '<div id="floater" style="z-index:9998; left:0px; top: 0px; right:0px; background-color:#000000; width:100%; position:absolute;-moz-opacity:.50; filter:alpha(opacity=50); opacity:.50; display:none" onclick="lighterwindowclose();"></div><div id="iframeholder" style="z-index:9999; left:0px; right:0px; position:fixed; display:none"><div align="right" style="padding-right:60px; color:#FFFFFF"><a href="javascript:lighterwindowclose();"><font color="#FFFFFF">Close Window</font></a></div><div id="iframecontent"></div></div>';
}
function setLinks()
 {

    var theLinks = document.getElementsByTagName('a');
    //alert(theLinks.length);
    for (var i = 0; i < theLinks.length; i++)
    {
        if (theLinks[i].getAttribute('className') == 'lightwindow' || theLinks[i].getAttribute('class') == 'lightwindow')
        {
            theLinks[i].onclick = function() {
                lighterwindow(this.href);
                return false;
            };

        }
    }
    initlighterwindow();
}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
addLoadEvent(setLinks);
