function flashDetect(version) {
	if (navigator.plugins['Shockwave Flash']) {
		plugin_descr = navigator.plugins['Shockwave Flash'].description;
		return (parseInt(plugin_descr.substring(plugin_descr.indexOf(".") - 1)) >= version) 
	}
	return false
}

function isFlash() {
	return !(navigator.userAgent.indexOf("iCab") != -1 || navigator.userAgent.indexOf("MSIE 3") != -1);
}

function ieFlashDetect(version) {
	//window.onerror = function() { return true; }
	return new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + version);
}

function flashEnable(version) {
	if (!isFlash()) return false;
	if (navigator.userAgent.indexOf("MSIE") != -1 && 
		navigator.userAgent.indexOf("Windows") != -1 && 
		navigator.userAgent.indexOf("Opera") == -1) 
		return ieFlashDetect(version);
	return flashDetect(version);
}

function flashRegister(name) {
   var today = new Date();
   var expires = new Date();
   expires.setTime(today.getTime() + 1000*60*60*24*365);
   setCookie("flash", name, expires);
}

function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
   + "; path=/";
}

function getCookie(Name) {
	var search = Name + '=';
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search);
		if (offset != -1) { // if cookie exists
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(';', offset);
			// set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
	return '';
}

function isFlashDisabled() {
	return getCookie("flash_is") == "off";
}

function flashSettings(settings) {	
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000*60*60*24*365);
	setCookie("flash_is", settings, expires);
	document.location.reload();	
}


function buildFlashCode(source, width, height, background, transparent) {
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	str += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"'
	str += ' width="' + width + '" height="' + height + '" align="middle">';
	str += '<param name="allowScriptAccess" value="sameDomain">';
	str += '<param name="movie" value="' + source + '">';
	str += '<param name="quality" value="high">';
	if (background) { str += '<param name="bgcolor" value="' + background + '">'; }
	if (transparent) { str += '<param name="wmode" value="transparent">'; }
	str += '<embed quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"';
	str += ' pluginspage="http://www.macromedia.com/go/getflashplayer"';
	str += ' src="' + source + '" width="' + width + '" height="' + height + '"';
	if (background) { str += ' bgcolor="' + background + '"'; }
	if (transparent) { str += ' wmode="transparent"'; }
	str += '></embed></object>';
	return str;
}