// check if can be removed
/*function getElementsByClass(searchClass)
{
	elms = new Array();
	cnt = 0;
	allElms = document.getElementsByTagName("*");
	for(i = 0; i < allElms.length; i++)
	{
		if(allElms[i].className.indexOf(searchClass) != -1)
		{
			elms[cnt++] = allElms[i];
		}
	}
	return elms;
}*/
var active_entry = 0;
var active_entry_base64 = 0;

function openWin(uri)
{
	winOpen = window.open(uri, 'buma_window', 'width=600,height=900,scrollbars=yes,toolbar=no,location=no,resizable=yes');
}

function thisMovie(swf)
{
	if(navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[swf];
	}
	else
	{
		return document[swf];
	}
};

function sendEvent(swf,typ,prm)
{ 
	thisMovie(swf).sendEvent(typ,prm); 
};

function getUpdate(typ,pr1,pr2,swf)
{
	if (typ == "state" && (active_entry != 0))
	{
		if (pr1 == 0)
		{
			$(active_entry).firstChild.innerHTML = "<img class=\"ico over\" src=\"/images/ico-play.gif\" width=\"16\" height=\"16\" alt=\"Play\" />";
		}
		else if (pr1 == 2)
		{
			$(active_entry).firstChild.innerHTML = "<img class=\"ico over\" src=\"/images/ico-pause.gif\" width=\"16\" height=\"16\" alt=\"Pause\" />";
		}
	}
};

function loadFile(swf,obj)
{
	thisMovie(swf).loadFile(obj);
};

function playfile(swf,obj)
{
//	sendEvent(swf, 'stop');
	loadFile(swf,obj);
	sendEvent(swf, 'playpause');
	//sendEvent(swf, 'playpause');
	//sendEvent(swf, 'playitem, 1');
	//room for more functions
};

function listen(entry_id, html_id)
{
	if (active_entry != html_id)
	{
		// create waiting icon
		if (active_entry != 0)
		{
			$(active_entry).innerHTML = "<a href=\"javascript:void(0);\" onclick=\"listen('"+active_entry_base64+"','"+active_entry+"');\"><img class=\"ico\" src=\"/images/ico-play.gif\" width=\"16\" height=\"16\" alt=\"\" /></a>";
		}
		active_entry = html_id;
		active_entry_base64 = entry_id;
		$(html_id).innerHTML = "<img class=\"ico\" src=\"/images/ico-loader.gif\" width=\"16\" height=\"16\" alt=\"Loading "+html_id+"\" />";
		var url = '/ajax/createmp3.php';
		var params = 'entry_id='+entry_id;
		var ajax = new Ajax.Updater(
			{ success: html_id }, url, {method: 'get', parameters: params, evalScripts:true, onFailure: listen_Error});
	}
	else
	{
		sendEvent('mediaplayer', 'playpause');
	}
}

function listen_Error(obj)
{
	$(active_entry).innerHTML = "<img class=\"ico\" src=\"/images/ico-error.gif\" width=\"16\" height=\"16\" alt=\"Error\" />";
	alert(obj.responseText);
}

function simplePlayPause(swf, imgid)
{
	sendEvent(swf, 'playpause');
	
	if($(imgid).src.indexOf('/images/ico-play.gif') > 0)
	{
		$(imgid).src = '/images/ico-pause.gif'
	}
	else
	{
		$(imgid).src = '/images/ico-play.gif'
	}
}
