﻿var floatingMenuId = 'floatdiv';
var floatingMenu =
{
    targetX: -250,
    targetY: 10,
 
    hasInner: typeof(window.innerWidth) == 'number',
    hasElement: typeof(document.documentElement) == 'object'
        && typeof(document.documentElement.clientWidth) == 'number',
 
    menu:
        document.getElementById
        ? document.getElementById(floatingMenuId)
        : document.all
          ? document.all[floatingMenuId]
          : document.layers[floatingMenuId]
};
 
floatingMenu.move = function ()
{
    floatingMenu.menu.style.left = floatingMenu.nextX + 'px';
    floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
}
 
floatingMenu.computeShifts = function ()
{
    var de = document.documentElement;
 
    floatingMenu.shiftX =  
        floatingMenu.hasInner  
        ? pageXOffset  
        : floatingMenu.hasElement  
          ? de.scrollLeft  
          : document.body.scrollLeft;  
    if (floatingMenu.targetX < 0)
    {
        floatingMenu.shiftX +=
            floatingMenu.hasElement
            ? de.clientWidth
            : document.body.clientWidth;
    }
 
    floatingMenu.shiftY = 
        floatingMenu.hasInner
        ? pageYOffset
        : floatingMenu.hasElement
          ? de.scrollTop
          : document.body.scrollTop;
    if (floatingMenu.targetY < 0)
    {
        if (floatingMenu.hasElement && floatingMenu.hasInner)
        {
            // Handle Opera 8 problems
            floatingMenu.shiftY +=
                de.clientHeight > window.innerHeight
                ? window.innerHeight
                : de.clientHeight
        }
        else
        {
            floatingMenu.shiftY +=
                floatingMenu.hasElement
                ? de.clientHeight
                : document.body.clientHeight;
        }
    }
}
 
floatingMenu.calculateCornerX = function()
{
    if (floatingMenu.targetX != 'center')
        return floatingMenu.shiftX + floatingMenu.targetX;
 
    var width = parseInt(floatingMenu.menu.offsetWidth);
 
    var cornerX =
        floatingMenu.hasElement
        ? (floatingMenu.hasInner
           ? pageXOffset
           : document.documentElement.scrollLeft) + 
          (document.documentElement.clientWidth - width)/2
        : document.body.scrollLeft + 
          (document.body.clientWidth - width)/2;
    return cornerX;
};
 
floatingMenu.calculateCornerY = function()
{
    if (floatingMenu.targetY != 'center')
        return floatingMenu.shiftY + floatingMenu.targetY;
 
    var height = parseInt(floatingMenu.menu.offsetHeight);
 
    // Handle Opera 8 problems
    var clientHeight = 
        floatingMenu.hasElement && floatingMenu.hasInner
        && document.documentElement.clientHeight 
            > window.innerHeight
        ? window.innerHeight
        : document.documentElement.clientHeight
 
    var cornerY =
        floatingMenu.hasElement
        ? (floatingMenu.hasInner  
           ? pageYOffset
           : document.documentElement.scrollTop) + 
          (clientHeight - height)/2
        : document.body.scrollTop + 
          (document.body.clientHeight - height)/2;
    return cornerY;
};
 
floatingMenu.doFloat = function()
{
    var stepX, stepY;
 
    floatingMenu.computeShifts();
 
    var cornerX = floatingMenu.calculateCornerX();
 
    var stepX = (cornerX - floatingMenu.nextX) * .07;
    if (Math.abs(stepX) < .5)
    {
        stepX = cornerX - floatingMenu.nextX;
    }
 
    var cornerY = floatingMenu.calculateCornerY();
 
    var stepY = (cornerY - floatingMenu.nextY) * .07;
    if (Math.abs(stepY) < .5)
    {
        stepY = cornerY - floatingMenu.nextY;
    }
 
    if (Math.abs(stepX) > 0 ||
        Math.abs(stepY) > 0)
    {
        floatingMenu.nextX += stepX;
        floatingMenu.nextY += stepY;
        floatingMenu.move();
    }
 
    setTimeout('floatingMenu.doFloat()', 20);
};
 
// addEvent designed by Aaron Moore
floatingMenu.addEvent = function(element, listener, handler)
{
    if(typeof element[listener] != 'function' || 
       typeof element[listener + '_num'] == 'undefined')
    {
        element[listener + '_num'] = 0;
        if (typeof element[listener] == 'function')
        {
            element[listener + 0] = element[listener];
            element[listener + '_num']++;
        }
        element[listener] = function(e)
        {
            var r = true;
            e = (e) ? e : window.event;
            for(var i = element[listener + '_num'] -1; i >= 0; i--)
            {
                if(element[listener + i](e) == false)
                    r = false;
            }
            return r;
        }
    }
 
    //if handler is not already stored, assign it
    for(var i = 0; i < element[listener + '_num']; i++)
        if(element[listener + i] == handler)
            return;
    element[listener + element[listener + '_num']] = handler;
    element[listener + '_num']++;
};
 
floatingMenu.init = function()
{
    floatingMenu.initSecondary();
    floatingMenu.doFloat();
};
 
