﻿jQuery.fn.reflect = function (config) {
	$this = $(this);
	var $i = $this.parent().prev().children("img");
	var iw = $i.attr("offsetWidth");
	var ih = $i.attr("offsetHeight");

	var is = $i.attr("src");
	var h = "";

	try {
		if(!window.ActiveXObject) {
			$c = $this.children("img").css("display", "none").next().css("margin", "0 auto");
			$c.attr("width", iw);
			$c.attr("height", config.height);
			c = $c.get(0);
			if (c.getContext) {
				var test = c.getContext("2d");
				test.save();
				test.translate(0, ih-1);
				test.scale(1, -1);
				test.drawImage($i.get(0), 0, 0, iw, ih);
				test.restore();
				test.globalCompositeOperation = "destination-out";
				var gradient = test.createLinearGradient(0, 0, 0, config.height);
				gradient.addColorStop(1, "rgba(255, 255, 255, 1.0)");
				gradient.addColorStop(0, "rgba(255, 255, 255, 0.3)");
				test.fillStyle = gradient;
				test.fillRect(0, 0, iw, config.height);
			}
			$c.slideDown("slow", st);
		}
		else {
			var ieOpacity = config.height * config.opacity * 100 / config.height;
			$r = $this.children("canvas").css("display", "none").prev();
			$r.attr("src", is).css({"width":iw+"px", "height":ih+"px", "margin":"0 auto", "filter":"flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+ieOpacity+",style=1,finishOpacity=0,startx=0,starty=0,finishx=0,finishy="+(config.height-5)+")"}).slideDown(200, st);
		}
	}
	catch(e) {
		ih = ih || parseInt($i.parent().attr("offsetHeight"));
		for(var i=0; i<config.height; i++) {
            var opacity = (config.height - i) * config.opacity / config.height;
			var ieOpacity = config.height * config.opacity * 100 / config.height;
            var mt = ih - i - 1;
            h += "<div style='opacity:" + opacity + ";margin:0 auto;display:block;filter:flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+ieOpacity+",style=1,finishOpacity=0,startx=0,starty=0,finishx=0,finishy="+config.height+");overflow:hidden;margin:0 auto;width:"+(iw||170)+"px;height:1px'><img style='display:block;margin:-" + mt + "px auto 0' src='" + is + "' /></div>";
        }
		$this.attr("innerHTML", h);
		st();
	}
	$i.attr("width", iw);
	$i.attr("height", ih);
	
	$o = $this.parent();
	$h = $o.prev();
	$w = $o.parent();
	$e = $o.find(".sqlalieeS").parent();
	$ti = $o.children(".sqlapliTA");
	$w.hover(
		function() {
			$(this).find(".sqlapldD").addClass("sqlapliIH").end().children(".sqlapliI").addClass("sqlapliIH").next().find(".sqlalieE").slideDown("fast");
		}, 
		function() {
			$(this).find(".sqlapldD").removeClass("sqlapliIH").end().children(".sqlapliI").removeClass("sqlapliIH").next().find(".sqlalieE").slideUp("fast");
		}
	);
	$e.click(se).next().click(
		function() {
			var $t = $(this).parents(".sqlaplI");
			var pn = $t.attr("n");
			var pi = $t.attr("i");
			var $pImg = $t.find(".reflect");
			var pSrc = $pImg.attr("src");
			var pAlt = $pImg.attr("alt");
			sqlMasker.config.shower.contentType = "delPhoto";
			sqlMasker.config.shower.width = 400;
			sqlMasker.config.shower.title = "提示";
			sqlMasker.config.shower.xhr.type = "post";
			sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/DeleteImage";
			sqlMasker.config.shower.xhr.value = ["imageId=", pi];
			sqlMasker.operation.ajax.preDeal = function() {
				$(".sqlPopupOperation").css("display", "none");
			};
			sqlMasker.operation.ajax.callback = function(json) {
				if(json.Result<=0) {
					$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>删除</span>失败了……</b>");
					window.setTimeout(sqlMasker.close, 2000);
				}
				else {
					window.location.reload();
				}
			};
			sqlMasker.CustomDom.delPhoto = '<div class="sqlaplI" i="'+pi+'" n="'+pn+'">'+
					'<a href="#this" title="'+pn+'" class="sqlapliI">'+
						'<img class="reflect sqlNotToLarge" src="'+pSrc+'" alt="'+pAlt+'" title="'+pAlt+'" />'+
					'</a>'+
				'</div>'+
				'<div class="sqlMaskerContent" style="line-height:18px;margin-top:10px;overflow:hidden;width:'+ (sqlMasker.config.shower.width-20) +'px">'+
					'此操作不可恢复，你确定要删除吗？'+
				'</div>'+
				'<div class="sqlPopupOperation" style="margin-top:25px">'+
					'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
					'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
				'</div>';
			sqlMasker.init("Basic", "innerHTML");
			//init("Basic", "appendChild");	
		}
	);
	$ti.children("div").hover(
		function(){
			$(this).css({"background-color":"#fffdea", "border":"1px solid #666", "padding":"0"});
		}, 
		function(){
			$(this).css({"background-color":"transparent", "border":"0", "padding":"1px"});
		}
	).end().click(se);
	
	if($(".sqlaPL").length > 0){
		$(document).click(function(ev){
			ev = ev || window.event;
			var target = ev.target || ev.srcElement;
			if(target.parentNode.className != "sqlalieE" && target.className.indexOf("cnViBtnSilver") < 0 && target.className.indexOf("cnViBtnBlueJ") < 0 && (!target.getAttribute("i") || sqlPO.c.find(".sqlapliTA div").attr("i") != target.getAttribute("i")) && !target.getAttribute("maxlength") && !!sqlPO.c && sqlPO.c.length > 0){
				sqlPO.c.find(".sqlapliTA").children("span").css("display", "none").prev().fadeIn("fast", function(){
					$(this).parents(".sqlapldW").removeClass("sqlTag");
				});
			};
		});
	}
	
	function se(ev){
		ev = ev || window.event;
		var target = ev.target || ev.srcElement;
		var $t = $(target).parents(".sqlapldW");
		if(!$t.hasClass("sqlTag")) {
			if(sqlPO.c) {
				try {
					sqlPO.c.removeClass("sqlTag");
					$z = sqlPO.c.children(".sqlapliTA").children("span").css("display", "none");
					$z.fadeOut("fast").prev().slideDown("fast");
					$z.prev().css({"background-color":"transparent", "border":"0", "padding":"1px"});
				}
				catch(e){};
			}
			
			$t.addClass("sqlTag").children(".sqlapliTA").children("div").css("display", "none").next().fadeIn("fast", function(){
				var $temp = $t.find(".sqlapliTA");
				$temp.find("span input").attr("value", $temp.find("div").attr("n")).focus();
			}).children("a").click(function(){
				var $st = $(this);
				var $sv = $st.prev();
				var $sp = $st.parent();
				var $spv = $sp.prev();
				var si = $spv.attr("i");
				var sn = $spv.attr("n");
				var sv = $sv.attr("value");
				
				if(sn!=sv && $.trim(sv)!="") {
					var url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/UpdateImageCaption";
					var req = {"webservices": url,"contentType":"application/x-www-form-urlencoded","values":["imageId=",si,"&imageCaption=",encodeURIComponent(sv)].join("")};
					CNMS.loadAjax(req, callback);
				}
				else {
					$sp.css("display", "none");
					$spv.fadeIn("fast", function(){$t.removeClass("sqlTag");});
				}
				
				function callback(aoJson) {
					if(aoJson.Result>0) {
						$spv.attr("n", sv).attr("innerHTML", sqlPO.ll(sv));
					}
					$sp.css("display", "none");
					$spv.fadeIn("fast", function(){$t.removeClass("sqlTag");});
				}
			});
			sqlPO.c = $t;
		}
	}
	
	function st() {
		$(this).parent().next().children("div").css("display", "none").attr("innerHTML", function(){return sqlPO.ll($(this).attr("n"));}).fadeIn("fast");
	}
};

