// ----------------------------------------------------------
// INDEX.JS (C)
// Author:	Uwe Griehl
// 		released under the MIT License: http://www.opensource.org/licenses/mit-license.php
// last update:	25-03-2008
// function:	helds all javascript functions and variables needed for
//		web page index.html to start the application
// ----------------------------------------------------------

var INDEX_JS_VERSION="2.12";

// Determine browser and version

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.isFF    = false;  // Firefox
  this.isOP    = false;  // Opera
  this.version = null;
  this.win     = false;	
  this.mac     = false;	
  this.linux     = false;	

  ua = navigator.userAgent.toUpperCase();
  if((ua.indexOf("WIN")!=-1) || (ua.indexOf("32BIT")!=-1))
    this.win = true;
  if(ua.indexOf("MAC")!=-1)
    this.mac = true;
  if(ua.indexOf("LINUX")!=-1)
    this.linux = true;
  this.ua=ua;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
  }

  s = "FIREFOX";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isFF = true;
    this.version = parseFloat(ua.substr(i + s.length+1));
  }

  s = "OPERA";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length+1));
  }

  s = "NETSCAPE6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "GECKO";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
  }

  if(!this.isIE && !this.isFF && !this.isNS && !this.isOP)
  {
    alert("This browser is not supported.\nPlease use Internet Explorer, Firefox, Netscape, Opera or another Gecko compatible browser.");
    return;
  } 
 
} // end of Browser()

var FlashDetect = new function(){
	var self = this;
	self.installed = false;
	self.major = -1;
	self.minor = -1;
	self.revision = -1;
	self.revisionStr = "";
	self.activeXVersion = "";
	var activeXDetectRules = [
		{
			"name":"ShockwaveFlash.ShockwaveFlash.7",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash.6",
			"version":function(obj){
				var version = "6,0,21";
				try{
					obj.AllowScriptAccess = "always";
					version = getActiveXVersion(obj);
				}catch(err){}
				return version;
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash",
			"version":function(obj){
				return getActiveXVersion(obj);
			}
		}
	];
	var getActiveXVersion = function(activeXObj){
		var version = -1;
		try{
			version = activeXObj.GetVariable("$version");
		}catch(err){}
		return version;
	};
	var getActiveXObject = function(name){
		var obj = -1;
		try{
			obj = new ActiveXObject(name);
		}catch(err){}
		return obj;
	};
	var parseActiveXVersion = function(str){
		var versionArray = str.split(",");//replace with regex
		return {
			"major":parseInt(versionArray[0].split(" ")[1], 10),
			"minor":parseInt(versionArray[1], 10),
			"revision":parseInt(versionArray[2], 10),
			"revisionStr":versionArray[2]
		};
	};
	var parseRevisionStrToInt = function(str){
		return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
	};
	self.majorAtLeast = function(version){
		return self.major >= version;
	};
	self.FlashDetect = function(){
		if(navigator.plugins && navigator.plugins.length>0){
			var type = 'application/x-shockwave-flash';
			var mimeTypes = navigator.mimeTypes;
			if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
				var desc = mimeTypes[type].enabledPlugin.description;
				var descParts = desc.split(' ');//replace with regex
				var majorMinor = descParts[2].split('.');
				self.major = parseInt(majorMinor[0], 10);
				self.minor = parseInt(majorMinor[1], 10); 
				self.revisionStr = descParts[3];
				self.revision = parseRevisionStrToInt(self.revisionStr);
				self.installed = true;
			}
		}else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
			var version = -1;
			for(var i=0; i<activeXDetectRules.length && version==-1; i++){
				var obj = getActiveXObject(activeXDetectRules[i].name);
				if(typeof obj == "object"){
					self.installed = true;
					version = activeXDetectRules[i].version(obj);
					if(version!=-1){
						var versionObj = parseActiveXVersion(version);
						self.major = versionObj.major;
						self.minor = versionObj.minor; 
						self.revision = versionObj.revision;
						self.revisionStr = versionObj.revisionStr;
						self.activeXVersion = version;
					}
				}
			}
		}
	}();
}

var browser = new Browser();
var BASEPATH=self.location.href;
BASEPATH=BASEPATH.split("index")[0];

// ----- check Flash Player and version


