/*
 * RealObject embed
 * http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
 *
 * based on a script by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/)
 *
 */

RealObject = function(real, id, w, h, c ) {
	this.real = real;
	this.id = id;
	this.width = w;
	this.height = h;
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.altTxt = "alternative text";
	this.bypassTxt = "";
	this.params = new Object();
	this.variables = new Object();
	if (c) this.color = this.addParam('bgcolor', c);
	this.doDetect = detectReal();
}

RealObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}

RealObject.prototype.getParams = function() {
    return this.params;
}

RealObject.prototype.getParam = function(name) {
    return this.params[name];
}

RealObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}

RealObject.prototype.getVariable = function(name) {
    return this.variables[name];
}

RealObject.prototype.getVariables = function() {
    return this.variables;
}

RealObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

RealObject.prototype.getHTML = function() {
    var realHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        realHTML += '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        realHTML += '<param name="src" value="' + this.real + '" />';
        realHTML += '<param name="console" value="one" />';
        if (this.getParamTags() != null) {
            realHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            realHTML += '<param name="realVars" value="' + this.getVariablePairs() + '" />';
        }
        realHTML += '</object>';
    }
    else { // Everyone else
        realHTML += '<embed type="audio/x-pn-realaudio-plugin" src="' + this.real + '" width="' + this.width + '" height="' + this.height + '" name="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            realHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            realHTML += ' realVars="' + this.getVariablePairs() + '"';
        }
        realHTML += ' console="wp"></embed>';
    }
    return realHTML;
}


RealObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}

RealObject.prototype.write = function(elementId) {
	if( this.doDetect==true) {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}
}

// get value of querystring param
function getQueryParamValue(param) {
	var q = document.location.search;
	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 "";
	}
}


function detectReal() {
 var agt=navigator.userAgent.toLowerCase();
	var ie  = (agt.indexOf("msie") != -1);
	var ns  = (navigator.appName.indexOf("Netscape") != -1);
	var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
	var mac = (agt.indexOf("mac")!=-1);
	var noRealPlug, noWMPlug;

	if (ie && win) {
		var plugin = detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer");
	}
	if (ns || !win) {
		nse = "";
		for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		var plugin = detectNS("audio/x-pn-realaudio-plugin","RealPlayer");
	}
	if (plugin.indexOf("RealPlayer")!=-1) {
		return true;
	} else {
		return false;
	}

}



function detectNS(ClassID,name) {
	n = "";
	if (nse.indexOf(ClassID) != -1)
		if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name;
	return n;
}

function detectIE(ClassID,name) {
	result = false;
	document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))<'+'/'+'SCRIPT>');
	if (result) return name;
	else return '';
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
	}
}

	function checkStatus(playerid)
	{
		playerStatus = document.MediaPlayer.GetPlayState();
		if(playerStatus == 0) self.location.href = playerid;
		else theTimer=setTimeout("checkStatus('"+playerid+"')",500);
	}