var sqlSubnav5 = {
	init : function() {
		var $s = $(".sqlaB");
		if($s.length > 0 ) {
			$s.children("a[title='删除相册']").click(function(){
				sqlSubnav5.delAlbum($s);
			});
			$s.children("a[title='删除照片']").click(function(){
				sqlSubnav5.delPhoto($s);
			});
			$s.children("a[title='相册属性']").click(function(){
				sqlSubnav5.modAlbumAttr($s);
			});
			$s.children("a[title='创建相册']").click(function(){
				sqlSubnav5.creatAlbum();
			});
			$s.children("a[title='移动照片']").click(function(){
				sqlSubnav5.movePhoto($s);
			});
		}
	},
	creatAlbum : function() {
		sqlMasker.config.shower.contentType = "creatAlbum";
		sqlMasker.config.shower.width = 400;
		sqlMasker.config.shower.title = "创建相册";
		sqlMasker.config.shower.xhr.type = "post";
		sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/CreateAlbum";
		
		sqlMasker.operation.ajax.preDeal = function() {
			$(".sqlPopupOperation").css("display", "none");
			var sqlAlbumGrant = "";
			$("input[name='sqlAlbumRadio']").each(function() {
				var $this = $(this);
				if($this.attr("checked") == true) {
					sqlAlbumGrant = $this.attr("value");
				}
			});
			sqlMasker.config.shower.xhr.value = ["albumTitle=", encodeURIComponent($("input[name='sqlAlbumNameMod']").attr("value")), "&privacy=", sqlAlbumGrant, "&password=", $("input[name='sqlPasswordMod']").attr("value")];
		};
		sqlMasker.operation.ajax.callback = function(json) {
			if(json.Result<=0) {
				$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>创建</span>失败了……</b>");
				window.setTimeout(sqlMasker.close, 2000);
			}
			else {
				window.location.reload();
				sqlMasker.close();
			}
		};
		sqlMasker.CustomDom.creatAlbum = '<div class="sqlModAlbumAttrName">'+
				'<b>相册名称:</b><br /><br />'+
				'<input id="sqlAlbumNameMod" maxlength="40" name="sqlAlbumNameMod" type="text" value="" />'+
			'</div>'+
			'<ul class="sqlModAlbumGrant clearfix">'+
				'<li style="float:left;width:150px;font-size:12px"><b>可以查看照片的用户：</b></li>'+
				'<li style="float:left" class="sqlModAlbumGrantLi2 clearfix">'+
					'<div class="clearfix">'+
						'<input id="sqlAlbumRadio0" style="display:block;*margin-top:-4px" name="sqlAlbumRadio" checked="true" value="0" type="radio" />'+
						'<label for="sqlAlbumRadio0">所有人</label>'+
						'<input id="sqlAlbumRadio1" style="display:block;*margin-top:-4px" name="sqlAlbumRadio" value="1" type="radio" />'+
						'<label for="sqlAlbumRadio1">好友</label>'+
						'<input id="sqlAlbumRadio2" style="display:block;*margin-top:-4px" name="sqlAlbumRadio" value="2" type="radio" />'+
						'<label for="sqlAlbumRadio2">仅自己</label>'+
					'</div>'+
					'<div class="clearfix" style="margin-top:15px;height:22px;line-height:22px">'+
						'<input id="sqlAlbumRadio3" name="sqlAlbumRadio" value="3" style="display:block;margin-top:5px;*margin-top:0" type="radio" />'+
						'<label for="sqlAlbumRadio3">密码访问</label>'+
						'<input id="sqlPasswordMod" maxlength="8" name="sqlPasswordMod" type="text" style="display:none;width:100px;" />'+
					'</div>'+
					'<div class="sqlPopupOperation" style="margin-top:25px">'+
						'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
						'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
					'</div>'+
				'</li>'+
			'</ul>';
		sqlMasker.init("Basic", "innerHTML");
		$("input[name='sqlPasswordMod']").keyup(function(e){var e=e||event;var c=e.which||e.keyCode;if(c==32){var p=e.srcElement||e.target;p.value=p.value.replace(/ /g, "");}});
		$(".sqlModAlbumGrantLi2").find("input[name='sqlAlbumRadio']").click(function() {
			if($(this).attr("value") == "3") {
				$("input[name='sqlPasswordMod']").css("display", "block");
			}
			else {
				$("input[name='sqlPasswordMod']").css("display", "none");
			}
		});
	},
	movePhoto : function() {
		sqlMasker.config.shower.contentType = "movePhoto";
		sqlMasker.config.shower.width = 400;
		sqlMasker.config.shower.title = "移动照片";
		sqlMasker.config.shower.xhr.type = "post";
		
		sqlMasker.operation.ajax.preDeal = function() {
			var sqlAlbumGrant = "";
			$("input[name='sqlAlbumRadio']").each(function() {
				var $this = $(this);
				if($this.attr("checked") == true) {
					sqlAlbumGrant = $this.attr("value");
				}
			});
			if(sqlSubnav5.moveTag) {
				var select = $(".sqlMovePhoto").children("select")[0];
				sqlSubnav5.destinationAlbumId = sqlSubnav5.destinationAlbumId || select.options[select.options.selectedIndex].value;
				if(sqlSubnav5.destinationAlbumId == "-1") {
					return false;
				}
				sqlMasker.config.shower.xhr.value = ["imageId=", _imageId, "&destinationAlbumId=", sqlSubnav5.destinationAlbumId];	
				sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/MoveImageToNewAlbum";
			}
			else {
				sqlMasker.config.shower.xhr.value = ["albumTitle=", encodeURIComponent($("input[name='sqlAlbumNameMod']").attr("value")), "&privacy=", sqlAlbumGrant, "&password=", $("input[name='sqlPasswordMod']").attr("value")];
				sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/CreateAlbum";
				$(".sqlPopupOperation").css("display", "none");
			}
		};
		sqlMasker.operation.ajax.callback = function(json) {
			if(sqlSubnav5.moveTag) {
				if(json.Result<=0) {
					$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>移动照片</span>失败了……</b>");
					sqlSubnav5.moveTag = false;
					window.setTimeout(sqlMasker.close, 2000);
				}
				else {
					window.location.reload();
					sqlMasker.close();
				}
			}
			else {
				if(json.Result<=0) {
					$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>移动照片</span>失败了……</b>");
					window.setTimeout(sqlMasker.close, 2000);
				}
				else {
					sqlSubnav5.moveTag = true;
					sqlSubnav5.destinationAlbumId = json.Result;
					sqlMasker.operation.ajax.xhr();
				}
			}
		};
		sqlMasker.CustomDom.movePhoto = '<div class="sqlMovePhoto" style="text-align:left"><select style="width:200px"></select></div>'+
			'<div style="margin-top:15px;color:#666;margin-bottom:15px;font-weight:bold;text-align:left">或新创建一个相册</div>'+
			'<div class="sqlModAlbumAttrName">'+
				'<b>相册名称:</b><br /><br />'+
				'<input id="sqlAlbumNameMod" maxlength="40" style="border:1px solid #999" name="sqlAlbumNameMod" type="text" value="" />'+
			'</div>'+
			'<ul class="sqlModAlbumGrant clearfix">'+
				'<li style="float:left;width:150px;font-size:12px"><b>可以查看照片的用户：</b></li>'+
				'<li style="float:left" class="sqlModAlbumGrantLi2 clearfix">'+
					'<div class="clearfix">'+
						'<input id="sqlAlbumRadio0" name="sqlAlbumRadio" style="display:block;*margin-top:-4px" checked="true" value="0" type="radio" />'+
						'<label for="sqlAlbumRadio0">所有人</label>'+
						'<input id="sqlAlbumRadio1" name="sqlAlbumRadio" style="display:block;*margin-top:-4px" value="1" type="radio" />'+
						'<label for="sqlAlbumRadio1">好友</label>'+
						'<input id="sqlAlbumRadio2" name="sqlAlbumRadio" style="display:block;*margin-top:-4px" value="2" type="radio" />'+
						'<label for="sqlAlbumRadio2">仅自己</label>'+
					'</div>'+
					'<div class="clearfix" style="margin-top:15px;height:22px;line-height:22px">'+
						'<input id="sqlAlbumRadio3" name="sqlAlbumRadio" value="3" style="display:block;margin-top:5px;*margin-top:0" type="radio" />'+
						'<label for="sqlAlbumRadio3">密码访问</label>'+
						'<input id="sqlPasswordMod" maxlength="8" name="sqlPasswordMod" type="text" style="display:none;width:100px;" />'+
					'</div>'+
					'<div class="sqlPopupOperation" style="margin-top:25px">'+
						'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
						'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
					'</div>'+
				'</li>'+
			'</ul>';
		sqlMasker.init("Basic", "innerHTML");
		$("input[name='sqlPasswordMod']").keyup(function(e){var e=e||event;var c=e.which||e.keyCode;if(c==32){var p=e.srcElement||e.target;p.value=p.value.replace(/ /g, "");}});
		$(".sqlModAlbumGrantLi2").find("input[name='sqlAlbumRadio']").click(function() {
			if($(this).attr("value") == "3") {
				$("input[name='sqlPasswordMod']").css("display", "block");
			}
			else {
				$("input[name='sqlPasswordMod']").css("display", "none");
			}
		});
		CNMS.loadJsonP("http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/GetCurrentUserAlbums?callback=sqlSubnav5.getCallback&r="+(new Date()).toString().split(" ").join(""));
	},
	getCallback : function(json) {
		var s = "<option value='-1'>选择相册</option>";
		for(var i=0; i<json.length; i++) {
			s += "<option value='"+json[i].Key+"'>"+json[i].Value+"</option>";
		}
		var select = $(".sqlMovePhoto").children("select");
		var input = $("input[name='sqlAlbumNameMod']");
		select.each(function(){
			var $t = $(this);
			$t.append(s);
		}).bind("change", function(){
			if(this.options.selectedIndex != 0) {
				input.attr("readonly", true).attr("value", "").css({"background":"#ddd"});
				sqlSubnav5.moveTag = true;
			}
			else {
				input.attr("readonly", false).css({"background":""});
			}
		});
		input.keyup(function() {
			if($.trim(this.value)!="") {
				select.attr("disabled", true);
				sqlSubnav5.moveTag = false;
			}
			else {
				select.attr("disabled", false);
			}
		});
	},
	moveTag : true,
	destinationAlbumId : null,
	modAlbumAttr  : function(obj) {
		var $t = $(obj);
		var ap = $t.attr("ap");
		var ag = $t.attr("ag");
		var an = $t.attr("an");
		var ai = $t.attr("ai");

		sqlMasker.config.shower.contentType = "modAlbumAttr";
		sqlMasker.config.shower.width = 400;
		sqlMasker.config.shower.title = "相册属性";
		sqlMasker.config.shower.xhr.type = "post";
		sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/UpdateAlbum";
		
		sqlMasker.operation.ajax.preDeal = function() {
			var sqlAlbumGrant = "";
			$("input[name='sqlAlbumRadio']").each(function() {
				var $this = $(this);
				if($this.attr("checked") == true) {
					sqlAlbumGrant = $this.attr("value");
				}
			});
			sqlMasker.config.shower.xhr.value = ["albumId=", ai, "&albumTitle=", encodeURIComponent($("input[name='sqlAlbumNameMod']").attr("value")), "&privacy=", sqlAlbumGrant, "&password=", $("input[name='sqlPasswordMod']").attr("value")];
			$(".sqlPopupOperation").css("display", "none");
		};
		sqlMasker.operation.ajax.callback = function(json) {
			if(json.Result<=0) {
				$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>更新</span>失败了……</b>");
				window.setTimeout(sqlMasker.close, 2000);
			}
			else {
				sqlMasker.close();
			}
		};
		sqlMasker.CustomDom.modAlbumAttr = '<div class="sqlModAlbumAttrName">'+
				'<b>相册名称:</b><br /><br />'+
				'<input id="sqlAlbumNameMod" maxlength="40" name="sqlAlbumNameMod" type="text" value="'+an+'" />'+
			'</div>'+
			'<ul class="sqlModAlbumGrant clearfix">'+
				'<li style="float:left;width:150px;font-size:12px"><b>可以查看照片的用户：</b></li>'+
				'<li style="float:left" class="sqlModAlbumGrantLi2 clearfix">'+
					'<div class="clearfix">'+
						'<input id="sqlAlbumRadio0" style="display:block;*margin-top:-4px" name="sqlAlbumRadio" checked="true" value="0" type="radio" />'+
						'<label for="sqlAlbumRadio0">所有人</label>'+
						'<input id="sqlAlbumRadio1" style="display:block;*margin-top:-4px" name="sqlAlbumRadio" value="1" type="radio" />'+
						'<label for="sqlAlbumRadio1">好友</label>'+
						'<input id="sqlAlbumRadio2" style="display:block;*margin-top:-4px" name="sqlAlbumRadio" value="2" type="radio" />'+
						'<label for="sqlAlbumRadio2">仅自己</label>'+
					'</div>'+
					'<div class="clearfix" style="margin-top:15px;height:22px;line-height:22px">'+
						'<input id="sqlAlbumRadio3" name="sqlAlbumRadio" value="3" style="display:block;margin-top:5px;*margin-top:0" type="radio" />'+
						'<label for="sqlAlbumRadio3">密码访问</label>'+
						'<input id="sqlPasswordMod" maxlength="8" name="sqlPasswordMod" type="text" style="display:none;width:100px;" />'+
					'</div>'+
					'<div class="sqlPopupOperation" style="margin-top:25px">'+
						'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
						'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
					'</div>'+
				'</li>'+
			'</ul>';
		sqlMasker.init("Basic", "innerHTML");
		$(".sqlModAlbumGrantLi2").find("input[name='sqlAlbumRadio']").each(function(){
				var $this = $(this);
				if($this.attr("value") == ag) {
					$this.attr("checked", true);
					if(ag == "3") {
						$("input[name='sqlPasswordMod']").attr("value", ap).css("display", "block").bind("keyup",function(e){var e=e||event;var c=e.which||e.keyCode;if(c==32){var p=e.srcElement||e.target;p.value=p.value.replace(/ /g, "");}});
					}
				}
				
			}
		).click(function() {
			if($(this).attr("value") == "3") {
				$("input[name='sqlPasswordMod']").css("display", "block");
			}
			else {
				$("input[name='sqlPasswordMod']").css("display", "none");
			}
		});
	},
	delPhoto : function(obj) {
		var $t = $(obj);
		var pn = $t.attr("pn");
		var pi = $t.attr("pi");
		var pSrc = $t.attr("psrc");
		var pAlt = pn;
		sqlMasker.config.shower.contentType = "delPhoto";
		sqlMasker.config.shower.width = 400;
		sqlMasker.config.shower.title = "提示";
		sqlMasker.config.shower.xhr.type = "post";
		sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/DeleteImage";
		sqlMasker.config.shower.xhr.value = ["imageId=", pi];
		sqlMasker.operation.ajax.preDeal = function() {
			$(".sqlPopupOperation").css("display", "none");
		};
		sqlMasker.operation.ajax.callback = function(json) {
			if(json.Result<=0) {
				$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>删除</span>失败了……</b>");
				window.setTimeout(sqlMasker.close, 2000);
			}
			else {
				var url = $t.attr("purl");
				if(url == "") {
					window.location.reload();
				}
				else {
					window.location.href = url;
				}
			}
		};
		sqlMasker.CustomDom.delPhoto = '<div class="sqlaplI" i="'+pi+'" n="'+pn+'">'+
				'<a href="#this" title="'+pn+'" class="sqlapliI">'+
					'<img class="reflect sqlNotToLarge" src="'+pSrc+'" alt="'+pAlt+'" title="'+pAlt+'" />'+
				'</a>'+
			'</div>'+
			'<div class="sqlMaskerContent" style="line-height:18px;margin-top:10px;overflow:hidden;width:'+ (sqlMasker.config.shower.width-20) +'px">'+
				'此操作不可恢复，你确定要删除吗？'+
			'</div>'+
			'<div class="sqlPopupOperation" style="margin-top:25px">'+
				'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
				'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
			'</div>';
		sqlMasker.init("Basic", "innerHTML");
			//init("Basic", "appendChild");	
	},
	delAlbum : function(obj) {
		var $t = $(obj);
		var ap = $t.attr("ap");
		var ag = $t.attr("ag");
		var an = $t.attr("an");
		var ai = $t.attr("ai");
		var aSrc = $t.attr("asrc");
		var aAlt = an;
		sqlMasker.config.shower.contentType = "delAlbum";
		sqlMasker.config.shower.width = 400;
		sqlMasker.config.shower.title = "提示";
		sqlMasker.config.shower.xhr.type = "post";
		sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/DeleteAlbum";
		sqlMasker.config.shower.xhr.value = ["albumId=", ai];
		sqlMasker.operation.ajax.preDeal = function() {
			$(".sqlPopupOperation").css("display", "none");
		};
		sqlMasker.operation.ajax.callback = function(json) {
			if(json.Result<=0) {
				$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>删除</span>失败了……</b>");
				window.setTimeout(sqlMasker.close, 2000);
			}
			else {
				var url = $t.attr("aurl");
				if(url == "") {
					window.location.reload();
				}
				else {
					window.location.href = url;
				}
			}
		};
		sqlMasker.CustomDom.delAlbum = '<div class="sqlali" p="'+ap+'" g="'+ag+'" n="'+an+'" i="'+ai+'">' +
				'<div title="'+an+'" class="sqlaliW">'+
					'<table cellspacing="0" cellpadding="0">'+
						'<tr>'+
							'<td><img src="'+aSrc+'" alt="'+aAlt+'" title="'+aAlt+'" /></td>'+
						'</tr>'+
					'</table>'+
				'</div>'+
			'</div>'+
			'<div class="sqlMaskerContent" style="line-height:18px;margin-top:-65px;overflow:hidden;width:'+ (sqlMasker.config.showerWidth-20) +'px">'+
				'此操作不可恢复，你确定要删除&nbsp;“&nbsp;<b>'+an+'</b>&nbsp;”&nbsp;相册里的所有照片吗？'+
			'</div>'+
			'<div class="sqlPopupOperation" style="margin-top:25px">'+
				'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
				'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
			'</div>';
		sqlMasker.init("Basic", "innerHTML");
		//init("Basic", "appendChild");	
	}
};

