var player =
{
	id:'player-id',
	width:301,
	height:5,
	init:function()
	{
		var volbar = common.el('player-volume');
		if(common.getCookie('player_vol') != '')
		{
		  var volbar_width = common.getCookie('player_vol');
		  volbar.style.backgroundPosition = '-' + ((30 * (100 - volbar_width) / 100)) + 'px 0';
		}
		else
		{
		  common.setCookie('player_vol', '60');
		  common.setCookie('player_mute', '0');
		  volbar.style.backgroundPosition = '-12px 0';
		}
		if(common.getCookie('player_mute') == '1')
		{
		  volbar.style.backgroundPosition = '-30px 0';
		}
		else
		{
		  common.setCookie('player_mute', '0');
		}
		if(common.getCookie('player_time_style') == '')
		{
		  common.setCookie('player_time_style', 'lower');
		}
	},
	writeFlash:function(path, duration, autoplay)
	{
		var html = '';
		if(isGecko) 
		{
			html += '<embed type="application/x-shockwave-flash" src="' + http_server + '_/tpl/fla/player.swf" width="' + this.width + '" height="' + this.height + '"';
			html += ' id="' + this.id + '" name="' + this.id + '" wmode="transparent" quality="high"';
			html += ' flashvars="debug=false&autostart=' + autoplay + '&volume=' + this.getVol() + '&host=' + host + '&id=' + path + '&duration=' + duration + '" menu="false" />';
		}
		else
		{
			html += '<object id="' + this.id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '">';
			html += '<param name="movie" value="' + http_server + '_/tpl/fla/player.swf">';
			html += '<param name="bgcolor" value="#FFFFFF" />';
			html += '<param name="quality" value="high" />';
			html += '<param name="menu" value="false" />';
			html += '</object>';
		}
		common.el('player-flash-id').innerHTML = html; 
	},
	play:function(obj, path, duration)
	{
 		if(common.el(this.id) != null)
 		{
 			this.setVariable('setVolume', this.getVol());
 			obj.className = obj.className.search(/_play/i) != -1 ? 'player_control_stop' : 'player_control_play'; 
  		this.setVariable('buttonPressed', 'true');
		}
		else
		{
			this.writeFlash(path, duration, 'false');
			obj.className = 'player_control_stop';
			var interval = 0;
			var cycle = function()
			{
				player.setVariable('setVolume', player.getVol());
				player.setVariable('buttonPressed', 'true');
				clearInterval(interval);
			};
			interval = setInterval(cycle, 200);
		}
	},
	stop:function()
	{
		this.setVariable('setState', 'stop');
	},
	setVariable:function(func, value)
	{
		var player = common.el(this.id);
		var counter = 0;
		var interval = 0;
		var cycle = function()
		{
			try 
			{
				if (isMSIE || player.SetVariable) 
				{
					player.SetVariable("audioPlayer_mc." + func, value);
					clearInterval(interval);
					return true;
				}
			}
			catch (e) 
			{
				alert(e);
			}
			if (counter++ > 3) 
			{
				clearInterval(interval);
			}
			return false;
		};
		if (!cycle()) 
		{
			interval = setInterval(cycle, 50);
		}
	},
	getVol:function()
	{
		if(common.getCookie('player_mute') == '1')
		{
		  return 0;
		}
		else
		{
		  return common.getCookie('player_vol') != '' ? common.getCookie('player_vol') : 60;
		}
	},
	mute:function()
	{
		var volbar = common.el('player-volume');
	  if(common.getCookie('player_mute') == '1')
		{
      volbar.style.backgroundPosition = '-' + ((30 * (100 - common.getCookie('player_vol')) / 100)) + 'px 0'; 
      common.setCookie('player_mute', '0');
		}
		else
		{
      var volbarw = common.getCookie('player_vol');
      common.setCookie('player_vol', volbarw);
      volbar.style.backgroundPosition = '-30px 0';
      common.setCookie('player_mute', '1');
		}
		this.setVariable('setVolume', this.getVol());
	},
	vol:function(event, obj)
	{
		var mouse = getMousePosition(event);
		var level = Math.round((mouse.x - common.getX(obj)) / 6) + 1;
		common.setCookie('player_vol', level * 20);
		common.el('player-volume').style.backgroundPosition = '-' + ((30 * (100 - common.getCookie('player_vol')) / 100)) + 'px 0';
		this.setVariable('setVolume', this.getVol());
	}
}
var track_duration = 0;
var track_length = 0;
var track_l = 0;
function returnValues(message)
{ 
	var spl = message.split(':');
	if(spl[0] == 'load_progress')
	{
  	var progress = parseInt(spl[1] / 1000);
  	progress = parseInt(progress / track_duration * 100);
  	var minus = parseInt(288 * (progress / 100));
  	var bar = common.el('player-loader-progess');
  	bar.width = 288 - minus;
  	bar.style.marginLeft = minus + 14 + 'px';
	}
	else if(spl[0] == 'position_changed')
	{
  	var progress = parseInt(spl[1] / 1000);
  	if(progress != track_length)
  	{
  		track_length = progress;
  		var minutes = Math.floor(progress / 60);
  		minutes = minutes.toString().length < 2 ? '0' + minutes : minutes;
  		var secundes = progress % 60;
  		secundes = secundes.toString().length < 2 ? '0' + secundes : secundes;
  		common.el('player-timer-id').innerHTML = minutes + ':' + secundes;
  	}
	}
	else if(spl[0] == 'track_end')
	{
  	//ps_player.next_prew('next');
	}
	else
	{
		//common.el('flash-debug-id').value += message + "\n";
	}
}
