/*****************************************
* - Example of use:-
*
*    window.onload = function() {
* 	
* 	   gp = new gPopup('gp1', true);
* 	   gp.show();
*    }
******************************************/

var ref;

function gPopup( id, center, timeout ) {
		
	this.gpElement = document.getElementById( id );
	
	this.center = center || false;
	this.timeout = timeout || 0;
	
	this.gpElement.hide = hide;
	this.hide = hide;	
	this.show 	  = show;
	
	/*
	* Attach the close function to
	* child elements
	*/
	chNodes = this.gpElement.childNodes;
	for(var i=0;i<chNodes.length;i++) {
		if( chNodes[i].nodeName == 'A' 
		 || chNodes[i].nodeName == 'IMG' ) {
		chNodes[i].gpObj = this;
		}
	}
	

	
	function show() {
		
		/*
		* If we already have a cookie
		* don't show
		*/
		if( readCookie( 'gpopup_'+this.gpElement.id ) ) {
			//return null;
		}
		
		/*
		* make the overlay float
		*/
		this.gpElement.style.position = 'absolute';
		this.gpElement.style.display = 'block';
		
		if( this.center ) {
			
			/*
			* find and set center values
			*/
			var winW = 630, winH = 460;
			
			if (parseInt(navigator.appVersion)>3) {
			 if (navigator.appName=="Netscape") {
			  winW = window.innerWidth;
			  winH = window.innerHeight;
			 }
			 if (navigator.appName.indexOf("Microsoft")!=-1) {
			  winW = document.body.clientWidth;
			  winH = document.body.clientHeight;
			 }
			}
			
			gpH = parseInt(this.gpElement.style.height);
			gpW = parseInt(this.gpElement.style.width);
			
			this.gpElement.style.top = ((winH/2)-(gpH/2))+'px';
			this.gpElement.style.left = ((winW/2)-(gpW/2))+'px';
			
		} else {
			
			this.gpElement.style.top = this.topPos + 'px';
			this.gpElement.style.left = this.leftPos + 'px';
		}
		

		ref = this;
		
		if(document.all)document.getElementById('movie').Play();
		
		if( this.timeout ) {
			setTimeout( hideDelayed, this.timeout );
		}
		
		/*
		* Set cookie
		*/
		//createCookie( 'gpopup_'+this.gpElement.id, 1, 1 );
		
	}
	
	function hide() {
	
		/*
		* Hide the surrounding 
		* gpElement
		*/
		this.gpElement.style.display = 'none';
		if(document.all)document.getElementById('movie').Stop();
	}
	
	function hideDelayed() {

		ref.gpElement.style.display = 'none';
	}


}

/*
* End of class
*/

function gpHide( clsEle ) {
	clsEle.gpObj.hide();
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
