// JavaScript Document
var dropdowncompleted = 0;
function popupLeftPosition(popup_width){
	var myWidth = 0, outputWidth;

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  	outputWidth = (myWidth / 2) - (popup_width / 2);
	outputWidth = outputWidth ;
	return outputWidth;
}

function popupTopPosition(){
  	var outputHeight, myHeight = 0;

  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && (document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
	outputHeight = (myHeight / 2) - 50;
	outputHeight = outputHeight;
	return outputHeight;
}

function DropDownEffect(target, destinationTop, maxSpeed)
{	var currentTop = parseInt(target.style.top);
	if(isNaN(currentTop))	currentTop = 0;
	var dropSpeed = 1 + Math.abs(destinationTop - currentTop)/10;
	if(dropSpeed > maxSpeed) 	dropSpeed = maxSpeed;
	if(currentTop < destinationTop)
	{	currentTop += dropSpeed;
		if(currentTop > destinationTop)	currentTop = destinationTop;
	}else
	{	currentTop -= dropSpeed;
		if(currentTop < destinationTop)	currentTop = destinationTop;
	}
	target.style.top = parseInt(currentTop) + "px";
	if (currentTop == destinationTop)
	{	clearInterval(target.animation);
		dropdowncompleted  =1;
	}
}

//with courtesy of Richard Rutter from http://www.splintered.co.uk/experiments/archives/javascript_fade/fade.jsx
function fadeIn(target) 
{   if(target.fade == null) target.fade = 0;
	if (target.fade <= 100) {
			if (target.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				target.style.MozOpacity = (target.fade/100)-.001;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (target.style.opacity!=null) {
				/* CSS3 compatible */
				target.style.opacity = (target.fade/100)-.001;
			} else if (target.style.filter!=null) {
				/* IE's proprietary filter */
				target.style.filter = "alpha(opacity="+target.fade+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}
			target.style.visibility = "visible";
			target.fade += 5;
			if(target.fade>100)
			{	clearInterval(target.animation);
				dropdowncompleted  =1;
			}
	}
}

function getPageHeight() {
	var pagescroll,	winHeight;;
	
	if (window.innerHeight && window.scrollMaxY) {	
		pagescroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		pagescroll = document.body.scrollHeight;
	} else {
		pagescroll = document.body.offsetHeight;
	}
	if (self.innerHeight) {
		winHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		winHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowHeight = document.body.clientHeight;
	}	
	if(pagescroll < winHeight){
		pageHeight = winHeight;
	} else { 
		pageHeight = pagescroll;
	}
	return pageHeight;
}

function lightbox(target)
{	if (target.style.MozOpacity!=null) {
			/* Mozilla's pre-CSS3 proprietary rule */
		target.style.MozOpacity = 0.8;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
	} else if (target.style.opacity!=null) {
				/* CSS3 compatible */
		target.style.opacity = 0.8;
	} else if (target.style.filter!=null) {
				/* IE's proprietary filter */
		target.style.filter = "alpha(opacity=80)";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
	}
	target.style.visibility = "visible";
}

function check_dropdown(popupStyleTop)
{
	if(dropdowncompleted ==1)
		window.onscroll = function() {eval(start(popupStyleTop));};
	else	
		setTimeout("check_dropdown(popupStyleTop)",5);
}

function loadPopup (popup_content,popup_bgcolor,popup_width,effect,popup_left,popup_top,delay,autoscroll){
	var popupId = "WPS_popup_message";
	var popupStyleLeft;
	if(popup_left == "center")
		popupStyleLeft = popupLeftPosition(popup_width);
	else
		popupStyleLeft = popup_left;
	popupStyleTop = popupTopPosition();
	if(popup_top != "center") popupStyleTop = popup_top;
	var popupStyleBorder = "solid medium #000000";
	var popupStyleVisibility = "hidden";	
	document.write('<div id="WPS_popup_message" class="wps_popup" style="margin:auto;width:'+popup_width+'px;background-color:'+popup_bgcolor+';z-index:100;position:absolute;left:'+popupStyleLeft+'px;top:-400px;visibility:'+popupStyleVisibility+'">'+popup_content+'</div>');
	if(effect == "popup")
	{ 	document.getElementById('WPS_popup_message').style.top = popupStyleTop + "px";
		if(delay>0)
			setTimeout("document.getElementById('WPS_popup_message').style.visibility = 'visible'",delay);
		else
			document.getElementById('WPS_popup_message').style.visibility = "visible";
		if(autoscroll==1)
		{
			window.onscroll = function() {eval(start(popupStyleTop));};
		}		
	}
	else if(effect == "dropdown")
	{	document.getElementById('WPS_popup_message').style.visibility = "visible";
		if(delay>0)
		{	setTimeout("document.getElementById('WPS_popup_message').animation = setInterval('DropDownEffect(document.getElementById(\"WPS_popup_message\"),popupStyleTop,10)',60)",delay);
		}else
		{	document.getElementById('WPS_popup_message').animation = setInterval('DropDownEffect(document.getElementById("WPS_popup_message"),popupStyleTop,10)',60);
		}
		if(autoscroll==1)
		{
			setTimeout("check_dropdown(popupStyleTop)",5);
		}
	}
	else if(effect == "fadein")
	{	document.getElementById('WPS_popup_message').style.top = popupStyleTop + "px";
		if(delay>0)
			setTimeout("document.getElementById('WPS_popup_message').animation = setInterval('fadeIn(document.getElementById(\"WPS_popup_message\"))',150)",delay);
		else
			document.getElementById('WPS_popup_message').animation = setInterval('fadeIn(document.getElementById("WPS_popup_message"))',150);
		if(autoscroll==1)
		{
			setTimeout("check_dropdown(popupStyleTop)",5);
		}	
	}
	else if(effect == "lightbox")
	{	pageheight = getPageHeight();
		document.write('<div id="lightbox_div" style="overflow:auto;width:100%;height:'+pageheight+'px;background-color:#000000;z-index:50;position:absolute;left:0px;top:0px;visibility:hidden"></div>');
		document.getElementById('WPS_popup_message').style.top = popupStyleTop + "px";
		if(delay>0)
		{	setTimeout("lightbox(document.getElementById('lightbox_div'))",delay);
			setTimeout("document.getElementById('WPS_popup_message').style.visibility = \"visible\"",delay);
		}
		else
		{	lightbox(document.getElementById('lightbox_div'));
			document.getElementById('WPS_popup_message').style.visibility = "visible";
		}
		if(autoscroll==1)
		{
			window.onscroll = function() {eval(start(popupStyleTop));};
		}
	} 
}

