///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2009-11-22]
//--------------------------------------------------------------------------
/*参数：[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
    title:	窗口标题
  content:  内容(可选内容为)
    width:	内容宽度
   height:	内容高度
	 drag:  是否可以拖动(ture为是,false为否)
     time:	自动关闭等待的时间，为空是则不自动关闭
   showbg:	[可选参数]设置是否显示遮罩层(0为不显示,1为显示)
  cssName:  [可选参数]附加class名称
   typena:  传进来的类型
 ------------------------------------------------------------------------*/
 //示例:
 //------------------------------------------------------------------------
 //simpleWindown("例子","text:例子","500","400","true","3000","0","exa")
 //------------------------------------------------------------------------
var showWindown = true;
var typename = '';
var templateSrc = "http://192.168.2.123:99/img"; //设置loading.gif路径
function tipsWindown(title,content,width,height,css_type,typena) {
	var drag='true',time='',showbg='true',cssName='text';
	if(typena == 'alert')
	{
		time = 3000;
		showbg = false;
		var content = '<div style="padding-top:50px;">' + content + '</div>';
	}
	typename = typena;
	$("#windown-box").remove(); //请除内容
	var width = width>= 950?this.width=950:this.width=width;	    //设置最大窗口宽度
	var height = height>= 527?this.height=527:this.height=height;   //设置最大窗口高度
	var DragHead = null;
	if(typename == "task")
	{
		if(showWindown == true) {
			var simpleWindown_html = new String;
				simpleWindown_html = "<div id=\"windownbg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index: 999901\"></div>";
				simpleWindown_html += "<div id=\"windown-box\">";
				simpleWindown_html += "<div id=\"windown-content\"></div>"; 
				simpleWindown_html += "</div>";
				$("body").append(simpleWindown_html);
				show = false;
			DragHead = document.getElementById("windown-content");
		}
	}
	else
	{
		if(showWindown == true) {
			var simpleWindown_html = new String;
				simpleWindown_html = "<div id=\"windownbg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;z-index: 999901\"></div>";
				simpleWindown_html += "<div id=\"windown-box\" class=\"win_gray "+css_type+"\">";
				simpleWindown_html += "<div id=\"windown-title\" class=\"win_title\"><h2></h2><a id=\"windown-close\" class=\"fr\"></a></div>";
				simpleWindown_html += "<div id=\"windown-content\"></div>"; 
				simpleWindown_html += "</div>";
				$("body").append(simpleWindown_html);
				show = false;
				$("#windown-box").css("background-color","#FFF");
			DragHead = document.getElementById("windown-title");
		}
	}
	
	$("#windown-content").html(content);
	
	$("#windown-title h2").html(title);
	if(showbg == "true") {$("#windownbg").show();}else {$("#windownbg").remove();};
	$("#windownbg").animate({opacity:"0.6"},"normal");//设置透明度
	$("#windown-box").show();
	if( height >= 527 ) {
		$("#windown-title").css({width:(parseInt(width) - 18)+"px"});
		$("#windown-content").css({width:(parseInt(width))+"px",height:"auto"});
	}else {
		$("#windown-title").css({width:(parseInt(width) - 18)+"px"});
		$("#windown-content").css({width:width+"px",height:"auto"});
	}
	var	cw = document.documentElement.clientWidth,ch = document.documentElement.clientHeight,est = document.documentElement.scrollTop; 
	var _version = $.browser.version;
	if ( _version == 6.0 ) {
		$("#windownbg").html("<iframe style=\"height:"+$(document).height()+"px;width:"+$(document).width()+"px;filter:alpha(opacity=0);opacity:0;\"></iframe>");
		$("#windown-box").css({left:"50%",top:(parseInt((ch)/2)+est)+"px",marginTop: -(parseInt(height)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	}else {
		$("#windown-box").css({left:"50%",top:"45%",marginTop:-(parseInt(height)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	};
	var Drag_ID = document.getElementById("windown-box");
	
		
	var moveX = 0,moveY = 0,moveTop,moveLeft = 0,moveable = false;
		if ( _version == 6.0 ) {
			moveTop = est;
		}else {
			moveTop = 0;
		}
	var	sw = Drag_ID.scrollWidth,sh = Drag_ID.scrollHeight;
		DragHead.onmouseover = function(e) {
			if(drag == "true"){DragHead.style.cursor = "move";}else{DragHead.style.cursor = "default";}
		};
		DragHead.onmousedown = function(e) {
		if(drag == "true"){moveable = true;}else{moveable = false;}
		e = window.event?window.event:e;
		var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop-moveTop;
		moveX = e.clientX-ol;
		moveY = e.clientY-ot;
		document.onmousemove = function(e) {
				if (moveable) {
				e = window.event?window.event:e;
				var x = e.clientX - moveX;
				var y = e.clientY - moveY;
					if ( x > 0 &&( x + sw < cw) && y > 0 && (y + sh < ch) ) {
						Drag_ID.style.left = x + "px";
						Drag_ID.style.top = parseInt(y+moveTop) + "px";
						Drag_ID.style.margin = "auto";
						}
					}
				}
		document.onmouseup = function () {moveable = false;};
		Drag_ID.onselectstart = function(e){return false;}
	}
	$("#windown-content").attr("class","windown-"+cssName);
	var closeWindown = function() {
		$("#windownbg").remove();
		$("#windown-box").fadeOut("slow",function(){$(this).remove();});
	}
	$("#windown-close").click(function() {
		
		var idclass = GetCookie("idclass");
		if ( idclass && idclass.length > 0 )
		{
			DelCookie('idclass');
		}
		if( typename== "cover")    //如果是封面修改 则不移除
		{
			$("#windownbg").hide();
			$("#windown-box").fadeOut("slow");
		}
		else
		{
			$("#windownbg").remove();
			$("#windown-box").fadeOut("slow",function(){$(this).remove();});
		}
		if(typename == 'tzsucc' &&  GetID('musicDetailPage'))
		{
			$.ajax({
				type:"POST",
				url:"/music/0",
				data:"tzsucc=ture&smallpage=smallpage",
				success:function(msg){
					var arr = msg.split('|');
					$('#tzListUsers').html('<li id="ztuser' + arr[0] + '" class="border"><a href="/user/' + arr[0] + '"><img src="' + arr[2] + '" /><span class="all_usname">' + arr[1] + '</span></a></li>');
					scrollToBottom('#tzUsersShow');
					var isShow = true;
					var time = 0;    //次数
					var init = setInterval(function()
					{
						if(time < 8)
						{
							if(isShow)
							{
								$('#ztuser'+arr[0]).addClass('border');
								isShow = false;
							}
							else
							{
								$('#ztuser'+arr[0]).removeClass('border');isShow = true;
							}
							time++;
						}
						else
						{
							$('#ztuser'+arr[0]).addClass('border');
							window.clearInterval(init);
						}
						
					},200);
				}
			});
		}
		else if(typename == 'downsucc' &&  GetID('musicDetailPage'))
		{
			$.ajax({
				type:"POST",
				url:"/music/0",
				data:"downsucc=ture&smallpage=smallpage",
				success:function(msg){
					var arr = msg.split('|');
					if($("#noBuyerNum").length > 0)  //如果光荣榜里面没有用户 而是提示信息 则先隐藏信息
					{
						$("#noBuyerNum").hide();
					}
					if($("#douser"+arr[0]).length == 0)
					{
						$('#downListUsers').prepend('<li id="douser' + arr[0] + '" class="border"><a href="/user/' + arr[0] + '"><img src="' + arr[2] + '" /><span class="all_usname">' + arr[1] + '</span></a></li>');
					}
					scrollToBottom('#downListUsers');
					var isShow = true;
					var time = 0;    //次数
					var init = setInterval(function()
					{
						if(time < 8)
						{
							if(isShow)
							{
								$('#douser'+arr[0]).addClass('border');
								isShow = false;
							}
							else
							{
								$('#douser'+arr[0]).removeClass('border');isShow = true;
							}
							time++;
						}
						else
						{
							$('#douser'+arr[0]).addClass('border');
							window.clearInterval(init);
						}
						
					},200);
				}
			});
		}
	});
	if( time != "" && typeof(time) != "undefined") {
	
		setTimeout(closeWindown,time);
	}
}

/**
*	关闭弹出窗口
*/
function closeTipWindow()
{
	var idclass = GetCookie("idclass");
	if ( idclass && idclass.length > 0 )
	{
		DelCookie('idclass');
	}
	$("#windownbg").remove();
	$("#windown-box").fadeOut("slow",function(){$(this).remove();});
	if(typename == 'tzsucc'  &&  GetID('musicDetailPage'))
	{
		$.ajax({
			type:"POST",
			url:"/music/0",
			data:"tzsucc=ture&smallpage=smallpage",
			success:function(msg){
				var arr = msg.split('|');
				$('#tzListUsers').html('<li id="ztuser' + arr[0] + '" class="border"><a href="/user/' + arr[0] + '"><img src="' + arr[2] + '" /><span class="all_usname">' + arr[1] + '</span></a></li>');
				scrollToBottom('#tzUsersShow');
				var isShow = true;
				var time = 0;    //次数
				var init = setInterval(function()
				{
					if(time < 8)
					{
						if(isShow)
						{
							$('#ztuser'+arr[0]).addClass('border');
							isShow = false;
						}
						else
						{
							$('#ztuser'+arr[0]).removeClass('border');isShow = true;
						}
						time++;
					}
					else
					{
						$('#ztuser'+arr[0]).addClass('border');
						window.clearInterval(init);
					}
					
				},200);
			}
		});
	}
	else if(typename == 'downsucc'  &&  GetID('musicDetailPage'))
	{
		$.ajax({
			type:"POST",
			url:"/music/0",
			data:"downsucc=ture&smallpage=smallpage",
			success:function(msg){
				var arr = msg.split('|');
				if($("#noBuyerNum").length > 0)  //如果光荣榜里面没有用户 而是提示信息 则先隐藏信息
				{
					$("#noBuyerNum").hide();
				}
				if($("#douser"+arr[0]).length == 0)
				{
					$('#downListUsers').prepend('<li id="douser' + arr[0] + '" class="border"><a href="/user/' + arr[0] + '"><img src="' + arr[2] + '" /><span class="all_usname">' + arr[1] + '</span></a></li>');
				}
				//var isShow = true;
				//setInterval(function(){if(isShow){$('#douser'+arr[0]).addClass('border');isShow = false;}else{$('#douser'+arr[0]).removeClass('border');isShow = true;}},200);
				scrollToBottom('#downListUsers');
				var isShow = true;
				var time = 0;    //次数
				var init = setInterval(function()
				{
					if(time < 8)
					{
						if(isShow)
						{
							$('#douser'+arr[0]).addClass('border');
							isShow = false;
						}
						else
						{
							$('#douser'+arr[0]).removeClass('border');isShow = true;
						}
						time++;
					}
					else
					{
						$('#douser'+arr[0]).addClass('border');
						clearInterval(init);
					}
					
				},200);
			}
		});
	}
}



