﻿// JScript File

var ieAlpha = false;
var mzAlpha = false;
var alphaStep = 0.075;
var control = null;
var fadertimer = null;
var fadedir = 1

function StartPopup()
{
    control = document.getElementById('orderpopup');
   
    // First we hide the control if it was visible before
    control.style.visibility = 'hidden';
    
    ieAlpha = (control.filters)? true:false;
    mzAlpha = (control.style.MozOpacity)? true: false;
    if (ieAlpha)
    {
        control.filters["alpha"].opacity = 10;
    }
    else
    {
        control.style.MozOpacity = 0.10;
    }
    
    // Then we stop timers if they were active
    if (fadertimer != null)
        window.clearInterval(fadertimer);
        
    // Reposition the control
    repositionPopup(generalx, generaly);
        
    // Start fading in again
    fadedir = 1;
    control.style.visibility = 'visible';
    document.getElementById('content').className = 'popupshown';
    fadertimer = window.setInterval("Fade()" , 100);
}

function Fade()
{	
    ieAlpha = (control.filters)? true:false;
    mzAlpha = (control.style.MozOpacity)? true: false;
    var currentAlpha = (ieAlpha)? ((control.filters["alpha"].opacity)/100):(control.style.MozOpacity);

    if(!currentAlpha) {
	    window.clearInterval(fadertimer);
	    return;
    }

    var finalAlpha;
    var tmpAlpha = 0.1;

    if (fadedir == 1) {
        
	    if ( (currentAlpha + alphaStep) >= 0.90  ) {
		    if (ieAlpha) control.filters["alpha"].opacity = 90
		    else control.style.MozOpacity =  0.90
		    clearInterval(fadertimer);
		    fadertimer = null;
		    // Now wait a sec and start fading out again
		    fadertimer = window.setInterval("Delay()" , 2000);
    		
	    } else {
		    if (ieAlpha) { 
			    control.filters["alpha"].opacity = (parseFloat(currentAlpha) + alphaStep)*100;
		    }
		    else {
			    control.style.MozOpacity = parseFloat(currentAlpha) + alphaStep;
		    }
    			
	    }
    } else {
	    if ( (currentAlpha - alphaStep) < 0.05  ) {
		    if (ieAlpha) control.filters["alpha"].opacity = 5
		    else control.style.MozOpacity =  0.05;	
		    control.style.visibility = "hidden";
		    window.clearInterval(fadertimer);
    		
		    initClose = false;
		    fadedir = 1;
    		
	    } else {
		    if (ieAlpha) control.filters["alpha"].opacity = (currentAlpha - alphaStep)*100
		    else control.style.MozOpacity =  parseFloat(currentAlpha) - alphaStep;				
	    }
    }
}

function Delay()
{
    window.clearTimeout(fadertimer);
    fadertimer = null;
    // Start fading in
    fadedir = -1;
    fadertimer = window.setInterval("Fade()", 100);
}

function repositionPopup (objClickX, objClickY)
{
    var rootH = control.offsetHeight;
    var rootW = control.offsetWidth;

    if (( objClickX + rootW + posOffsetX ) > viewport.width) {
	    if (( objClickX - rootW - posOffsetX ) > 0) {
		    control.style.left = ( objClickX - rootW - posOffsetX ) + "px";
	    } else {
		    control.style.left = ( viewport.scrollX + viewport.width - posOffsetX - rootW ) + "px";
	    }
    } else {
	    control.style.left = (objClickX + posOffsetX) + "px";
    	
    }

    if (( objClickY - rootH + posOffsetY ) < 0 ) {
	    if (( objClickY + rootW - posOffsetY ) < viewport.height ) {
		    control.style.top = ( objClickY - posOffsetY ) + "px";
	    } else {
		    control.style.top = posOffsetY + "px";
	    }
    } else {
	    control.style.top = (objClickY + posOffsetY - rootH) + "px";
    }
}

