// Detect OS ---------------------------
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";
//
function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
if (!OS){
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
} 



// Init flash title OR plain h1 title --------------------------- 
function writeFlashTitle(id, fl_title, flash_link, btn) {
	if (fl_title != "") {
    //alert(">>" + fl_title);
    var supported_browser = false;
		var flash_swf;
    if (browser == "Netscape Navigator") { supported_browser = true; }
    if (browser == "Internet Explorer") { supported_browser = true; }
    // All other browser do not support flash com... :(
    if (supported_browser == true) {
      var flash_title = fl_title;
    	if (document.getElementById) {		
    		flash_title = flash_title.replace(/&/,"//EN//");
    		flash_title = flash_title.replace(/&/,"//EN//");
    		flash_title = flash_title.replace(/&/,"//EN//");
    		flash_title = flash_title.replace(/&/,"//EN//");
    		if (btn == 'true') { 
					flash_swf = "flash/button_02.swf";
					var fo = new FlashObject(flash_swf, id, "100%", "24", 7);
				} else { 
					flash_swf = "flash/title_06.swf"; 
					var fo = new FlashObject(flash_swf, id, "100%", "30", 7);
				}
    		fo.addParam("wmode", "transparent");
    		fo.addVariable("var_title", flash_title);
				fo.addVariable("var_link", flash_link);
    		fo.write(id,fl_title,flash_link);
    	}
    } else {
			if (flash_link != '') { 
      	document.getElementById(id).innerHTML = "<a href='" + flash_link + "' title='" + fl_title + "'>" + fl_title + "</a>";
			} else {
				document.getElementById(id).innerHTML = fl_title;
			}
    } 
  }
}


var FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "left";
	this.params = new Object();
	this.variables = new Object();
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

var FOP = FlashObject.prototype;
FOP.addParam = function(name, value) { this.params[name] = value; }
FOP.getParams = function() { return this.params; }
FOP.getParam = function(name) { return this.params[name]; }
FOP.addVariable = function(name, value) { this.variables[name] = value; }
FOP.getVariable = function(name) { return this.variables[name]; }
FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { 
        // netscape plugin architecture
        // mozilla / firefox / safari...
        flashHTML += '<embed type="application/x-shockwave-flash" menu="false" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" name="' + this.id + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" name="' + this.id + '" align="' + this.align + '" wmode="transparent">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        flashHTML += '<param name="menu" value="false" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;	
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
    	variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId, escapeTitle, flash_link) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
	  // write plain h1
		if (flash_link != '') {
			document.getElementById(elementId).innerHTML = "<a href='" + flash_link + "' title='" + escapeTitle + "'>" + escapeTitle + "</a>";
		} else {
			document.getElementById(elementId).innerHTML = escapeTitle;
		}
	}	
}



/* ---- detection functions ---- */
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
   			flashversion = y.charAt(y.indexOf('.')-1);
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	return (getFlashVersion() >= ver) ? true:false; }

// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}

