/*	  browser-detect.js

	Just include this file in your html like this

	<script type="text/JavaScript" src="path/browser-detect.js">

	OS test  if (os.isWindows) your code (see which_os for list of os flags)
	Also innerHTML = "Your OS is " +os.platform

	Browser test if(browser.isFirefox) your code (see which_browser for list of browser flags)
	and (browser.version >= 6) your code. (versions are numeric)
*/

/* Because Mozilla versions have more than one
   point e.g. 1.7.2 we'll make this 1.0702 and allow
   for versions like 1.7.12		 */

function format_revision(rv){
	var rvParts = rv.split('.');
	var vr = rvParts[0] + '.';

	/* Pad leading 0 to sub-parts and combine*/
	for (var i = 1; i < rvParts.length; i++){
		vr += /\d{2}$/.exec("0" + rvParts[i]);
	}
	return vr * 1; //casts string to number
}

/* Determine which OS */
function which_os(){
	/* Set default values */
	this.isWindows = false;
	this.isMac = false;
	this.isLinux = false;
	this.isUnix = false;
	this.isSun = false;
	this.isWinCE = false;
	this.isOS_Unk = false;
	this.platform = "Unknown";	   //name of platform/os

	var re =  /windows ce|win|mac|linux|sun|unix/i;

	if (typeof window.navigator.platform != 'undefined') {

		this.platform = window.navigator.platform;

		switch (this.platform.match(re)){
		case "windows ce":
			this.isWinCE = true;
			break;
		case "win":
			this.isWindows = true;
			break;
		case "mac":
			this.isMac = true;
			break;
		case "linux":
			this.isLinux = true;
			break;
		case "unix":
			this.isUnix = true;
			break;
		case "sun":
			this.isSun = true;
			break;
		default:
			this.isOS_Unk = true;
			break;
		}//endcase
	}//endif
}//eof which_os

/* Now create an instance of which_os object an initial values*/
var os =new  which_os();