var sqlOperation = {
	inTag     : true,
	cur       : {},
	last      : {},
	d         : function() {return $(".sqlA").attr("d");},
	i         : {},
	t         : {},
	g         : {},
	p         : {},
	initAlbum : function() {
		$("input").filter(function(){return $(this).attr("maxlength")=="8";}).bind("keyup",function(e){var e=e||event;var c=e.which||e.keyCode;if(c==32){var p=e.srcElement||e.target;p.value=p.value.replace(/ /g, "");}});
		$(".sqlali").hover(function(){sqlOperation.cur=this;$(this).children(".sqlaliE").children(".sqlalieE").slideDown(100).end().end().children(".sqlaliW").addClass("sqlaliWH");},function(){sqlOperation.cur=this;$(this).children(".sqlaliE").children(".sqlalieE").slideUp(100).end().end().children(".sqlaliW").removeClass("sqlaliWH");});
		$(".sqlaliAT").hover(function(){
				var $this = $(this);
				if($this.attr("innerHTML")!="我的照片") {
					$this.css("background-color","#fffdea").css("border","1px solid #666").css("padding","0");
					$this.bind("click", function(){sqlOperation._sea();return false;});
				}
			},
			function(){
				$(this).css("background-color","transparent").css("border","none").css("padding","1px");
			}
		);
		
		$(document).click(function(ev){
			ev = ev || window.event;
			var target = ev.target || ev.srcElemen;
			if(sqlOperation.inTag && target.className.indexOf("sqlaligI") < 0 && target.className.indexOf("sqlaligsS") < 0 && target.className.indexOf("sqlaligSave") < 0 && target.getAttribute("maxlength") != "8") {
				$(sqlOperation.last).children(".sqlaliG").slideUp("fast",function(){
					$(sqlOperation.last).children("a.sqlaliAT,div.sqlaliNQ,.sqlaliE").fadeIn("slow");
				});
			}
			sqlOperation.inTag = true;
		});

		$(".sqlalinGrantShow").hover(function(){
				$(this).css("background-color","#fffdea").css("border","1px solid #666");
				$(this).bind("click", function(){sqlOperation.inTag = false;sqlOperation._sea();});
			},
			function(){
				$(this).css("background-color","transparent").css("border","0");
			}
		);
		
		$(".sqlalieeS").parent().click(function(){sqlOperation.inTag=false;sqlOperation._sea();}).next().click(function() {
			var $t = $(this).parents(".sqlali");
			var ap = $t.attr("p");
			var ag = $t.attr("g");
			var an = $t.attr("n");
			var ai = $t.attr("i");
			var $aImg = $t.find(".sqlJustATag");
			var aSrc = $aImg.attr("src");
			var aAlt = $aImg.attr("alt");
			sqlMasker.config.shower.contentType = "delAlbum";
			sqlMasker.config.shower.width = 400;
			sqlMasker.config.shower.title = "提示";
			sqlMasker.config.shower.xhr.type = "post";
			sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/DeleteAlbum";
			sqlMasker.config.shower.xhr.value = ["albumId=", ai];
			sqlMasker.operation.ajax.preDeal = function() {
				$(".sqlPopupOperation").css("display", "none");
			};
			sqlMasker.operation.ajax.callback = function(json) {
				if(json.Result<=0) {
					$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>删除</span>失败了……</b>");
					window.setTimeout(sqlMasker.close, 2000);
				}
				else {
					window.location.reload();
				}
			};
			sqlMasker.CustomDom.delAlbum = '<div class="sqlali" p="'+ap+'" g="'+ag+'" n="'+an+'" i="'+ai+'">' +
					'<div class="sqlaliW">'+
						'<table cellspacing="0" cellpadding="0">'+
							'<tr>'+
								'<td><img src="'+aSrc+'" alt="'+aAlt+'" title="'+aAlt+'" /></td>'+
							'</tr>'+
						'</table>'+
					'</div>'+
				'</div>'+
				'<div class="sqlMaskerContent" style="line-height:18px;margin-top:-65px;overflow:hidden;width:'+ (sqlMasker.config.showerWidth-20) +'px">'+
					'此操作不可恢复，你确定要删除&nbsp;"&nbsp;<b>'+an+'</b>&nbsp;"&nbsp;相册里的所有照片吗？'+
				'</div>'+
				'<div class="sqlPopupOperation" style="margin-top:25px">'+
					'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
					'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
				'</div>';
			sqlMasker.init("Basic", "innerHTML");
			//init("Basic", "appendChild");	
		});
		$("select.sqlaligsS").bind("change", function(){
			sqlOperation.inTag = false;
			if($(this).attr("selectedIndex")==3) {
				$(this).next().fadeOut("fast");
				$(this).parent().next().slideDown("fast");
			}
			else {
				$(this).parent().next().slideUp("fast");
				$(this).next().fadeIn("fast");
			}
		});
		$(".sqlaligSave").bind("click", function(){
			var n = sqlOperation.t.value;
			var g = sqlOperation.g;
			var gn = g.options[g.options.selectedIndex].text;
			var gi = g.options[g.options.selectedIndex].value;
			var p = sqlOperation.p.value;
			if(gi == 3 && p == "") {
				alert("哦？忘记输密码啦！");
				return false;
			}
			var url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/UpdateAlbum";
			var req = {"webservices": url,"contentType":"application/x-www-form-urlencoded","values":["albumId=",sqlOperation.i,"&albumTitle=",encodeURIComponent(n),"&privacy=",encodeURIComponent(gi),"&password=",p].join("")};
			var t = sqlOperation.cur;
			CNMS.loadAjax(req, callback);
			function callback(aoJson) {
				if(aoJson.Result>0) {
					$(t).attr("n", n);
					$(t).attr("g", gi);
					$(t).attr("p", p);
					$(t).children(".sqlaliAT").attr("innerHTML", n);
					$(t).children(".sqlaliNQ").children(".sqlalinGrantShow").attr("innerHTML", gn);
				}
				$(t).children(".sqlaliG").slideUp("fast",function(){
					$(t).children("a.sqlaliAT,div.sqlaliNQ,.sqlaliE").fadeIn("slow");
				})
			}
		});
	},
	_sea : function() {
		if(!!sqlOperation.last) {
			$(".sqlali").children("a.sqlaliAT,div.sqlaliNQ,.sqlaliE").css("display", "block").end().children(".sqlaliG").css("display", "none");
		}
		sqlOperation.last=sqlOperation.cur;
		var t = sqlOperation.cur;
		$(t).children("a.sqlaliAT,div.sqlaliNQ,.sqlaliE").fadeOut("fast", function(){
			$(t).children(".sqlaliG").slideDown("fast", function(){
				sqlOperation.p = $(this).children("div:nth-child(3)").children("input[maxlength='8']").get(0);
				if($(t).attr("g")==3) {
					$(this).children("div:nth-child(3)").css("display", "");
					sqlOperation.p.value=$(t).attr("p");
					$(this).children("div:nth-child(2)").children("a").fadeOut("fast");
				}
				else {
					$(this).children("div:nth-child(2)").children("a").css("display", "block");
					$(this).children("div:nth-child(3)").css("display", "none");
				}
				
				var i = $(t).attr("i");
				sqlOperation.i=i;
				sqlOperation.t = $(this).children("div:first").children(".sqlaligI").get(0);
				if(sqlOperation.d() == i) {
					$(sqlOperation.t).attr("value", $(t).attr("n")).attr("readonly", "readonly");
				}
				else {
					sqlOperation.t.value=$(t).attr("n");
				}
				sqlOperation.g = $(this).children("div:nth-child(2)").children("select").get(0);
				sqlOperation.g.selectedIndex=$(t).attr("g");
			});
		});
	}
};

