//initialize
var mBrowser = new browser();

//variables for Flash detection
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var flash7Installed = false;    // boolean. true if flash 7 is installed
var flash8Installed = false;    // boolean. true if flash 8 is installed
var flash9Installed = false;    // boolean. true if flash 9 is installed
var maxVersion = 9;             // highest version we can actually detect
//var hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.2;            // the version of javascript supported

//browser: creates a new browser object
function browser() 
{ 	//generic combination of both browserNS and browserIE
	var sAppName = navigator.appName;
	var sAppVersion = parseInt(navigator.appVersion);
	var sUA = navigator.userAgent.toLowerCase();
	
	this.isWin = false;
	this.isMac = false;
	this.isIE = false
	this.isIE4 = false;
	this.isIE5 = false;
	this.isIE55 = false;
	this.isIE5plus = false;
	this.isIE6 = false;
	this.isIE6plus = false;
	this.isNS = false;
	this.isNS4 = false;
	this.isNS6 = false;
	this.isNS6plus = false;
	this.isSafari = false;
	this.isNotSupported = false;
	this.isDOM1 = false;
	this.plugins = navigator.plugins;
	this.hasFlash = false;
	
	this.styleObj = "";
	this.col1 = "";
	
	//Identify unsupported browser versions (< 4)
	this.isNotSupported = (sAppVersion < 4);

	//Determine platform
	this.isWin = (sUA.indexOf("win")>=1); 
	this.isMac = (sUA.indexOf("mac")>=1); 

	if (sAppName == "Microsoft Internet Explorer") 
	{
		this.isIE = true;

		//create references for x-browser object references
		this.col1 = "all.";
		this.styleObj = ".style";
		this.isIE4 = (sUA.indexOf("msie 4.")>=1);
		this.isIE5 = (sUA.indexOf("msie 5.0")>=1);
		this.isIE55 = (sUA.indexOf("msie 5.5")>=1);
		this.isIE6 = (sUA.indexOf("msie 6")>=1);
		
		if (this.isIE5 || this.isIE55 || this.isIE6) 
		{
			this.isIE5plus = true;
			this.isIE4 = false;
		}
		if (this.isIE6)
		{
			this.isIE6plus = true;
		}
	} 
	else if (sAppName == "Netscape") 
	{
		this.isNS = true;
		if (sAppVersion == 4) 
		{
			this.isNS4 = true;
		}
		if (sAppVersion == 5) 
		{
			this.isNS6 = true;
			this.isNS6plus = true;
		}
		if (sAppVersion > 5) 
		{
			this.isNS6plus = true;
		}
		document.captureEvents(Event.CLICK);
	}
	this.isSafari = this.isMac && (sUA.indexOf("safari")>=1);
	
	//determine DOM1 support
	this.isDOM1 = (document.getElementById)  ? true : false;
	
	//IE5.5 is not fully DOM1 compliant
	if (this.isIE55) { this.isDOM1 = false; }
}
browser.prototype.checkFlash = checkFlash;
browser.prototype.writeWinIEscript = writeWinIEscript;

//writeIEscript: 
function writeWinIEscript() {
	if (this.isIE && this.isWin)
	{
	  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	  document.write('on error resume next \n');
	  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
	  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
	  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
	  document.write('<\/SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}	
}

//checkFlash: determines if the user has Flash, and sets browser object properties
function checkFlash() {
	//for win IE
	this.writeWinIEscript();
	
	var oPlugins = this.plugins;
	
	// If navigator.plugins exists...
	if (oPlugins) 
	{
		// ...then check for flash 2 or flash 3+.
		if (oPlugins["Shockwave Flash 2.0"] || oPlugins["Shockwave Flash"]) 
		{
		  // Some version of Flash was found. Time to figure out which.
		  
		  // Set convenient references to flash 2 and the plugin description.
		  var isVersion2 = oPlugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		  var flashDescription = oPlugins["Shockwave Flash" + isVersion2].description;
		
		  // DEBUGGING: uncomment next line to see the actual description.
		  // alert("Flash plugin description: " + flashDescription);
		  
		  // A flash plugin-description looks like this: Shockwave Flash 4.0 r5
		  // We can get the major version by grabbing the character before the period
		  // note that we don't bother with minor version detection. 
		  // Do that in your movie with $version or getVersion().
		  this.flashVersion = parseInt(flashDescription.substring(16));
		
		  // We found the version, now set appropriate version flags. Make sure
		  // to use >= on the highest version so we don't prevent future version
		  // users from entering the site.
		  flash2Installed = this.flashVersion == 2;    
		  flash3Installed = this.flashVersion == 3;
		  flash4Installed = this.flashVersion == 4;
		  flash5Installed = this.flashVersion == 5;
		  flash6Installed = this.flashVersion == 6;
		  flash7Installed = this.flashVersion == 7;
		  flash8Installed = this.flashVersion == 8;
		  flash9Installed = this.flashVersion >= 9;
		}
	}
	
	// Loop through all versions we're checking, and
	// set actualVersion to highest detected version.
	for (var i = 2; i <= maxVersion; i++) 
	{  
		if (eval("flash" + i + "Installed") == true) 
		{ 
			this.flashVersion = i;
		}
		if (this.flashVersion >= 2)
		{
			this.hasFlash = true;
		}
	}
}