/*
	User Agent v0.1
	
	Provides methods and properties for browser and Flash Player detection.

*/

if(typeof(TL.UserAgent) == "undefined") TL.UserAgent= new UserAgent();

function UserAgent(){
	var ua = navigator.userAgent.toLowerCase();
	
	var brwsrNameIndex;
	var brwsrNames = ['konqueror','safari','firefox','omniweb','opera','webtv','icab','msie','netscape','camino'];
	
	if(ua.indexOf('netscape6')+1){
		this.Browser = "netscape";
		this.Version = ua.substring((ua.indexOf('netscape6') + 10),(ua.indexOf('netscape6') + 10)+3);
	} else{
		for(var i=0; i<brwsrNames.length; i++){
			brwsrNameIndex = testUA(brwsrNames[i]);
			if(brwsrNameIndex){
				this.Browser = brwsrNames[i];
				break;
			}
		}
	}
	
	if(!this.Browser){
		if (!testUA('compatible')){
			this.Browser = "Netscape Navigator"
			this.Version = ua.substring(8,11);
		}else{
			this.Browser = "unknown";
		}
	}
	if (!this.Version) this.Version = ua.substring((brwsrNameIndex + this.Browser.length),(brwsrNameIndex + this.Browser.length)+3);
	
	this.Version = parseFloat(this.Version);
	
	if (!this.OS)
	{
		if (testUA('linux')) this.OS = "Linux";
		else if (testUA('x11')) this.OS = "Unix";
		else if (testUA('mac')) this.OS = "Mac"
		else if (testUA('win')) this.OS = "Windows"
		else this.OS = "unknown";
	}
	
	function testUA($brwsr){
		var _brwsrNameIndex = ua.indexOf($brwsr) + 1;
		return _brwsrNameIndex;
	}
	
	this.IsWin = true;
	this.IsWin = ua.match(/.*mac.*/) == null;
	
	this.IsMac = false;
	this.IsMac = ua.match(/.*mac.*/) != null;
	
	this.IsModern = getIsModern(this.OS,this.Browser,this.Version);
	
	this.SupportsFlashReplacement = getSupportsFlashReplacement(this.OS,this.Browser,this.Version);
	
	function getIsModern($os,$browser,$version){
		if($os == "Mac"){
			if((($browser == "netscape")&&($version >= 7))||(($browser == "firefox")&&($version >= 1))||(($browser == "msie")&&($version >= 5.2))||(($browser == "opera")&&($version >= 7.5))||(($browser == "camino")&&($version >= 0.8))||(($browser == "safari")&&($version >= 1))){
				return true;
			}else{
				return false;
			}
		}else{
			if((($browser == "netscape")&&($version >= 7))||(($browser == "firefox")&&($version >= 1))||(($browser == "msie")&&($version >= 5))||(($browser == "opera")&&($version >= 7.5))){
				return true;																																						
			}else{
				return false;
			}
		}
	}
	
	function getSupportsFlashReplacement($os,$browser,$version){
		if($os == "Mac"){
			if((($browser == "netscape")&&($version >= 7))||(($browser == "firefox")&&($version >= 1))||(($browser == "msie")&&($version >= 5.2))||(($browser == "opera")&&($version >= 7.5))||(($browser == "camino")&&($version >= 0.8))||(($browser == "safari")&&($version >= 1))){
				return true;
			}else{
				return false;
			}
		}else{
			if((($browser == "netscape")&&($version >= 6))||(($browser == "firefox")&&($version >= 1))||(($browser == "msie")&&($version >= 5))||(($browser == "opera")&&($version >= 7.5))){
				return true;																																						
			}else{
				return false;
			}
		}
	}
	
	
	this.GetFlashPlayerVersion = function(){
		var thisPlayerVersion = new TL.UserAgent.PlayerVersion(0,0,0);
		  if(navigator.plugins && navigator.mimeTypes.length){
			var x = navigator.plugins["Shockwave Flash"];
			
			if(x && x.description) {
			  thisPlayerVersion = new TL.UserAgent.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
			}
		  }else{
			try{
			  var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			  for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				thisPlayerVersion = new TL.UserAgent.PlayerVersion([i,0,0]);
			  }
			}catch(e){}
			
			if (!((TL.UserAgent.Browser == "msie")&&(thisPlayerVersion.major == 6))) { //Do not test minor version for IE and version 6 players
			 
			  try{
				thisPlayerVersion = new TL.UserAgent.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			  }catch(e){}
			}
		  }
		
		  return thisPlayerVersion;
	}

	this.HasFlashPlayerVersion = function($major, $minor, $rev){
		
		var thisVersion = new TL.UserAgent.GetFlashPlayerVersion;
		
		if(thisVersion.major < $major) return false;
		if(thisVersion.major > $major) return true;
		if(thisVersion.minor < $minor) return false;
		if(thisVersion.minor > $minor) return true;
		if(thisVersion.revision < $rev) return false;
		return true;
	}


	this.PlayerVersion = function(arrVersion){
		this.major = parseInt(arrVersion[0]) || 0;
		this.minor = parseInt(arrVersion[1]) || 0;
		this.revision = parseInt(arrVersion[2]) || 0;
	}

	this.HasFlash = function(){
		return TL.UserAgent.HasFlashPlayerVersion(1);
	}
	
	this.UsesActiveX = false;

	if((!this.IsMac)&&(typeof(window.ActiveXObject) != "undefined")){
		this.UsesActiveX = true;
	}
	
	this.isWinIE = this.Browser == "msie" &&  this.OS == "Windows"; 
	this.isMacIE = this.Browser == "msie" &&  this.OS == "Mac";
	this.isOpera = this.Browser == "opera";
	this.isNetscape6 = this.Browser == "netscape" && this.Version < 7;
	this.isSafari = this.Browser == "safari";
	
	this.SupportsDomStatus = (document.addEventListener && !this.isSafari && !this.isOpera &&!this.isNetscape6)||(this.isWinIE);
}