var sqlPO = {
	c    : {},
	init : function() {
		$(".sqlapldD").each(
			function(){
				$this=$(this);
				$this.reflect({height:30, opacity:0.35});
				$this.parent().prev().children("img").load(
					function(){
						$this.reflect({height:30, opacity:0.35});
					}
				).unbind("load");
			}
		);
	},
	ll : function(s) {
		if(s.length > 25) {
			return s.substring(0, 24)+"…";
		}
		return s;
	}
};

var sqlSS = {
	init : function() {
		//$(".sqlapfO div a img").load(function(){sqlSS.size($(this), 600);}).each(function(){sqlSS.size($(this), 600);});
		$(".sqlapftW").each(
			function(){
				$(this).children("span").children("a").click(
					function(){
						$p = $(this).parent();
						$b = $p.prev();
						$k = $b.prev();
						$p.fadeOut("fast");
						$k.fadeOut("fast", 
							function(){
								$b.fadeIn("fast").css("display", "block");
							}
						);
						return false;
					}
				);
			}
		);
		$(".sqlapftwB").children("a").click(
			function(){
				var $this = $(this);
				var $ti = $this.prev();
				var $tp = $this.parent();
				var n = $tp.attr("n");
				var v = $ti.attr("value");
				var i = $tp.attr("i");
				if(n!=v && !!v) {
					var url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/UpdateImageCaption";
					var req = {"webservices": url,"contentType":"application/x-www-form-urlencoded","values":["imageId=",i,"&imageCaption=",encodeURIComponent(v)].join("")};
					CNMS.loadAjax(req, callback);													
				}
				else {
					$tp.fadeOut("fast", function(){$(this).prev().fadeIn("fast").end().next().fadeIn("fast");});
				}
				function callback() {
					$tp.fadeOut("fast", function(){$(this).prev().fadeIn("fast", function(){$tp.attr("n", v).prev().attr("innerHTML", sqlPO.ll(v));}).end().next().fadeIn("fast");});
				}
			}
		);
		try {
			var coolPoint = CoolPoint({
					dom : {
						wrapper : document.getElementById("coolPoint_cell"),
						lastGroup : document.getElementById("coolPoint_lastGroup") , 
						nextGroup : document.getElementById("coolPoint_nextGroup"),
						submit : document.getElementById("coolPoint_submit"),
						score : document.getElementById("coolPoint_score")
					},
					smartListConf : { 
						dataUrl : "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/GetImageProps?imageId="+_imageId+"&userId="+_userId+"&start={K:start}&count={K:count}&kw=",
						wrapper : document.getElementById("coolPoint_cell"),
						header : '',
						repeater : '<a href="http://www.myspace.cn/{K:UserId}" target="_blank"><img id="{K:UserId}" src="{K:Image}" /></a>',
						footer : '',
						emptyView : '<ul><div style="margin-top:30px">做第一个送酷点的好友吧！</div></ul>',
						pageSize : 12
					},
					tipConf : { 
						tipClassName : "kcz_tipWrapper",
						tipView : '<div class="userName">{K:DisplayName}</div><div class="age"    {K:Display}>{K:Gender}，{K:Age}{K:Star}</div><div class="place" {K:Display}>{K:City}</div><div class="avartaWrapper"><img alt="{K:DisplayName}" src="{K:Image}" /></div>'
					}
				}
			);
			coolPoint.smartList.event.getData = function(aoData){
				var lxData = aoData.List;
				for(var i=0; i<lxData.length; i++) {
					var loData = lxData[i];
					loData["ImageM"] = loData["Image"].replace("c_","m_");
					var lsStar = loData["Star"];
					if(lsStar!=""){
						loData["Star"]="，"+lsStar;
					}
					if(loData["Age"]==0 || loData["Age"]==109){
						loData["Display"]='style="display:none;"';
					}
					coolPoint.tip.data[loData.UserId] = loData;					
				}		
			};			
			coolPoint.ctrl.postUrl = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/AddImageProps";
			coolPoint.tip.getKey = function(aeNode){
				return aeNode.id;
			};
			coolPoint.submit = function(){
				var obj = coolPoint;
				var loRequest={
					"webservices": obj.ctrl.postUrl,
					"contentType":"application/x-www-form-urlencoded",
					"values":"imageId="+_imageId+"&userId="+_userId
				};
				if(_isLogin && _canSent) {
					CNMS.loadAjax(loRequest, action);
				}
				else if(!_isLogin){
					alert("请先登录");
				}
				else if(_isOwner) {
					alert("不能给自己酷点");
				}
				else if(!_canSent) {
					alert("您已送过酷点");
				}
				function action(aoData){
					if(aoData.Result == "1"){
						_canSent = false;
						obj.dom.submit.className = "haveSup";
						$(obj.dom.submit).find("u").attr("innerHTML", "个酷点");
						obj.refreshFirstPage();	
						obj.event.submit();	
                        
                        if(sharePhotoFromCoolPoint&&confirm("赠送酷点成功！马上将此内容分享给你的好友？")){
                            alert("已分享成功！");
                             var loPopShareRequest = {
                                "webservices":"http://share.myspace.cn/api/do_add_share.php",
                                "values":sharePhotoFromCoolPoint.conf["queryString"],
                                "contentType":"application/x-www-form-urlencoded"
                            }
                            CNMS.loadAjax(loPopShareRequest,function(){},"share");
                        }                        
					}else{
						alert(aoData.Msg);
					}
				}
			};
			coolPoint.buildUI();
			coolPoint.listen();
		}
		catch(e){}
	},
	size : function(o, x) {
		var w = o.attr("offsetWidth");
		var h = o.attr("offsetHeight");
		if(w > x) {
			h = parseInt(h/w*x);
			w = x;
		}
		o.css({"width":w, "height":h});
	}
};

