$(function(){

	$("#player_dialog").dialog({
		autoOpen:false,
		bgiframe: true,
		resizable: true,
		modal: true,
		width:340,
		height:370,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		beforeclose:function(){
			try{
			stopPlayer();
			}
			catch(err)
			{
				
			}
		}

	});
	$.fn.media.mapFormat('mp3', 'winmedia');
	$.fn.media.mapFormat('mpg', 'winmedia');
	$.fn.media.mapFormat('mpeg', 'winmedia');
	$.fn.media.mapFormat('mp4', 'winmedia');
	$.fn.media.mapFormat('wav', 'winmedia');

	$(".play").click(function(){

		var link=$(this).attr("link");
		var title=$(this).attr("dname");

		$("#player_dialog").html('<center><a class="media" href="'+link+'"></a></center>')
		$("a.media").media(
		{
			autoplay:true,
			height:300,
			width:300,
			attrs:
			{
				name:"player",
				id:"player"
			}
		}
		);
		$("#player_dialog").dialog('option', 'title', title);
		$("#player_dialog").dialog('open');
	});

	function stopPlayer()
	{
		var type=$("#player").attr("type");

		if(type=="application/x-oleobject" || type=="application/x-ms-wmp" || type=="application/x-mplayer2"  )//if the player is windows media player
		{
			document.getElementById("player").controls.stop();//worked for wmplayer FF & IE
		}
		else// if the player is real player
		{
			thissound= eval("document.player");
			thissound.DoStop();//worked for realplayer IE & FF
		}
	}
});