// Some browsers init scrollbars only after
// full document load.
floatingMenu.initSecondary = function()
{
    floatingMenu.computeShifts();
    floatingMenu.nextX = floatingMenu.calculateCornerX();
    floatingMenu.nextY = floatingMenu.calculateCornerY();
    floatingMenu.move();
}
 
if (document.layers)
    floatingMenu.addEvent(window, 'onload', floatingMenu.init);
else
{
    floatingMenu.init();
    floatingMenu.addEvent(window, 'onload',
        floatingMenu.initSecondary);
}

/* Script by: www.jtricks.com
 * Version: 20080801
 * Latest version:
 * www.jtricks.com/javascript/navigation/floating_close.html
 */
floatingMenu.hide = function()
{
    floatingMenu.menu.style.display='none';
    return false;
}
 
floatingMenu.show = function()
{
    floatingMenu.menu.style.display='block';
    return false;
}


function addLoadEvent(func) {   // Add New function to onload Event;
    
    var oldonload = window.onload;

    if (typeof window.onload != 'function') {

        window.onload = func;

    } else {

    window.onload = function() {
            if (oldonload) { oldonload(); } func();
        }
    } 
    
  }


function addClickEvent(a, i, func) {
    if (typeof a[i].onclick != 'function') {
        a[i].onclick = func;
    } 
}

var theDiv = '<div id="ExitSplashDiv" onmouseover="javascript:hideexitcancelbuttonimage();StopExitImpactAudio();" style="display:block; width:100%; height:100%; position:absolute; background:#FFFFFF; margin-top:0px; margin-left:0px;" align="center">';
theDiv = theDiv + '<div id="ExitCancelButtonImageDiv" style="background: #ffffff; width: 100%;" align="center"><img src="/images/ImportAlert.jpg" border="0"></div>';
theDiv = theDiv + '<div id="exitsplashimpactaudio" style="width:0px; height:0px; overflow:hidden;" ><embed FlashVars="playlist=/playlist.aspx?Songfile=' + voiceURL + '" width="0" height="0" wmode="transparent" src="/images/mp3player.swf" type="application/x-shockwave-flash"></div>'; // <embed wmode="transparent" src="http://exitsplash.s3.amazonaws.com/player.swf?url=http://exitsplash.s3.amazonaws.com/files/exitsplash6.mp3&mode=play&autostart=true&exit4c5da318029a7" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1" height="1"></embed></div>';
theDiv = theDiv + '<iframe src="' + exitsplashpage + '" width="100%" height="100%" align="middle" frameborder="0"></iframe>';
theDiv = theDiv + '</div>';

theBody = document.body; 
if (!theBody) { theBody = document.getElementById("body"); if (!theBody) { theBody = document.getElementsByTagName("body")[0]; } }
var PreventExitSplash = false;

function DisplayExitSplash() {
    if (PreventExitSplash == false) {
        window.scrollTo(0, 0);
        window.alert(exitsplashalertmessage);
        PreventExitSplash = true;
       if(!document.getElementById("ExitSplashMainOuterLayer")){
	        divtag = document.createElement("div");
        	divtag.setAttribute("id", "ExitSplashMainOuterLayer");
	        divtag.style.position = "absolute";
        	divtag.style.width = "100%";
	        divtag.style.height = "100%";
        	divtag.style.zIndex = "99";
	        divtag.style.left = "0px";
	        divtag.style.top = "0px";
	} else { alert('YES'); divtag = document.getElementById("ExitSplashMainOuterLayer"); }
        divtag.innerHTML = theDiv;
        theBody.innerHTML = "";
        theBody.topMargin = "0px";
        theBody.rightMargin = "0px";
        theBody.bottomMargin = "0px";
        theBody.leftMargin = "0px";
        theBody.style.overflow = "hidden";
        theBody.appendChild(divtag);

        return exitsplashmessage;
    }
}

var a = document.getElementsByTagName('A');

for (var i = 0; i < a.length; i++) {

    if (a[i].target !== '_blank') {

        addClickEvent(a, i, function() {
        PreventExitSplash = true; });
    } else {
        addClickEvent(a, i, function() {
        PreventExitSplash = false; });
    }
}

disablelinksfunc = function() {
    var a = document.getElementsByTagName('A');
    for (var i = 0; i < a.length; i++) {
        if (a[i].target !== '_blank') {
            addClickEvent(a, i, function() {
            PreventExitSplash = true; }); 
         } else { addClickEvent(a, i, function() { PreventExitSplash = false; }); } } }

hideexitcancelbuttonimage = function() { document.getElementById('ExitCancelButtonImageDiv').style.display = 'none'; }

StopExitImpactAudio = function() { var esDiv = document.getElementById('ExitSplashDiv'); var esiaDiv = document.getElementById('exitsplashimpactaudio'); esDiv.removeChild(esiaDiv); }

addLoadEvent(disablelinksfunc);

disableformsfunc = function() { var f = document.getElementsByTagName('FORM'); for (var i = 0; i < f.length; i++) { if (!f[i].onclick) { f[i].onclick = function() { PreventExitSplash = true; } } else if (!f[i].onsubmit) { f[i].onsubmit = function() { PreventExitSplash = true; } } } }

addLoadEvent(disableformsfunc);

// window.onbeforeunload = DisplayExitSplash;