var sqlMasker = {
	config : {
		smTag       : "sqlMasker",   //   标识弹出对话框
		shower      : {              //   实际内容显示区域
			width       : 0,
			top         : 0,
			left        : 0,
			title       : "",
			borderWidth : 7,
			className   : "sqlMaskerShower",
			contentClass: "sqlMaskersoContent",
			contentType : "",
			xhr         : {url : "", type : "", value : []}
		},
		browser     : {             //   获取浏览器的各项指标
			width       : 0,
			height      : 0,
			hideSpecial : ["select", "object", "embed", "iframe"]
		}
	},
	DOM : {
		Basic : {
			style : '.sqlMasker {display:block}'+
					'.sqlMaskerBG {position:absolute;left:0;top:0;z-index:100;width:100%;background:black;opacity:0.5;-moz-opacity:0.5;filter:alpha(opacity=50);opacity:0.5}'+
					'.sqlMaskerShower {position:absolute;background-color:#fff;z-index:200}'+
					'.sqlMaserksOuter {border:7px solid #1F52AA;margin:0;list-style:none}'+
					'.sqlMaserksOuter dt {overflow:hidden;display:block;color:#039;height:16px;font-size:12px;font-weight:bold;margin:10px 10px 5px;padding:0}'+
					'.sqlMaserksOuter dt div {float:left}'+
					'.sqlMaserksOuter dt span {display:table-cell;display:-moz-inline-box;display:inline-block;background:url(http://xfiles.cdnmyspace.cn/dir/uibox/idialog/img/icons.gif) no-repeat; width:16px; height:16px; vertical-align:middle;margin-right:3px}'+
					'.sqlMaserksOuter dt a {background:url(http://xfiles.cdnmyspace.cn/dir/uibox/idialog/img/icons.gif) no-repeat;background-position:0 -35px;float:right;width:15px;height:15px;}'+
					'.sqlMaskersoGang {background:url(http://xfiles.cdnmyspace.cn/dir/uibox/idialog/img/icons.gif) repeat-x; background-position:0 -20px; border-top:1px solid #9EC1E3;display:block;height:5px;overflow:hidden;margin:0 10px}'+
					'.sqlMaskersoContent{margin:30px 10px;text-align:center}',
			frame : function(){
				return '<div class="sqlMasker" style="display:block">'+
					'<div class="sqlMaskerBG" style="height:'+sqlMasker.config.browser.height+'px"></div>'+
					'<div class="sqlMaskerShower" style="top:'+sqlMasker.config.shower.top+'px;left:'+sqlMasker.config.shower.left+'px">'+
						'<dl class="sqlMaserksOuter" style="width:'+sqlMasker.config.shower.width+'px">'+
							'<dt>'+
								'<div>'+
									'<span></span>'+ sqlMasker.config.shower.title+
								'</div>'+
								'<a href="#this" onclick="sqlMasker.close()"></a>'+
							'</dt>'+
							'<dd class="sqlMaskersoGang"></dd>'+
							'<dd class="sqlMaskersoContent">'+
								'{sql:dialogType}'+
							'</dd>'+
						'</dl>'+
					'</div>'+
				'</div>';
			}
		}
	},
	CustomDom : {},
	operation : {
		getData : {
			browser : function() {
				var db = document.body;
				var dd = document.documentElement;
				var bhs = db.scrollHeight;
				var bhc = dd.clientHeight;
				
				sqlMasker.config.browser.width = db.scrollWidth;
				sqlMasker.config.browser.height = bhs > bhc ? bhs : bhc;
				sqlMasker.config.shower.top = dd.scrollTop + 100;
				if(navigator.userAgent.toLowerCase().indexOf("safari") >= 0) {
					sqlMasker.config.shower.top = window.pageYOffset + 100;
				}
				sqlMasker.config.shower.left = (sqlMasker.config.browser.width - sqlMasker.config.shower.width - sqlMasker.config.shower.borderWidth*2)/2;
			}
		},
		ajax : {
			xhr : function() {
				sqlMasker.operation.ajax.preDeal();
				if(sqlMasker.config.shower.xhr.type == "post") {
					var req = {"webservices": sqlMasker.config.shower.xhr.url,"contentType":"application/x-www-form-urlencoded","values":sqlMasker.config.shower.xhr.value.join("")};
					CNMS.loadAjax(req, sqlMasker.operation.ajax.callback);
				}
				else {
					
				}
			},
			preDeal : function(){},
			callback : function() {}
		},
		eventHandler : {
			scroll : function() {
				$("."+sqlMasker.config.shower.className).css("top", document.documentElement.scrollTop + 100 + "px");
				if(navigator.userAgent.toLowerCase().indexOf("safari") >= 0) {
					$("."+sqlMasker.config.shower.className).css("top", window.pageYOffset + 100 + "px");
				}
			},
			resize : function() {
				$("."+sqlMasker.config.shower.className).css("left", (document.body.scrollWidth - sqlMasker.config.shower.width - sqlMasker.config.shower.borderWidth*2)/2 + "px");
			}
		},
		hideAll : function(value) {
			$(sqlMasker.config.browser.hideSpecial.join(",")).css("visibility", value);
		}
	},
	init : function(type, category) {
		sqlMasker.operation.hideAll("hidden");
		if($("."+sqlMasker.config.smTag).length <= 0) {
			sqlMasker.operation.getData.browser();	
			$("head").append("<style type=\"text/css\">"+sqlMasker.DOM[type].style+"</style>");
			if(category == "innerHTML") {
				$("body").append(sqlMasker.DOM[type].frame().split("{sql:dialogType}").join(sqlMasker.CustomDom[sqlMasker.config.shower.contentType]));
			}
			else if(category == "appendChild") {
				
			}
		}
		else {
			var $sqlMasker = $("."+sqlMasker.config.smTag);
			$sqlMasker.css("display","block");
			if(category == "innerHTML") {
				$("."+sqlMasker.config.shower.contentClass).append(sqlMasker.CustomDom[sqlMasker.config.shower.contentType]);
			}
			else if(category == "appendChild") {
				
			}
		}
		$(window).scroll(sqlMasker.operation.eventHandler.scroll);
		$(window).resize(sqlMasker.operation.eventHandler.resize);
	},
	close : function() {
		sqlMasker.operation.hideAll("visible");
		$("."+sqlMasker.config.smTag).css("display","none");
		$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "");
	}
};

