var xx = 0;
var ss = "";
var lasstEL = null;
GE_Player = function(el) {
	ss += el.href + "\n";
	if (xx++==10) alert(lasstEL == el);
	lasstEL = el;
	this.el = $(el);
	this.parentEl = null;
	this.rootName = null;
	this.replaced = false;
	this.w = null;	//player width
	this.d = null;	//dark color
	this.l = null;	//light color
	this.a = null; //headline anchor element for player
	this.init();
}

GE_Player.prototype.init = function() {
	var tmphref = unescape(this.el.href);
	this.rootName = tmphref.substring(0,tmphref.length-4);
	this.parentEl = document.createElement('span');
	this.el.parentNode.insertBefore(this.parentEl, this.el);
	this.parentEl.appendChild(this.el);
	this.el.observe('click', function(e){Event.stop(e);this.write();}.bind(this));
	this.a = this.el.up().previous('h4');
	if (this.a) this.a.observe('click', function(e){Event.stop(e);this.write();}.bind(this));
	this.prevImage = this.el.up().previous('a');
	if (this.prevImage) this.prevImage.observe('click', function(e){Event.stop(e);this.write();}.bind(this));	
}

GE_Player.prototype.write = function() {
	if (!this.replaced) {
		this.getStyle();
		
		var placeholderId = this.el.parentNode.insert( new Element('div') ).down().identify()
		
		var flashvars = {};
		if (this.w) flashvars.player_width=this.w;
		if (this.d) flashvars.color_dark=this.d;
		if (this.l)flashvars.color_light=this.l;
		flashvars.flv_path=this.rootName + ".flv";
		flashvars.title=this.el.title;

		var params = {};
		params.bgcolor="#FFFFFF";
		params.scale="noscale";
		params.wmode="transparent";

		var attributes = {};
		attributes.id="audioPlayer"
		
		swfobject.embedSWF(GE_baselink + "html_view/flash/audio.swf", placeholderId, (this.w)?this.w:110, "20", "8",null, flashvars, params, attributes);
		
		/*
		var so = new SWFObject( GE_baselink + "html_view/flash/audio.swf", "audioPlayer", (this.w)?this.w:110, "20", "8", "#FFFFFF");
	    so.addParam("wmode", "transparent");
		if (this.w) so.addVariable("player_width", this.w);
		if (this.d) so.addVariable("color_dark", this.d);
		if (this.l) so.addVariable("color_light", this.l);
		so.addVariable("flv_path", this.rootName + ".flv");
		so.addVariable("title", this.el.title);
		so.write(this.el.parentNode);
		*/
		this.replaced = true;
	}
}

GE_Player.prototype.getStyle = function() {
	if (this.el.className.indexOf('customPlayer')>-1) {
		this.el.removeClassName('g_boxed_link');
		this.el.setStyle({display:'block',visibility:'hidden'});
		this.w = parseInt(this.el.getStyle('width'));
		this.d = this.el.getStyle('background-color');
		this.l = this.el.getStyle('color');
	}
}

GE_Main.mapFnToCSS('bhv_audioPlayer',GE_Player);