/***************** FUNCTIONS FOR PLAYING MP3 FILES ************************/

var _demo_play = "להמשעת הקובץ לחצו כאן";
var _demo_stop = "לעצירת הקובץ לחצו כאן";

var mp3_cDemo;
var mp3_cButton;
var mp3_nClass;

function randomString(len) {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = len;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function getPlayerDiv()
{
	if(document.getElementById("MediaPlayerManagerDiv")==null){
		var myDiv = document.createElement("div");
		myDiv.setAttribute("id","MediaPlayerManagerDiv");
		myDiv.style.position = "absolute";
		myDiv.style.top = "-9999px";
		document.body.appendChild(myDiv);
	}
	else
	{
		myDiv = document.getElementById("MediaPlayerManagerDiv");
	}
	return myDiv;
}

function stopButton () {
	myDiv = document.getElementById("MediaPlayerManagerDiv");
	if (myDiv != null) {
		removePlayerButton(myDiv);
	}
	if (mp3_cButton != null && mp3_nClass != null) {
		mp3_cButton.className = mp3_nClass;
		if (mp3_cButton.firstChild && mp3_cButton.firstChild.nodeValue == _demo_stop) mp3_cButton.firstChild.nodeValue = _demo_play;
	}
}

function createPlayerButton(myDiv, demo_file){
	// ADDING RENDOM STRING IS REQUIRED FOR CACHING ISSUES
	if (demo_file == "") return false;

	fmovie = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1">'+
		        '<param name="movie" value="'+_base+'/flashFiles/tmp3_button.swf?unique='+randomString(10)+'&sound_file='+demo_file+'&soundComplete=javascript:stopButton()" />'+
		       ' <!--[if !IE]>-->'+
		       ' <object type="application/x-shockwave-flash" data="'+_base+'/flashFiles/tmp3_button.swf?unique='+randomString(10)+'&sound_file='+demo_file+'&soundComplete=javascript:stopButton()" width="1" height="1">'+
		       ' <!--<![endif]-->'+
		        '<!--[if !IE]>-->'+
		       ' </object>'+
		       ' <!--<![endif]-->'+
		     ' </object>';

	myDiv.innerHTML = fmovie;
}

function removePlayerButton(myDiv){
	myDiv.innerHTML = "";
	mp3_cDemo = null;
}

function mpButton (demo_button, demo_file, def_class, act_class) {
	if (demo_file == "") return false;
	if (def_class == null) def_class = "three";
	if (act_class == null) act_class = "three three_current_active";
	mp3_nClass = def_class;
	myDiv = getPlayerDiv();

	if (mp3_cDemo == demo_file) {
		stopButton();
		return false;
	}

	createPlayerButton(myDiv, demo_file);

	if (mp3_cButton != null) mp3_cButton.className = def_class;
	demo_button.className = act_class;

	mp3_cDemo = demo_file;
	mp3_cButton = demo_button;

	return false;
}

/***************** END MP3 FILES FUNCTIONS ************************/