var sqlTags = {
	mouseDown : false,
	mouseState : false
};

var sqlDrag = {
	finalSequence : [],
	mouseOffset : null,
	iMouseDown : false,
	lMouseState : false,
	dragObject : null,
	DragDrops : [],
	curTarget : null,
	lastTarget : null,
	dragHelper : null,
	rootParent : null,
	rootSibling : null,
	moved : false,
	CreateDragContainer : function() {
		var cDrag        = sqlDrag.DragDrops.length;
		sqlDrag.DragDrops[cDrag] = [];
		for(var i=0; i<arguments.length; i++){
			var cObj = arguments[i];
			sqlDrag.DragDrops[cDrag].push(cObj);
			cObj.setAttribute('DropObj', cDrag);
			for(var j=0; j<cObj.childNodes.length; j++){
				if(cObj.childNodes[j].nodeName=='#text') continue;	
				cObj.childNodes[j].setAttribute('DragObj', cDrag);
			}
		}
	},
	init : function() {
		Number.prototype.NaN0=function(){return isNaN(this)?0:this;};
		function getPosition(e){
			var left = 0;
			var top  = 0;
			while (e.offsetParent){
				left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
				top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
				e     = e.offsetParent;
			}
			left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
			top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
			return {x:left, y:top};
		}
		
		function mouseCoords(ev){
			if(ev.pageX || ev.pageY){
				return {x:ev.pageX, y:ev.pageY};
			}
			return {
				x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
				y:ev.clientY + document.body.scrollTop  - document.body.clientTop
			};
		}

		function getMouseOffset(target, ev){
			ev = ev || window.event;
			var docPos    = getPosition(target);
			var mousePos  = mouseCoords(ev);
			return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
		}
		
		function mouseMove(ev){
			ev         = ev || window.event;
			var target   = ev.target || ev.srcElement;
			if(target.className != "sqlmiB" && target.tagName.toLowerCase() == "img") {
				target = target.parentNode;
			}
			var mousePos = mouseCoords(ev);
				var dragObj = target.getAttribute('dragObj');
				if(dragObj!=null){
					if(target!=sqlDrag.lastTarget){
						var oClass = target.getAttribute('overClass');
						if(oClass){
							target.setAttribute('origClass', target.className);
							target.className = oClass;
						}
					}
					if(sqlDrag.iMouseDown && !sqlDrag.lMouseState){
						sqlPM.operation.movedTag = true;
						sqlDrag.moved = true;
						sqlDrag.curTarget     = target;
						sqlDrag.rootParent    = sqlDrag.curTarget.parentNode;
						sqlDrag.rootSibling   = sqlDrag.curTarget.nextSibling;
						sqlDrag.mouseOffset   = getMouseOffset(target, ev);
						for(var i=0; i<sqlDrag.dragHelper.childNodes.length; i++) sqlDrag.dragHelper.removeChild(sqlDrag.dragHelper.childNodes[i]);

						sqlDrag.dragHelper.appendChild(sqlDrag.curTarget.cloneNode(true));
						sqlDrag.dragHelper.style.display = 'block';
						var dragClass = sqlDrag.curTarget.getAttribute('dragClass');
						if(dragClass){
							sqlDrag.dragHelper.firstChild.className = dragClass;
						}
						sqlDrag.dragHelper.firstChild.removeAttribute('DragObj');
						var dragConts = sqlDrag.DragDrops[dragObj];
						sqlDrag.curTarget.setAttribute('startWidth',  parseInt(sqlDrag.curTarget.offsetWidth));
						sqlDrag.curTarget.setAttribute('startHeight', parseInt(sqlDrag.curTarget.offsetHeight));
						sqlDrag.curTarget.style.display  = 'none';

						for(var i=0; i<dragConts.length; i++){
							with(dragConts[i]){
								var pos = getPosition(dragConts[i]);
								setAttribute('startWidth',  parseInt(offsetWidth));
								setAttribute('startHeight', parseInt(offsetHeight));
								setAttribute('startLeft',   pos.x);
								setAttribute('startTop',    pos.y);
							}
							for(var j=0; j<dragConts[i].childNodes.length; j++){
								with(dragConts[i].childNodes[j]){
									if((nodeName=='#text') || (dragConts[i].childNodes[j]==sqlDrag.curTarget)) continue;
		
									var pos = getPosition(dragConts[i].childNodes[j]);
									setAttribute('startWidth',  parseInt(offsetWidth));
									setAttribute('startHeight', parseInt(offsetHeight));
									setAttribute('startLeft',   pos.x);
									setAttribute('startTop',    pos.y);
								}
							}
						}
					}
				}
				if(sqlDrag.curTarget){
					sqlDrag.dragHelper.style.top  = mousePos.y - sqlDrag.mouseOffset.y;
					sqlDrag.dragHelper.style.left = mousePos.x - sqlDrag.mouseOffset.x;
		
					var dragConts  = sqlDrag.DragDrops[sqlDrag.curTarget.getAttribute('DragObj')];
					var activeCont = null;
		
					var xPos = mousePos.x - sqlDrag.mouseOffset.x + (parseInt(sqlDrag.curTarget.getAttribute('startWidth')) /2);
					var yPos = mousePos.y - sqlDrag.mouseOffset.y + (parseInt(sqlDrag.curTarget.getAttribute('startHeight'))/2);
					for(var i=0; i<dragConts.length; i++){
						with(dragConts[i]){
							if((parseInt(getAttribute('startLeft'))                                           < xPos) &&
								(parseInt(getAttribute('startTop'))                                            < yPos) &&
								((parseInt(getAttribute('startLeft')) + parseInt(getAttribute('startWidth')))  > xPos) &&
								((parseInt(getAttribute('startTop'))  + parseInt(getAttribute('startHeight'))) > yPos)){

									activeCont = dragConts[i];
									break;
							}
						}
					}

					if(activeCont){
						var beforeNode = null;

						for(var i=activeCont.childNodes.length-1; i>=0; i--){
							with(activeCont.childNodes[i]){
								if(nodeName=='#text') continue;
								if(sqlDrag.curTarget != activeCont.childNodes[i]                                                  &&
									((parseInt(getAttribute('startLeft')) + parseInt(getAttribute('startWidth')))  > xPos) &&
									((parseInt(getAttribute('startTop'))  + parseInt(getAttribute('startHeight'))) > yPos)){
										beforeNode = activeCont.childNodes[i];
								}
							}
						}
						if(beforeNode){
							if(beforeNode!=sqlDrag.curTarget.nextSibling){
								activeCont.insertBefore(sqlDrag.curTarget, beforeNode);
							}
						} else {
							if((sqlDrag.curTarget.nextSibling) || (sqlDrag.curTarget.parentNode!=activeCont)){
								activeCont.appendChild(sqlDrag.curTarget);
							}
						}
						setTimeout(function(){
						var contPos = getPosition(activeCont);
						activeCont.setAttribute('startWidth',  parseInt(activeCont.offsetWidth));
						activeCont.setAttribute('startHeight', parseInt(activeCont.offsetHeight));
						activeCont.setAttribute('startLeft',   contPos.x);
						activeCont.setAttribute('startTop',    contPos.y);}, 5);
						if(sqlDrag.curTarget.style.display!=''){
							sqlDrag.curTarget.style.display    = '';
							sqlDrag.curTarget.style.cssText = 'opacity:0.3;-moz-opacity:0.3;*filter:alpha(opacity=30);background:green';
						}
					}
					else {
						if(sqlDrag.curTarget.style.display!='none'){
							sqlDrag.curTarget.style.display  = 'none';
						}
					}
					sqlDrag.curTarget.setAttribute("c", "0");
					var r = new RegExp(sqlDrag.curTarget.getAttribute("pid")+"\,");
					sqlPM.data.buffer = sqlPM.data.buffer.replace(r, "");
				}
				sqlDrag.lMouseState = sqlDrag.iMouseDown;
				sqlDrag.lastTarget  = target;

			if(sqlDrag.dragObject){
				sqlDrag.dragObject.style.position = 'absolute';
				sqlDrag.dragObject.style.top      = mousePos.y - sqlDrag.mouseOffset.y;
				sqlDrag.dragObject.style.left     = mousePos.x - sqlDrag.mouseOffset.x;
			}
			sqlDrag.lMouseState = sqlDrag.iMouseDown;
			if(sqlDrag.curTarget || sqlDrag.dragObject) return false;
		}
		
		function mouseUp(ev){
			ev = ev || window.event;
			var t = ev.target || ev.srcElement;
			if(!sqlDrag.moved && (t.className == "sqlmiB" || t.parentNode.className == "sqlmiB")) {
				var $t = $(t);
				if(t.className != "sqlmiB") {
					$t = $t.parent();
				}
				var pid = $t.attr("pid");
				if($t.attr("c")==0) {
					$t.css("background", "#6698cb").attr("c", "1");
					sqlPM.data.buffer += pid + ",";
				}
				else {
					$t.css("background", "#f0f0f0").attr("c", "0");
					var r = new RegExp(pid+"\,");
					sqlPM.data.buffer = sqlPM.data.buffer.replace(r, "");
				}
			}
			sqlDrag.moved = false;
			if(sqlDrag.curTarget){
				sqlDrag.dragHelper.style.display = 'none';
				if(sqlDrag.curTarget.style.display == 'none'){
					if(sqlDrag.rootSibling){
						sqlDrag.rootParent.insertBefore(sqlDrag.curTarget, sqlDrag.rootSibling);
					} else {
						sqlDrag.rootParent.appendChild(sqlDrag.curTarget);
					}
				}
				sqlDrag.curTarget.style.display    = '';
				sqlDrag.curTarget.style.cssText = 'opacity:1;-moz-opacity:1;*filter:alpha(opacity=100)';
			}
			sqlDrag.curTarget  = null;
			sqlDrag.dragObject = null;
			sqlDrag.iMouseDown = false;
		}
		
		function mouseDown(ev){
			ev         = ev || window.event;
			var target = ev.target || ev.srcElement;
			if(target.className != "sqlmiB" && target.tagName.toLowerCase() == "img") {
				target = target.parentNode;
			}

			sqlDrag.iMouseDown = true;
			if(target.onmousedown || target.getAttribute('DragObj') || target.parentNode.getAttribute('DragObj')){
				return false;
			}
		}
		
		function makeDraggable(item){
			if(!item) return;
			item.onmousedown = function(ev){
				sqlDrag.dragObject  = this;
				sqlDrag.mouseOffset = getMouseOffset(this, ev);
				return false;
			}
		}
		document.onmousemove = mouseMove;
		document.onmousedown = mouseDown;
		document.onmouseup   = mouseUp;
	}
};

