if(typeof cookiejar == "undefined") var cookiejar = new Object();
if(typeof cookiejar.js == "undefined") cookiejar.js = new Object();

cookiejar.js.Browser = new function() {
	this.agent = navigator.userAgent.toLowerCase();
	
	this.isMac = /mac os x/.test(this.agent);
	this.isWin = /windows/.test(this.agent);
	
	this.isIE  = /msie/.test(this.agent);
	this.isOpera = /opera/.test(this.agent);
	this.isFireFox = /firefox/.test(this.agent);
	this.isSafari = /safari/.test(this.agent);
	this.isNetscape = /netscape/.test(this.agent);
	this.isMozilla = /mozilla/.test(this.agent);
}

cookiejar.js.SWFObj = new function() {
	var browser = cookiejar.js.Browser;
	this.urlData = "";
	this.MMdoctitle = "";
	this.MMPlayerType = "";
	this.MMredirectURL = "";

	this.attributes = new Array();
	this.attributes["bgcolor"] = SWFProps.bgclr;
	this.attributes["wmode"] = "window";
	this.attributes["loop"] = "false";
	this.attributes["menu"] = "false";
	this.attributes["quality"] = "high";
	this.attributes["scale"] = "noScale";
	this.attributes["allowScriptAccess"] = "sameDomain";
	this.attributes["align"] = "middle";
	this.attributes["FlashVars"] = "";
	this.attributes["type"] = "application/x-shockwave-flash";
	this.attributes["pluginspage"] = "http://www.adobe.com/go/getflashplayer";
	this.attributes["codebase"] = "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab";

	this.ControlVersion = function() {
		var version;
		var axo;
		var e;
		
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			version = axo.GetVariable("$version");
			} catch (e) { }
			
			if (!version) {
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
					version = "WIN 6,0,21,0";
					axo.AllowScriptAccess = "always";
					version = axo.GetVariable("$version");
					} catch (e) { }
			}	
			
			if (!version) {
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
					version = axo.GetVariable("$version");
					} catch (e) { }
				}
				
				if (!version) {
					try {
						axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
						version = "WIN 3,0,18,0";
					} catch (e) { }
				}
				
			if (!version) {
				try {
					axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					version = "WIN 2,0,0,11";
			} catch (e) {
				version = -1;
			}
		}
		return version;
	}

	this.GetSwfVer = function() {
		var flashVer = -1;
		var plugins = navigator.plugins;
		
		if (plugins != null && plugins.length > 0) {
			if (plugins["Shockwave Flash 2.0"] || plugins["Shockwave Flash"]) {
				var swVer2 = plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = plugins["Shockwave Flash" + swVer2].description;			
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		else if (/webtv\/2.6/.test(this.browser)) flashVer = 4;
		else if (/webtv\/2.5/.test(this.browser)) flashVer = 3;
		else if (/webtv/.test(this.browser)) flashVer = 2;
		else if (browser.isIE && browser.isWin && !browser.isOpera) {
			flashVer = this.ControlVersion();
		}	
		return flashVer;
	}

	this.DetectFlashVer = function(reqMajorVer, reqMinorVer, reqRevision) {
		versionStr = this.GetSwfVer();
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(browser.isIE && browser.isWin && !browser.isOpera) {
				tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
				tempString        = tempArray[1];			// "2,0,0,11"
				versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
			} else {
				versionArray      = versionStr.split(".");
			}
			var versionMajor      = versionArray[0];
			var versionMinor      = versionArray[1];
			var versionRevision   = versionArray[2];
			
			if (versionMajor > parseFloat(reqMajorVer)) {
				return true;
			} else if (versionMajor == parseFloat(reqMajorVer)) {
				if (versionMinor > parseFloat(reqMinorVer)) {
					return true;
				} else if (versionMinor == parseFloat(reqMinorVer)) {
					if (versionRevision >= parseFloat(reqRevision))
					return true;
				}
			}
		}
		return false;
	}
	
	this.versionArray = SWFProps.v.split(".");
	this.requiredMajorVersion = this.versionArray[0];
	this.requiredMinorVersion = this.versionArray[1];
	this.requiredRevision = this.versionArray[2];
	this.hasProductInstall = this.DetectFlashVer(6, 0, 65);
	this.hasReqestedVersion = this.DetectFlashVer(this.requiredMajorVersion, this.requiredMinorVersion, this.requiredRevision);
	
	this.AC_AddExtension = function(src, ext) {
		if (src.indexOf('?') != -1) return src.replace(/\?/, ext+'?'); 
		else return src + ext;
	}

	this.AC_GetArgs = function(args, ext, classid, mimeType) {
		var ret = new Object();
		ret.embedAttrs = new Object();
		ret.params = new Object();
		ret.objAttrs = new Object();
		for (var i in args) {
			switch (i) {	
				case "classid":
					break;
				case "pluginspage":
					ret.embedAttrs[i] = args[i];
					break;
				case "src":
					args[i] = this.AC_AddExtension(args[i], ext);  
					ret.embedAttrs["src"] = args[i];
					break;
				case "movie":	
					args[i] = this.AC_AddExtension(args[i], ext);
					ret.params["movie"] = args[i];
					break;
				case "name":
					ret.embedAttrs[i] = args[i];
					break;
				case "codebase":
				case "type":
				case "id":
					ret.objAttrs[i] = args[i];
					break;
				case "width":
				case "height":
				case "align":
					ret.embedAttrs[i] = ret.objAttrs[i] = args[i];
					break;
				default:
					ret.embedAttrs[i] = ret.params[i] = args[i];
					break;
			}
		}
		ret.objAttrs["classid"] = classid;
		if (mimeType) ret.embedAttrs["type"] = mimeType;
		if (ret.embedAttrs["FlashVars"]!="") ret.params["FlashVars"] = ret.embedAttrs["FlashVars"] += "&" + this.urlData;
		else ret.params["FlashVars"] = ret.embedAttrs["FlashVars"] += this.urlData;
		ret.params["FlashVars"] = ret.embedAttrs["FlashVars"] = this.encodeFV(ret.params["FlashVars"]);
		return ret;
	}

	this.encodeFV = function(fv) {
		var pairs = fv.split("&");
		var str = "";
		for (var i=0;i<pairs.length;i++) {
			var tmp = pairs[i].split("=");
			if (tmp[0]!="v" && tmp[0]!="s" && tmp[0]!="m" && tmp[0]!="baseURL") tmp[0] = tmp[0]+"_fv";
			str += tmp[0]+"="+tmp[1];
		
			if (i!=pairs.length-1) str += "&";
		}
		return str;
	}

	this.AC_Generateobj = function(objAttrs, params, embedAttrs, _w, _h) { 
		var str = '';
		if (browser.isIE && browser.isWin && !browser.isOpera) {
			str += '<object ';
			for (var i in objAttrs) str += i + '="' + objAttrs[i] + '" ';
			str += '>';
			for (var i in params) str += '<param name="' + i + '" value="' + params[i] + '" /> ';
			str += '</object>';
		} else {
			str += '<embed ';
			for (var i in embedAttrs)
			str += i + '="' + embedAttrs[i] + '" ';
			str += '> </embed>';
		}
		document.getElementById(SWFProps.div).innerHTML = str;
	}

	this.outputHTML = function() {
		var urlParams = this.getURLParams();
		var deeplink = this.getDeeplink();
		var domain = "";
		if (location.href.indexOf("file:")<0) domain = "baseURL=http://"+location.host+"/";
	
		if (urlParams.length>0) {
			this.urlData = domain + "&" +urlParams;
		} else {
			this.urlData = domain;
		}
		//alert("domain: "+domain);
		//alert("urlParams: "+urlParams);
		//alert("search: "+window.location.search);
		//alert("location: "+window.location);
		//alert("Deeplink: "+this.getDeeplink());
		if(this.hasProductInstall && !this.hasReqestedVersion && SWFProps.isExpress) {
			this.MMPlayerType = (browser.isIE == true) ? "ActiveX" : "PlugIn";
			this.MMredirectURL = window.location;
			document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			this.MMdoctitle = document.title;
			this.attributes["FlashVars"] = "MMredirectURL="+this.MMredirectURL+"&MMplayerType="+this.MMPlayerType+"&MMdoctitle="+this.MMdoctitle;
			this.attributes["name"] = this.attributes["id"] = SWFProps.iswf;
			this.attributes["src"] = this.attributes["movie"] = SWFProps.path + SWFProps.iswf;
			this.attributes["width"] = SWFProps.iw;
			this.attributes["height"] = SWFProps.ih;
			var ret = this.AC_GetArgs(this.attributes, ".swf", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
			this.AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs, SWFProps.iw, SWFProps.ih);
		} else if (this.hasReqestedVersion) {
			this.attributes["name"] = this.attributes["id"] = SWFProps.swf;
			this.attributes["src"] = this.attributes["movie"] = SWFProps.path + SWFProps.swf;
			this.attributes["width"] = SWFProps.w;
			this.attributes["height"] = SWFProps.h;
			var ret = this.AC_GetArgs(this.attributes, ".swf", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
			this.AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs, SWFProps.w, SWFProps.h);
		} else {
			document.getElementById(SWFProps.div).innerHTML = "Unable to embed SWF into HTML.";
		}
	}
	
	this.setAttribute = function(name, value) {
		this.attributes[name] = value;
	}
	
	this.getURLParams = function() {
		if (window.location.href.indexOf("?")>1) {
			str = window.location.href.split("?");
			return str[1];
		} else {
			return "";
		}
	}
	
	this.getDeeplink = function() {
		var str = window.location;
		return "";
	}
	
	this.regExReplace = function(str, reg, rep) {
		var s = unescape(str);
		var re = new RegExp(eval(unescape(reg)));
		return s.replace(re, unescape(rep));
	}
	
	this.regExpMatch = function(str, reg) {
		var s = unescape(str);
		var arr = s.match(eval(unescape(reg)));
		return this.encodeArray(arr);
	}
	
	this.encodeArray = function(arr) {
		for (var i=0; i<arr.length;i++) {
			arr[i] = encodeURIComponent(arr[i]);
		}
		return arr;
	}

	this.window_stack = new Array();
	this.createPopupWindow = function(url,name,props) {
		var newWin = window.open(url,name,props);
		this.window_stack[name] = newWin;
	}
	this.closePopup = function(name) {
		this.window_stack[name].close();
	}
	
	this.setUserIcon = function(iconPath) {
		var AIM_location = "aim:BuddyIcon?Src="+iconPath;
		location.href = AIM_location;
		return true;
	}
}

SWFObj = cookiejar.js.SWFObj;