$(function() {

	$("#add").click(function(){submit_upload_media()});
	$("#upload_form_div").click(function(){$("#upload_form").toggleClass("hidden")});
	
	function do_submit()
	{
		$("#upload_media").submit();
		
	}
   	
	
	$("#player_dialog").dialog({
	autoOpen:false,
	bgiframe: true,
	resizable: true,
	modal: true,
	width:340,
	height:370,
	overlay: {
		backgroundColor: '#000',
		opacity: 0.5
	}
//	to solve the error js
//	beforeclose:function(){
//		try{
//		stopPlayer();
//		}
//		catch(err)
//		{
//			
//		}
//	}

});//dialog

	
		$.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');
		$.fn.media.mapFormat('avi', 'winmedia');
		$.fn.media.mapFormat('asf', 'winmedia');
		$.fn.media.mapFormat('ra', 'Real Player');
		$.fn.media.mapFormat('ram', 'Real Player');
		$.fn.media.mapFormat('rm', 'Real Player');
		$.fn.media.mapFormat('flv', 'realplayer');
		
		
		
		   	 
		   	$(".play").click(function(){ 
		   		var link=$(this).attr("link");
				var title=$(this).attr("title");
				
				$("#player_dialog").html(link)


			   	 $("a.media").media(
		        {
		        autoplay:true,
		        height:240,
		        width:320,
		        attrs:
		        {
		        	name:"player",
		        	id:"player"
		        }
		        } 
		         );
		   	
				
				$("#player_dialog").dialog('option', 'title', title);
				$("#player_dialog").dialog('open');
		   	}) //click function
			
	
		   	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
				}
				
			}
					   	
});

	function submit_upload_media(){
		$("#upload_media").validate({
			rules:{
			name:{
					required:true
				}
		,
		
		email:{
			required:true,
			email:true
		}
,
				file_name:{
			required:true

				},
				media_file:{
					required:true,
					accept: "swf|mpg|mpeg|wav|asf|avi|wma|wmv|mp3|ram|rm|ra|flv"
						},
				media_image:{
					required:true,
					accept: "jpg|jpeg|png|gif"
						}
				
			},
			messages:{
				name: {
					required: "<div><font color='red'>"+REQUIRED_NAME+"</font></div>"
				}
			,
			email: {
				required: "<div><font color='red'>"+REQUIRED_EMAIL+"</font></div>",
				email: "<div><font color='red'>"+VALID_EMAIL+"</font></div>"
			}
		,
			file_name:
				{
				required:"<div><font color='red'>"+ENTER_FILE_NAME+"</font></div>"
					
				},
				media_file:
				{
				required:"<div><font color='red'>"+UPLOAD_FILE+"</font></div>",
				accept: "<div><font color='red'>"+UPLOAD_VALID_TYPE+"</font></div>"
					
				},
				media_image:
				{
				required:"<div><font color='red'>"+UPLOAD_IMAGE+"</font></div>",
				accept: "<div><font color='red'>"+UPLOAD_VALID_IMAGE+"</font></div>"
					
				}
			}		
		});
		
		
		
		
		if($("#upload_media").valid()){
			$("#upload_media").submit();
			
		}


	
	}	
	
	function openUploadSong()
	{
		window.open("../templates/songs_uploads.php",'', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=550,left = 300,top =100');
	}	
