var $ = function(item){return (document.getElementById(item));};
var MP3Player = {
	init : function() {
		return(this);
	},
	__playlist : new Array(),
	__FlashPlayer : new String(),
	__CurrentPlayingIndex : "",
	__SetFlashPlayer : function(FObject) {
		MP3Player.__FlashPlayer = FObject.Player.toString(); 
		return(MP3Player.__FlashPlayer);
	},
	__CreateButtons : function(ID) {
		var BTN_on  = ''	
				  	//+ '<div id="btn_on_'+ ID +'" style="height:20px;width:93px">'
				  	+ '<span style="display:none">&nbsp;[</span><a id="btn_on_'+ ID +'" rel="nofollow" href="javascript:void(0)" '
				  	+ 'onclick="javascript:MP3Player.__PlaySongByIndex({__MID: \''+ ID +'\'});" '		
				  	+ 'onkeypress="javascript:retun(true);">'
				  	+ '<img src="http://i55.tower.com/www/surf/img_v2/img_exp/flash/play_button.gif" alt="Play"'
				  	+ 'style="border:none" width="35" height="20"/><span style="display:none">Play Song</span></a>'
				  	//+ '<span style="display:none">]&nbsp;</span></div>';
					+ '<span style="display:none">]&nbsp;</span>';
					
		var BTN_off = ''	
				  	//+ '<div id="btn_off_' + ID + '" style="display:none;height:20px;width:93px">'		
					+ '<span style="display:none">&nbsp;[</span><a style="display:none" rel="nofollow" id="btn_off_' + ID + '" href="javascript:void(0)" onclick="javascript:MP3Player.__ExternalStopSelected()"'
					+ 'onkeypress="javascript:retun(true);"><img src="http://i55.tower.com/www/surf/img_v2/img_exp/flash/stop_button.gif"'	
					+ 'alt="Stop" style="border:none;padding-top:1px;padding-bottom:1px" width="63" height="18" />'
					//+ '<span style="display:none">Stop Song</span></a><span style="display:none">]&nbsp;</span></div>'
					+ '<span style="display:none">Stop Song</span></a><span style="display:none">]&nbsp;</span>'
		
		var BTNTMPL = BTN_on + BTN_off;
		document.write(BTNTMPL);
		return;
	},
	__GetFlashMovie : function(__MID) {
		try{
			   var isIE = navigator.appName.indexOf("Microsoft") != -1; 	
			   var agt=navigator.userAgent.toLowerCase();
			   var isOpera = (agt.indexOf("opera") != -1);
			   var isSafari = (agt.indexOf("safari") != -1);
			   if (!(isOpera) && !(isSafari))  return ((isIE) ? window[__MID] : document[__MID]);
			   else return (document.getElementById(__MID));
		} catch (e) {return;}	  
	},
	__PlaySongByIndex : function(Obj) {
		var __MID = Obj.__MID;
		if ((isNaN(__MID)) || (MP3Player.__FlashPlayer.toString() == "")) return (false);
		else {
			try{
				MP3Player.__GetFlashMovie(MP3Player.__FlashPlayer).SetVariable('__ChangeSongID', Number(__MID));
			} catch (e){return;}
			return;
		}
	},
	__AddToPlaylist : function(_obj) {
		if (_obj.url.toString() !== "") {
			_AddURL = _obj.url.toString().split("|").join("&");
			MP3Player.__playlist.push(_obj.url.toString());
		} else return;
	},
	__SetActiveItem : function(_id) {
		try{
			if (MP3Player.__CurrentPlayingIndex !== "") MP3Player.__StopActiveItems();	
			if ($("btn_on_" + String(Number(_id + 1)))) {
				MP3Player.__CurrentPlayingIndex = String(Number(_id + 1));
				//$("td_" + MP3Player.__CurrentPlayingIndex).className = 'sil_table';
				$("btn_on_" + MP3Player.__CurrentPlayingIndex).style.display = 'none';
				$("btn_off_" + MP3Player.__CurrentPlayingIndex).style.display = 'block';
			}
		} catch (e) { return;}
	},
	__StopActiveItems : function() {
		if ($("btn_on_" + MP3Player.__CurrentPlayingIndex)) {
			//$("td_" + MP3Player.__CurrentPlayingIndex).className = 'wh_table';	
			$("btn_off_" + MP3Player.__CurrentPlayingIndex).style.display = 'none';
			$("btn_on_" + MP3Player.__CurrentPlayingIndex).style.display = 'block';
		} else return;
	},
	__FadeOutput : function() {
		window.setTimeout(function(){
			new Effect.Highlight("mp3_player_object", {startcolor:'#FFFF99', endcolor:'#FFFFFF'});
		}, 400);	
	},
	__ExternalStopSelected : function() {
		try{
			MP3Player.__GetFlashMovie(MP3Player.__FlashPlayer.toString()).SetVariable('__StopCurrentSong', true);
			return;
		} catch (e) {
			return;	
		}
	},
	__SendPlaylistToFlash : function() {
		try {
			if (Boolean(MP3Player.__playlist.length)) {
				for (i=0; i<= (MP3Player.__playlist.length); i++) {		
					if ((MP3Player.__playlist[i]) && (MP3Player.__playlist[i].toString() !== "")) {
						MP3Player.__GetFlashMovie(MP3Player.__FlashPlayer.toString()).SetVariable('__AddSong', MP3Player.__playlist[i].toString());
					}	
					else continue;	
				} return;
			} else return;
		} catch (e) {
			return;
		}	
	},
	__LoadPlaylistData : function() {
		window.setTimeout(function(){
			MP3Player.__SetFlashPlayer({Player: 'MP3_player'});
			MP3Player.__SendPlaylistToFlash();
			window.status = "";
		}, 1000);	
		return;
	}
};


// Attach the event...
if (typeof window.addEventListener != 'undefined')
{
	window.addEventListener('load',
	function()
	{		
		try {
			if (document.getElementById('tracks_welcome_note')) document.getElementById('tracks_welcome_note').style.display='block';
			if (document.getElementById('main_mp3_player')) document.getElementById('main_mp3_player').style.display='block';	
			for (i=0;i <= 4; i++) {
				if (document.getElementById('listen_' + i)) document.getElementById('listen_' + i).style.display='block';
			}
		} catch (e) {return (true);}
		
	},false);
}
else if (typeof window.attachEvent != 'undefined')
{
	window.attachEvent('onload',function()
	{	
		try {
			if (document.getElementById('tracks_welcome_note')) document.getElementById('tracks_welcome_note').style.display='block';
			if (document.getElementById('main_mp3_player')) document.getElementById('main_mp3_player').style.display='block';	
			for (i=0;i <= 4; i++) {
				if (document.getElementById('listen_' + i)) document.getElementById('listen_' + i).style.display='block';
			}
		} catch (e) {return (true);}		
	});
}