var sqlPM = {
	data : {
		img : typeof ImagesJson == "undefined" ? {} : ImagesJson,
		dom : {
			className : {
				normal : "sqlmiB"
			},
			html : '<div pid="{sql:id}" dragClass="sqlmiBMove" c="0" class="{sql:className}">'+
				'<img src="{sql:src}" title="{sql:name}" alt="{sql:name}" />'+
			  '</div>'
		},
		wrapper : $(".sqlMoveImg"),
		buffer : ""
	},
	operation : {
		movedTag : false,
		moveTag : true,
		destinationAlbumId : null,
		show : function() {
			var l = sqlPM.data.img.length;
			var x = [];
			for(var i=0; i<l; i++) {
				x[i] = sqlPM.data.dom.html.split("{sql:id}").join(sqlPM.data.img[i].id).split("{sql:className}").join(sqlPM.data.dom.className.normal).split("{sql:src}").join(sqlPM.data.img[i].src).split("{sql:name}").join(sqlPM.data.img[i].name);
			}
			sqlPM.data.wrapper.attr("innerHTML", x.join(""));
			$(".sqlmoB").children("a[title='删除']").click(sqlPM.operation.delPhotos);
			$(".sqlMoveBottom").children("a[title='删除']").click(sqlPM.operation.delPhotos);
			$(".sqlmoB").children("a[title='移动']").click(sqlPM.operation.movePhotos);
			$(".sqlMoveBottom").children("a[title='移动']").click(sqlPM.operation.movePhotos);
			$(".sqlmoB").children("a[title='保存排序结果']").click(sqlPM.operation.sort);
			$(".sqlMoveBottom").children("a[title='保存排序结果']").click(sqlPM.operation.sort);
		},
		delPhotos : function() {
			sqlMasker.config.shower.contentType = "delPhotos";
			sqlMasker.config.shower.width = 400;
			sqlMasker.config.shower.title = "批量删除照片";
			sqlMasker.config.shower.xhr.type = "post";
			sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/DeleteMultipleImages";
			sqlMasker.operation.ajax.preDeal = function() {
				$(".sqlPopupOperation").css("display", "none");
			};
			if(sqlPM.data.buffer != "") {
				sqlMasker.config.shower.xhr.value = ["albumId=", moveAid, "&imageIds=", sqlPM.data.buffer];
				sqlMasker.operation.ajax.callback = function(json) {
					if(json.Result<=0) {
						$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>删除</span>失败了……</b>");
						window.setTimeout(sqlMasker.close, 2000);
					}
					else {
						window.location.reload();
					}
				};
				sqlMasker.CustomDom.delPhotos = '<div class="sqlMaskerContent" style="line-height:18px;margin-top:10px;overflow:hidden;width:'+ (sqlMasker.config.shower.width-20) +'px">'+
						'此操作不可恢复，你确定要删除吗？'+
					'</div>'+
					'<div class="sqlPopupOperation" style="margin-top:25px">'+
						'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
						'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
					'</div>';
			}
			else {
				sqlMasker.CustomDom.delPhotos = "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>哎呀呀，你还没有<span style='color:red'>选择照片</span>……</b>";
				window.setTimeout(sqlMasker.close, 2000);
			}
			sqlMasker.init("Basic", "innerHTML");
		},
		sort : function() {
			sqlMasker.config.shower.contentType = "sort";
			sqlMasker.config.shower.width = 400;
			sqlMasker.config.shower.title = "保存照片排序";
			sqlMasker.config.shower.xhr.type = "post";
			sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/ArrangeAlbumImages";
			sqlMasker.operation.ajax.preDeal = function() {
				$(".sqlPopupOperation").css("display", "none");
			};
			if(sqlPM.operation.movedTag) {
				var s = [];
				$(".sqlmiB").each(function(){
					s.push($(this).attr("pid"));
				});
				sqlMasker.config.shower.xhr.value = ["albumId=", moveAid, "&imageIds=", s.join(",")];
				sqlMasker.operation.ajax.callback = function(json) {
					if(json.Result<=0) {
						$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>排序</span>失败了……</b>");
						window.setTimeout(sqlMasker.close, 2000);
					}
					else {
						window.location.reload();
					}
				};
				sqlMasker.CustomDom.sort = '<div class="sqlMaskerContent" style="line-height:18px;margin-top:10px;overflow:hidden;width:'+ (sqlMasker.config.shower.width-20) +'px">'+
						'你确定要对照片进行重新排序吗？'+
					'</div>'+
					'<div class="sqlPopupOperation" style="margin-top:25px">'+
						'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
						'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
					'</div>';
			}
			else {
				sqlMasker.CustomDom.sort = "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>喵~~~，你还没有<span style='color:red'>排序</span>照片呢……</b>";
				window.setTimeout(sqlMasker.close, 2000);
			}
			sqlMasker.init("Basic", "innerHTML");
		},
		movePhotos : function() {
			sqlMasker.config.shower.contentType = "movePhotos";
			sqlMasker.config.shower.width = 400;
			sqlMasker.config.shower.title = "批量移动照片";
			sqlMasker.config.shower.xhr.type = "post";
			sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/CreateAlbum";
			if(sqlPM.data.buffer != "") {
				sqlMasker.operation.ajax.preDeal = function() {
					var sqlAlbumGrant = "";
					$("input[name='sqlAlbumRadio']").each(function() {
						var $this = $(this);
						if($this.attr("checked") == true) {
							sqlAlbumGrant = $this.attr("value");
						}
					});
					if(sqlPM.operation.moveTag) {
						var select = $(".sqlMovePhoto").children("select")[0];
						sqlPM.operation.destinationAlbumId = sqlPM.operation.destinationAlbumId || select.options[select.options.selectedIndex].value;
						if(sqlPM.operation.destinationAlbumId == "-1") {
							return false;
						}
						sqlMasker.config.shower.xhr.value = ["albumId=", moveAid, "&destinationAlbumId=", sqlPM.operation.destinationAlbumId, "&imageIds=", sqlPM.data.buffer];	
						sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/MoveMultipleImagesToNewAlbum";
					}
					else {
						sqlMasker.config.shower.xhr.value = ["albumTitle=", encodeURIComponent($("input[name='sqlAlbumNameMod']").attr("value")), "&privacy=", sqlAlbumGrant, "&password=", $("input[name='sqlPasswordMod']").attr("value")];
						$(".sqlPopupOperation").css("display", "none");
					}
				};
				sqlMasker.operation.ajax.callback = function(json) {
					if(sqlPM.operation.moveTag) {
						if(json.Result<=0) {
						$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>移动照片</span>失败了……</b>");
							window.setTimeout(sqlMasker.close, 2000);
						}
						else {
							window.location.reload();
							sqlMasker.close();
						}
					}
					else {
						if(json.Result<=0) {
							$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>移动照片</span>失败了……</b>");
							window.setTimeout(sqlMasker.close, 2000);
						}
						else {
							sqlPM.operation.destinationAlbumId = json.Result;
							sqlPM.operation.moveTag = true;
							sqlMasker.operation.ajax.xhr();
						}
					}
				};
				sqlMasker.CustomDom.movePhotos = '<div class="sqlMovePhoto" style="text-align:left"><select style="width:200px"></select></div>'+
					'<div style="margin-top:15px;color:#666;margin-bottom:15px;font-weight:bold;text-align:left">或新创建一个相册</div>'+
					'<div class="sqlModAlbumAttrName">'+
						'<b>相册名称:</b><br /><br />'+
						'<input id="sqlAlbumNameMod" maxlength="40" style="border:1px solid #999" name="sqlAlbumNameMod" type="text" value="" />'+
					'</div>'+
					'<ul class="sqlModAlbumGrant clearfix">'+
						'<li style="float:left;width:150px;font-size:12px"><b>可以查看照片的用户：</b></li>'+
						'<li style="float:left" class="sqlModAlbumGrantLi2 clearfix">'+
							'<div class="clearfix">'+
								'<input id="sqlAlbumRadio0" name="sqlAlbumRadio" style="display:block;*margin-top:-4px" checked="true" value="0" type="radio" />'+
								'<label for="sqlAlbumRadio0">所有人</label>'+
								'<input id="sqlAlbumRadio1" name="sqlAlbumRadio" style="display:block;*margin-top:-4px" value="1" type="radio" />'+
								'<label for="sqlAlbumRadio1">好友</label>'+
								'<input id="sqlAlbumRadio2" name="sqlAlbumRadio" style="display:block;*margin-top:-4px" value="2" type="radio" />'+
								'<label for="sqlAlbumRadio2">仅自己</label>'+
							'</div>'+
							'<div class="clearfix" style="margin-top:15px;height:22px;line-height:22px">'+
								'<input id="sqlAlbumRadio3" name="sqlAlbumRadio" value="3" style="display:block;margin-top:5px;*margin-top:0" type="radio" />'+
								'<label for="sqlAlbumRadio3">密码访问</label>'+
								'<input id="sqlPasswordMod" maxlength="8" name="sqlPasswordMod" type="text" style="display:none;width:100px;" />'+
							'</div>'+
							'<div class="sqlPopupOperation" style="margin-top:25px">'+
								'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>确定</i></b></a>'+
								'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
							'</div>'+
						'</li>'+
					'</ul>';
				sqlMasker.init("Basic", "innerHTML");
				$("input[name='sqlPasswordMod']").keyup(function(e){var e=e||event;var c=e.which||e.keyCode;if(c==32){var p=e.srcElement||e.target;p.value=p.value.replace(/ /g, "");}});
				$(".sqlModAlbumGrantLi2").find("input[name='sqlAlbumRadio']").click(function() {
					if($(this).attr("value") == "3") {
						$("input[name='sqlPasswordMod']").css("display", "block");
					}
					else {
						$("input[name='sqlPasswordMod']").css("display", "none");
					}
				});
				CNMS.loadJsonP("http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/GetCurrentUserAlbums?callback=sqlPM.operation.getCallback&r="+(new Date()).toString().split(" ").join(""));
			}
			else {
				sqlMasker.CustomDom.movePhotos = "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>哎呀呀，你还没有<span style='color:red'>选择照片</span>……</b>";
				window.setTimeout(sqlMasker.close, 2000);
				sqlMasker.init("Basic", "innerHTML");
			}
		},
		getCallback : function(json) {
			var s = "<option value='-1'>选择相册</option>";
			for(var i=0; i<json.length; i++) {
				s += "<option value='"+json[i].Key+"'>"+json[i].Value+"</option>";
			}
			var select = $(".sqlMovePhoto").children("select");
			var input = $("input[name='sqlAlbumNameMod']");
			select.each(function(){
				var $t = $(this);
				$t.append(s);
			}).bind("change", function(){
				if(this.options.selectedIndex != 0) {
					input.attr("readonly", true).attr("value", "").css({"background":"#ddd"});
					sqlPM.operation.moveTag = true;
				}
				else {
					input.attr("readonly", false).css({"background":""});
				}
			});
			input.keyup(function() {
				if($.trim(this.value)!="") {
					select.attr("disabled", true);
					sqlPM.operation.moveTag = false;
				}
				else {
					select.attr("disabled", false);
				}
			});
		}
	}
};

