$.extend({
	msgBox:function(str){var tempdialog = new Boxy("" , {modal:true , closeable:true , title:"操作提示"});	var tempDialogJQuery = tempdialog.boxy;$("div.boxy-content",tempDialogJQuery).html(str);$(".close",tempDialogJQuery).hide();tempdialog.tween(300 , 90 , function(val){$(".close",tempDialogJQuery).show();window.setTimeout(function(){tempdialog.hide();tempDialogJQuery.remove();},1500);},"json");}			
});

$.fn.extend({
	check: function() {
		return this.each(function() { this.checked = !this.checked; });
	},
	musiccheck: function(){
		return this.click(function(){
			$("input:checkbox[name='list[]']").check();
		});
	},
	playMusic:function(){
		var tid = this.attr("rel");
		return this.click(function(){window.open ("http://www.l99.com/EditTracks_miniTracks.action?trackMainIds=" + tid,"trackwindow","height=250,width=250,top=300,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");});
	},
	manyMusic:function(){
		return this.click(function(){var listNum = $("input:checkbox[name='list[]']:checked").length;if(listNum >= 1) {var list =  new Array();$("input[@name='list[]']:checked").each(function(){list.push($(this).val());	});window.open ("http://www.l99.com/EditTracks_miniTracks.action?trackMainIds=" + list.join("_"),"newwindow","height=250,width=250,top=300,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");	}});
	},
	allMusic:function(){
		return this.click(function(){var list =  new Array();$("input:checkbox[name='list[]']").each(function(){list.push($(this).val());});window.open ("http://www.l99.com/EditTracks_miniTracks.action?trackMainIds=" + list.join("_"),"newwindow","height=250,width=250,top=300,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");	});
	},
	delMusic:function(){
		return this.click(function(){
			var track_id = $(this).attr("rel");
			Boxy.ask("确认删除这条音乐记录吗? ",["确定","取消"],function(val){
					if (val == "取消") {
						$("table.boxy-wrapper").remove();
						return;
					}
					var tempdialog = new Boxy("" , {modal:true , closeable:true , title:"操作提示"});	
					var tempDialogJQuery = tempdialog.boxy;
					$("div.boxy-content",tempDialogJQuery).html("正在操作中....");	
					$(".close",tempDialogJQuery).hide();
					$.post("http://www.l99.com/EditTracks_deleteTrack.action",{trackMainId:track_id},function(data){
						if(data.status == "1"){
							$("ul#track_" + track_id).hide("slow");
							musicNum = musicNum - 1;
							$("span#music_all_num").text(musicNum);
						}
						tempdialog.tween(200 , 30 , function(val){
							$(".close",tempDialogJQuery).show();		
							$("div.boxy-content",tempDialogJQuery).html(data.msg);
							window.setTimeout(function(){tempdialog.hide();	tempDialogJQuery.remove();},1500);
						});
					},"json");	
				},{modal:true,closeable:true,draggable:false,width:500,height:700,title:"删除音乐提示"});
			});
	},
	addMusic:function(rex, trackPlugin){
		return this.click(function(){
			var musicUrl = $("input#track_url").val().replace(/(^\s*)|(\s*$)/g, "");
			if(musicUrl === "" || musicUrl == "http://"){return;}
			var uriInfo =  musicUrl;
			if(musicUrl.length > 35) {
				uriInfo = musicUrl.substring(0,14) + "..." + musicUrl.substring(musicUrl.length-20);
			}
			var track_from = [];
			track_from.push("<form class='fadd_track' action='http://www.l99.com/EditTracks_addTrack.action' method='post'>");
			if(!rex.test($("input#track_url").val())){
				track_from.push("<div class='mt5' style='height:20px; clear:both; text-align:center;'><label>&nbsp;</label>『<span class='text_orange'>音乐地址不符合规格</span>』</div>");									
			}
			track_from.push("<div class='mt5' style='height:20px; clear:both;'><span class='block left mr5' style='width:70px; height:20px; text-align:right; clear:both;'>歌曲链接：</span><span class='text_blue left'>" + uriInfo + "</span></div>");
			track_from.push("<div class='mt5' style='height:20px; clear:both;'><span class='block left mr5' style='width:70px; height:20px; text-align:right; clear:both;'>歌曲名称：</span><input style='width:170px;'name='trackMain.trackTitle' /><strong>『*必填』</strong></div>");			
			track_from.push("<div class='mt5' style='height:20px; clear:both;'><span class='block left mr5' style='width:70px; height:20px; text-align:right; clear:both;'>歌手名称：</span><input style='width:170px;'name='trackMain.trackArtist' /></div>");			
			track_from.push("<div class='mt5' style='height:20px; clear:both;'><span class='block left mr5' style='width:70px; height:20px; text-align:right; clear:both;'>专辑名称：</span><input style='width:170px;'name='trackMain.traclAlbum' /></div>");									
			track_from.push("<div class='mt5' style='height:20px; clear:both;'><span class='block left mr5' style='width:70px; height:20px; text-align:right; clear:both;'>歌曲排序：</span><input style='width:170px;'name='trackMain.trackIndex' value='1' /><span>&nbsp;由高向低排序</span></div>");												
			track_from.push("<div class='mt5' style='height:20px; clear:both;'><span class='block left mr5' style='width:70px; height:20px; text-align:right; clear:both;'>空间音乐：</span><input type='checkbox' name='trackMain.trackSpace' value='true' id='addTrackSpaceMark' /><strong>『置为空间背景音乐』</strong></div>");												
			track_from.push("<input name='trackMain.trackUrl' type='hidden'  value='" + musicUrl + "'/>");
			track_from.push("</form>");	
			Boxy.ask(track_from.join(""),["确定","取消"],function(val){
				if (val == "取消") {
					$("table.boxy-wrapper").remove();
					return;
				}
				var tempdialog = new Boxy("" , {modal:true , closeable:true , title:"操作提示"});	
				var tempDialogJQuery = tempdialog.boxy;
				$("div.boxy-content",tempDialogJQuery).html("正在操作中....");	
				$(".close",tempDialogJQuery).hide();
				$("form.fadd_track:only-child").submit();	
			},{modal:true,closeable:true,draggable:false,width:500,height:700,title:"添加音乐提示"});
		});
	},
	editMusic:function(n){
		return this.click(function(){
			var track_id = $(this).attr("rel");
			$.get("http://www.l99.com/EditTracks_trackInfo.action",{trackMainId:track_id,nowPage:n},function(data){
				if(data.status == "1"){
					var editBox = $(data.msg);
					editBox.find("div#music_edit_play").one("click",playMusic);
					Boxy.ask(editBox,["确定","取消"],function(val){
					if (val == "取消") {
						$("table.boxy-wrapper").remove();
						return;
					}
					var tempdialog = new Boxy("" , {modal:true , closeable:true , title:"操作提示"});	
					var tempDialogJQuery = tempdialog.boxy;
					$("div.boxy-content",tempDialogJQuery).html("正在操作中....");	
					$(".close",tempDialogJQuery).hide();
					$("form.fedit_track:only-child").submit();	
					},{modal:true,closeable:true,draggable:false,width:500,height:700,title:"编辑音乐提示"});
				}else{
					$.msgBox(data.msg);
				}
			},"json");
		});
	},
	connectionMusic:function(n){
		return this.click(function(){
			var track_id = $(this).attr("rel");
			var track_title = $(this).attr("rev");
			Boxy.ask("确认收藏歌曲『" + track_title + "』到我的音乐盒？",["确定","取消"],function(val){
					if (val == "取消") {
						$("table.boxy-wrapper").remove();
						return;
					}
					var tempdialog = new Boxy("" , {modal:true , closeable:true , title:"操作提示"});	
					var tempDialogJQuery = tempdialog.boxy;
					$("div.boxy-content",tempDialogJQuery).html("正在操作中....");	
					$(".close",tempDialogJQuery).hide();
					$.post("http://www.l99.com/EditTracks_collectionTrack.action",{trackMainId:track_id},function(data){
						tempdialog.tween(200 , 30 , function(val){
							$(".close",tempDialogJQuery).show();		
							$("div.boxy-content",tempDialogJQuery).html(data.msg);
							window.setTimeout(function(){tempdialog.hide();	tempDialogJQuery.remove();},1500);
						});
					},"json");	
				},{modal:true,closeable:true,draggable:false,width:500,height:700,title:"收藏音乐提示"});
			});
	}
});