/* Deterimine which browser */
function which_browser(){

	/* Set default values */
	this.brand = "unk";	 //e.g. IE, Mozilla
	this.isOpera = false;
	this.isMSIE = false;
	this.isMozilla = false;
	this.isFirefox = false;
	this.isChrome = false;
	this.isNetscape = false;
	this.isGecko = false;
	this.isSafari = false;
	this.isOmniWeb = false;
	this.isKonqueror = false;
	this.isKHTML  = false;
	this.isAOL = false;
	this.isHotJava = false;
	this.isUnk = false;

	this.version = 0;
	this.cversion = "0";

	var agent = navigator.userAgent.toLowerCase();

	if (/(opera)\/?/.test(agent)){
		//Even if spoofing identify as opera
		this.brand = "Opera";
		this.isOpera = true;
		if (typeof RegExp.rightContext != "undefined")
			this.version = parseFloat(RegExp.rightContext, 10);
		else
			this.version = agent.match(/opera\/?\s*([\d.]+)/)[1] * 1;
		this.cversion = this.version;
	}
	else if (/msie/.test(agent)){
		this.brand = "MSIE";
		this.isMSIE = true;
		if (typeof RegExp.rightContext != "undefined")
			this.version = parseFloat(RegExp.rightContext, 10);
		else
			this.version = agent.match(/msie\D*([\d.]+)/)[1] * 1;

		this.cversion = this.version;
	}
	else if (/chrome/.test(agent)){
		this.isKHTML  = true;
		this.brand = "Chrome";
		this.isChrome = true;
		this.isKHTML  = true;

		if (/chrome\/(\d{1,3}(\.\d+)*)/.test(agent) ){
		    this.cversion = RegExp['$1'];
		    this.version = format_revision(this.cversion);
                }
	}
	else if (/Netscape/i.test(navigator.vendor)){
		//vendor is new for ver 6 +
		this.brand = "Netscape";
		this.isNetscape = true;
		this.isGecko = true;
		this.cversion = navigator.vendorSub;
		this.version = parseFloat(this.cversion, 10);
	}
	else if (/Firefox/i.test(navigator.vendor)){
		this.brand = "Firefox";
		this.isFirefox = true;
		this.isGecko = true;
		this.cversion = navigator.vendorSub;
		this.version = format_revision(this.cversion);
	}
	else if (/netscape\/?/.test(agent)){
		//anything not above call 4
		this.brand = "Netscape";
		this.isNetscape = true;

		if (typeof RegExp.rightContext != "undefined")
			this.version = parseInt(RegExp.rightContext);
		else
			this.version = agent(/netscape\/?([\d.]+)/)[1] * 1;

		this.cversion = this.version;
	}
	else if (/Gecko/i.test(navigator.product) && /rv:(\d{1,2}(\.\d{1,2}){0,2})/.test(agent) ){
	//everyone claims mozilla in ua,
	//but a Gecko and not any above
	//is mozilla

	this.isGecko = true;
	this.brand = "Mozilla";
	this.isMozilla = true;
	this.cversion = RegExp['$1'];
	this.version = format_revision(this.cversion);
	}
	else if (/aol/.test(agent) )  {
		//don't have a AOL so this is untested
		this.brand = "aol";
		this.isAOL = true;
		if (typeof RegExp.rightContext != "undefined")
			this.version = parseFloat(RegExp.rightContext, 10);
		else
			this.version  = agent.match(/aol\D*([\d.]+)/)[1] * 1;

		this.cversion = this.version;
	}
	else if (/hotjava/.test(agent)) {
		//don't have a HotJava so this is untested
		this.brand = "HotJava";
		this.isHotJava = true;
		this.cversion = navigator.appVersion;
		this.version  = parseFloat(this.cversion, 10);
	}
	else if (/khtml/.test(agent) || /KDE/.test(navigator.vendor)){
		this.isKHTML  = true;

		if (/safari\/(\d{1,3}(\.\d+)*)/.test(agent) ){
		this.brand = "Safari";
		this.isSafari = true;
		this.isKHTML  = true;
		this.cversion = RegExp['$1'];
		this.version = format_revision(this.cversion);
	}
		else if (/konqueror/.test(agent) ) {
			this.brand = "Konqueror";
			this.isKonqueror = true;
			this.cversion = agent.split("/")[3].split(" ")[0];
			this.version = format_revision(this.cversion);
		}
		else if (os.isMac) {
		//don't have a Mac so this is untested
			this.version = 0;
			this.cversion = "0";

			if (!navigator.accentColorName) {
				this.brand = "Safari";
				this.isSafari = true;
			}
			else {
				this.brand = "OmniWeb";
				this.isOmniWeb = true;
			}
		}
		else {
			this.brand = "unk-khtml";
			this.version = 0;
		}
	}
	else {
		//There are too many others
		this.brand = "unknown";
		this.isUnk = true;
		this.version = 0;
		this.cversion = "0";
	}

}//eof which_browser

var browser = new which_browser();

function what_screen() {
	this.VLOWRESWIDTH = 640;
	this.LOWRESWIDTH = 800;
	this.MEDRESWIDTH = 1024;
	this.MEDRES2WIDTH = 1200;
	this.MEDRES3WIDTH = 1280;
	this.HIGHRESWIDTH = 1400;
	this.VHIGHWIDTH = 1600;

	this.VLOWRESHEIGHT = 480;
	this.LOWRESHEIGHT = 600;
	this.MEDRESHEIGHT = 768;
	this.MEDRES2HEIGHT= 900;
	this.MEDRES3HEIGHT = 1024;
	this.HIGHRESHEIGHT = 1050;
	this.VHIGHHEIGHT = 1200;

	this.screenWidth = window.screen.width;
	this.screenHeight = window.screen.height;

	this.is640 = (this.screenWidth == this.VLOWRESWIDTH);
	this.is800 = this.x800 = (this.screenWidth == this.LOWRESWIDTH);
	this.is1024 = this.x1024 = (this.screenWidth == this.MEDRESWIDTH);
	this.is1400 = (this.screenWidth == this.HIGHRESWIDTH);
	this.is1600 = (this.screenWidth == this.VHIGHWIDTH);

	this.isLowRes = this.lowres = (this.screenWidth < this.MEDRESWIDTH);
	this.isMedRes = this.medres = (this.screenWidth >= this.MEDRESWIDTH && this.screenWidth < this.HIGHRESWIDTH);
	this.isHighRes = this.highres = (this.screenWidth >= this.HIGHRESWIDTH);
} //eof prototype Is
var scrn = new what_screen();