var sqlAblumInit = {
	init : function() {
		$(".sqlPLComment").click(function(ev){
			var $tcp = $(this);
			var pid = $tcp.parents(".sqlaplI").attr("i");
			sqlMasker.config.shower.contentType = "sendComment";
			sqlMasker.config.shower.width = 490;
			sqlMasker.config.shower.title = "发表评论";
			sqlMasker.config.shower.xhr.type = "post";
			sqlMasker.config.shower.xhr.url = "http://ajaxv2.myspace.cn/_Common/AjaxService/PhotoAlbumsSvc.svc/json/PostAComment";
			sqlMasker.operation.ajax.preDeal = function() {
				var tValue = document.getElementById("sqlTMDComment").value;
				if(!!$.trim(tValue)) {
					sqlMasker.config.shower.xhr.value = ["ownerId=", DisplayUserId, "&imageId=", pid, "&commentBody=", encodeURIComponent(tValue)];
				}
				else {
					return false;
				}
				$(".sqlPopupOperation").css("display", "none");
			};
	
			sqlMasker.operation.ajax.callback = function(json) {
				if(json.Result<=0) {
					$("."+sqlMasker.config.shower.contentClass).attr("innerHTML", "<img style='display:block;margin:0 auto 5px' src='http://xfiles.cdnmyspace.cn/dir/albums/v2/img/notify.jpg' />MySpace的大松鼠提示：<b>不好意思哦，<span style='color:red'>留言发表</span>失败了……</b>");
				}
				else {
					if(!!!NeedApprove) {
						var num = parseInt($tcp.attr("innerHTML").substring(5));
						$tcp.attr("innerHTML", "发表评论(" + (num + 1) +")");
					}
				}
				window.setTimeout(sqlMasker.close, 1500);
			};
			if(!!CurrentUserIsFriend) {
				sqlMasker.CustomDom.sendComment = '<div><textarea style="border:1px solid #7F9DB9;height:80px;overflow-y:scroll;width:460px" id="sqlTMDComment" name="sqlTMDComment" />'+
				'</div>';
				if(!!NeedApprove) {
					sqlMasker.CustomDom.sendComment += '<div style="margin-top:5px;height:16px;line-height:16px;text-align:right;color:#676767">您的留言需要照片主人的批准&nbsp;&nbsp;&nbsp;最多只能回复2000字</div>';
				}
				else {
					sqlMasker.CustomDom.sendComment += '<div style="margin-top:5px;height:16px;line-height:16px;text-align:right;color:#676767">最多只能回复2000字</div>';
				}
				sqlMasker.CustomDom.sendComment += '<div class="sqlPopupOperation" style="margin-top:25px">'+
					'<a href="#this" class="cnViBtnBlueJ" onclick="sqlMasker.operation.ajax.xhr()"><b><i>发表评论</i></b></a>'+
					'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
				'</div>';
			}
			else {
				sqlMasker.CustomDom.sendComment = '<div class="sqlMaskerContent" style="line-height:18px;margin-top:10px;overflow:hidden;width:'+ (sqlMasker.config.shower.width-20) +'px">'+
						'必须成为好友之后才能对照片评论。<a style="color:#039" href="http://profile.myspace.cn/modules/profiledisplay/pages/redirectAddFriend.aspx?friendid='+DisplayUserId+'" title="加为好友">点击这里</a>&nbsp;将此人加为好友。'+
					'</div>' +
					'<div class="sqlPopupOperation" style="margin-top:25px">'+
						'<a href="#this" class="cnViBtnSilver" onclick="sqlMasker.close()" style="margin-left:10px"><b><i>取消</i></b></a>'+
					'</div>';
			}
			sqlMasker.init("Basic", "innerHTML");
			ev.stopPropagation();
			return false;
		});
		sqlSS.init();
		$(document).ready(function(){
			if($(".sqlaliAT").length > 0) {
				sqlOperation.initAlbum();
			}
			sqlSubnav5.init();
			if(typeof ImagesJson != "undefined") {
				sqlPM.operation.show();
			}
			$(".sqlctcWE").find("a").click(function(){
				if($.trim($(".sqlctcWE textarea").attr("value"))=="") {
					alert("侬不能发空评论哦~~");
					return false;
				}
				this.style.display = "none";
			});
			try {
				if(!!_isLogin && !!_canSent) {
					$("#coolPoint_submit").attr("className", "");
				}
			}
			catch(e) {}
		});
		
		$(window).load(function(){
			sqlPO.init();
			if(typeof ImagesJson != "undefined") {
				sqlDrag.init();
				sqlDrag.CreateDragContainer(document.getElementById('DragContainer1'));
				sqlDrag.dragHelper = document.createElement("div");
				sqlDrag.dragHelper.style.cssText = "";
			}
		});
	}
};
(function() {
	sqlAblumInit.init();
})();