var MOUSE_X=0;
var MOUSE_Y=0;

var POS_LEFT=0;
var POS_TOP=0;

var popupPage_w = 500;
var popupPage_h = 400;

if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousedown = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousedown = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousedown = captureMousePosition;
}

function returnWindowCenterPos2(w, h) {
	if (document.all) {
	   /* the following is only available after onLoad */
	   w = document.body.clientWidth;
	   h = document.body.clientHeight;
	}
	else if (document.layers) {
	   w = window.innerWidth;
	   h = window.innerHeight;
	}

	var popW = 300, popH = 200;

	POS_LEFT = (w-popW)/2;
	POS_TOP = (h-popH)/2;
}


_movePopWindowTrigger = false;
_popWindowOffsetX = 0;
_popWindowOffsetY = 0;
_lastPopWindowLeft = 0;
_lastPopWindowTop = 0;

function returnPopupPos(ww, hh) {	
	var myWidth = 0, myHeight = 0, scrollTop=0;

  	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
	    myWidth = window.innerWidth;
    	myHeight = window.innerHeight;
		scrollTop = window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
		scrollTop = document.documentElement.scrollTop; 
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    	//IE 4 compatible
	    myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
		scrollTop = document.body.scrollTop; 
	}  
	
	POS_TOP = _lastPopWindowTop = (myHeight/2) - (hh/2) + scrollTop;
	POS_LEFT = _lastPopWindowLeft = (myWidth/2) - (ww/2);
}

function captureMousePosition(e) {
	var xMousePos = 0; // Horizontal position of the mouse on the screen
	var yMousePos = 0; // Vertical position of the mouse on the screen
	var xMousePosMax = 0; // Width of the page
	var yMousePosMax = 0; // Height of the page
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }

	MOUSE_X=xMousePos;
	MOUSE_Y=yMousePos;
	//alert(MOUSE_X + ", " + MOUSE_Y);
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


function popupPage(vis, options_bg, options_p) {
		// Pass true to gray out screen, false to ungray
		// options are optional.  This is a JSON object with the following (optional) properties
		// opacity:0-100         // Lower number = less grayout higher = more of a blackout 
		// zindex: #             // HTML elements with a higher zindex appear on top of the gray out
		// bgcolor: (#xxxxxx)    // Standard RGB Hex color code
		// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
		// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
		// in any order.  Pass only the properties you need to set.
		var options_bg = options_bg || {}; 		
		var zindex_bg = options_bg.zindex || 50;
		var opacity_bg = options_bg.opacity || 70;
		var opaque_bg = (opacity_bg / 100);
		var bgcolor_bg = options_bg.bgcolor || '#2A2C31';
		var dark=document.getElementById('darkenScreenObject');		
		if (!dark) {
			// The dark layer doesn't exist, it's never been created.  So we'll
			// create it here and apply some basic styles.
			// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
			var tbody = document.getElementsByTagName("body")[0];
			var tnode = document.createElement('div');           // Create the layer.
				tnode.style.position='absolute';                 // Position absolutely
				tnode.style.top='0px';                           // In the top
				tnode.style.left='0px';                          // Left corner of the page
				tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
				tnode.style.display='none';                      // Start out Hidden
				tnode.id='darkenScreenObject';                   // Name it so we can find it later
				tbody.appendChild(tnode);                            // Add it to the web page
			dark=document.getElementById('darkenScreenObject');  // Get the object.
		}
		
		var options_p = options_p || {}; 
		var zindex_p = options_p.zindex || 50;
		var opacity_p = options_p.opacity || 70;
		var opaque_p = (opacity_p / 100);
		var bgcolor_p = options_p.bgcolor || '#ffffff';
		var bordercolor_p = options_p.bordercolor || '#99cc33';
		var popupPage=document.getElementById('popupPage');
		if (!popupPage) {
			// The dark layer doesn't exist, it's never been created.  So we'll
			// create it here and apply some basic styles.
			// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
			var tbody2 = document.getElementsByTagName("body")[0];
			var tnode2 = document.createElement('div');           // Create the layer.
				tnode2.style.position='absolute';                 // Position absolutely				
				tnode2.style.top='0px';                           // In the top
				tnode2.style.left='0px';                          // Left corner of the page
				tnode2.style.overflow='hidden';                   // Try to avoid making scroll bars            
				tnode2.style.display='none';                      // Start out Hidden
				tnode2.id='popupPage';                   // Name it so we can find it later
				tbody2.appendChild(tnode2);                            // Add it to the web page
			popupPage=document.getElementById('popupPage');  // Get the object.
		}
		if (vis) {
			// Calculate the page width and height 
			if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
				var pageWidth = document.body.scrollWidth+'px';
				var pageHeight = document.body.scrollHeight+'px';
			} else if( document.body.offsetWidth ) {
				var pageWidth = document.body.offsetWidth+'px';
				var pageHeight = document.body.offsetHeight+'px';
			} else {
				var pageWidth='100%';
				var pageHeight='100%';
			}   
			//set the shader to cover the entire page and make it visible.
			dark.style.opacity=opaque_bg;                      
			dark.style.MozOpacity=opaque_bg;                   
			dark.style.filter='alpha(opacity='+opacity_bg+')'; 
			dark.style.zIndex=zindex_bg;        
			dark.style.backgroundColor=bgcolor_bg;  
			dark.style.width= pageWidth;
			dark.style.height= pageHeight;
			dark.style.display='block';	
			
			popupPage.style.zIndex=zindex_bg++; 			
			popupPage.style.backgroundColor=bgcolor_p;
			popupPage.style.border="2px solid "+bordercolor_p;			
			popupPage.style.width= popupPage_w+"px";
			popupPage.style.height= popupPage_h+"px";
			popupPage.style.display='block';	
		} else {
			dark.style.display='none';
			popupPage.style.display='none';	
		}
		return popupPage;
}

BrowserDetect.init();
//alert(BrowserDetect.browser);





 