/**
* Copyright © www.xardeau.com
*/
/*
* Get Mouse Pointer Position
*/
var posx = 0;
var posy = 0;
/*document.onmousemove = getMouseXY;*/

/**
* Get browser frame dimensions
*/
var frameWidth = 0;
var frameHeight = 0;
if (self.innerWidth)
{
	frameWidth = self.innerWidth;
	frameHeight = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth)
{
	frameWidth = document.documentElement.clientWidth;
	frameHeight = document.documentElement.clientHeight;
}
else if (document.body)
{
	frameWidth = document.body.clientWidth;
	frameHeight = document.body.clientHeight;
}	

/**
* Get Type of Browser + Version + OS
*/
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();

isNS4 = (document.layers) ? 1 : 0;
isIE4 = (document.all) ? 1 : 0;
isW3C = (document.getElementById && !document.all) ? 1 : 0;

function getCalculatedProperty(objName, property) {

    // ***** W3C Compatible DOM (NN6, Mozilla 16, etc.) *****

    if (isW3C) {
        docObj = document.getElementById(objName);
        if (property == "visibility") {
			cssp = docObj.style.visibility;
			return (cssp == "") ? "inherit" : cssp;
		}
		if (property == "clip") {
		    cssp = docObj.style.clip;
		    if (cssp == "") {
				cssStr = "rect(0px "; 
				cssStr += getCalculatedProperty(objName, "width") + " ";
				cssStr += getCalculatedProperty(objName, "height") + " ";
				cssStr += "0px)";
				return cssStr;
		    }
			return cssp;
		}
		if (property == "zIndex") {
		    cssp = docObj.style.zIndex;
		    return (cssp == "") ? "inherit" : cssp;
		}
		cssp = document.defaultView.getComputedStyle(docObj, "").getPropertyValue(property);
		return (cssp == "") ? "unknown" : cssp;
    }

    // ***** Netscape Navigator 4+ DOM *****

    if (isNS4) {
		docObj = document.layers[objName];
		if (property == "visibility") {
		    cssp = docObj.visibility;
		    return (cssp == "hide") ? "hidden" : (cssp == "show") ? "visible" : "inherit";
		}
		if (property == "clip") {
		    cssStr = "rect(" + docObj.clip.top + "px ";
		    cssStr += docObj.clip.right + "px ";
		    cssStr += docObj.clip.bottom + "px ";
		    cssStr += docObj.clip.left + "px)";
		    return cssStr;
		}
		if ((property == "width") || (property == "height")) {
		    return eval("docObj.clip." + property) + "px";
		}
		if (property == "top") property = "pageY";
		if (property == "left") property = "pageX";

		cssp = eval("docObj." + property);
		if (property != "zIndex") cssp += "px";

		return cssp;
    }

    // ***** Internet Explorer 4+ DOM *****

    if (isIE4) {
		if (property == "width") return eval(objName + ".offsetWidth") + "px";
		if (property == "height") return eval(objName + ".offsetHeight") + "px";

		if (property == "clip") {
		    cssp = eval(objName + ".style.clip");

		    if (cssp == "") {
				cssStr = "rect(0px ";
				cssStr += getCalculatedProperty(objName, "width") + " ";
				cssStr += getCalculatedProperty(objName, "height") + " ";
				cssStr += "0px)";
				return cssStr;
		    }
		    return cssp;
		}
		if (property == "top") return eval(objName + ".offsetTop") + 'px';
		if (property == "left") return eval(objName + ".offsetLeft") + 'px';

	        // Else, use 'currentStyle' to find the rest

		return eval(objName + ".currentStyle." + property);
    }
}
/**
* Get Mouse Coordinates
*/
function getMouseXY(e) {
	var typeEvent;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){
		typeEvent = 'pageXY';
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		typeEvent = 'clientXY';
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	//getElement('xy').innerHTML = "Type= " + typeEvent + ", " + posx + " : " + posy;
}

/**
* Get right mouse click
*/
function isRightMouseClick(e) {
	var rightclick;
	if (!e) var e = window.event;
	if (e.which) rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);
	return rightclick;
}
