if(top.location!=self.location)top.location=self.location;

function getFavHtmlCode() {
	return "<a href=\"javascript:window.open('http://cang.baidu.com/do/add?it='+encodeURIComponent(document.title.substring(0,76))+'&iu='+encodeURIComponent(location.href)+'&fr=ien#nw=1','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0\">☆添加到百度搜藏</a>　<a href=\"javascript:window.open('http://shuqian.qq.com/post?from=3&title='+encodeURIComponent(document.title)+'&uri='+encodeURIComponent(document.location.href)+'&jumpback=2&noui=1','favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');void(0)\">☆收藏到QQ书签</a>　<a href=\"javascript:window.open('http://myweb.cn.yahoo.com/popadd.html?url='+encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title), 'Yahoo','scrollbars=yes,width=440,height=440,left=80,top=80,status=yes,resizable=yes');void(0);\">☆添加到雅虎收藏<sup>+</sup></a>　<a href=\"javascript:void(0);\" onclick=\"if(window.sidebar)window.sidebar.addPanel(document.title, document.location.href, ''); else if( document.all )window.external.AddFavorite(document.location.href, document.title); else if(window.opera && window.print)return true;\">☆添加到收藏夹</a>";
}

$(document).ready(function(){
	$("#main_big_fav").html(getFavHtmlCode());

	var lockFlag = false;
	var imgLastId = imgCnt-1; //总的最大的图片编号
	var apiUrl = urlRoot+"fzl/view_ajax.php";

    var curFlag = "";
    $("#img_big").mousemove(function (e) {
        if (typeof(event)!='undefined') { //IE
            var imgX = event.offsetX;
        }else{ //FF
            var mouseLeft = (typeof(event)!='undefined') ? event.clientX : e.pageX;
            var imgLeft = $(this).offset().left;
            var imgX = mouseLeft-imgLeft;
        }
        var thisTitle = $.trim($("#main_big_title").html());
        if (imgX < $(this).width()/2) {
            if (curFlag!="right") {
                $(this).attr("title", "[上一张] "+thisTitle)
                       .css("cursor", "url(fzl/images/cur_left.cur),auto")
                       .unbind("click")
                       .click(function () {
                           $("#btn_prev").click();
                       });
            }
            curFlag = "right";
        }else{
            if (curFlag!="left") {
                $(this).attr("title", thisTitle+" [下一张]")
                       .css("cursor", "url(fzl/images/cur_right.cur),auto")
                       .unbind("click")
                       .click(function () {
                           $("#btn_next").click();
                       });
            }
            curFlag = "left";
        }
    });


	$("#btn_next, .btn_next").click(function () {
		if (lockFlag==true) {
			return false;
		}
		if (thisImgId==imgLastId) {
			windo_location(nextAlbumId, 0);
			return false;
		}
		lockFlag = true;
		showLoading();
		var imgId = thisImgId+1;
		$.get(apiUrl, 
			{ a:albumId, i:imgId },
			function(data){
				eval("var resultObj = "+data+";");
				setImgShow(resultObj);
				thisImgId++;
				$("#page_id_span").html(thisImgId+1);
				lockFlag = false;
			}
		);
		return false;
	});

	$("#btn_prev, .btn_prev").click(function () {
		if (lockFlag==true) {
			return false;
		}
		if (thisImgId==0) {
			windo_location(prevAlbumId, 0);
			return;
		}
		lockFlag = true;
		showLoading();
		var imgId = thisImgId-1;
		$.get(apiUrl, 
			{ a:albumId, i:imgId },
			function(data){
				eval("var resultObj = "+data+";");
				setImgShow(resultObj);
				thisImgId--;
				$("#page_id_span").html(thisImgId+1);
				lockFlag = false;
			}
		);
		return false;
	});

	function setImgShow(imgInfoObj) {
		$("#img_big").removeAttr("width");
		$("#img_big").removeAttr("height");
		$("#img_big").attr("src", imgInfoObj.img_src);
		$("#img_big").css({width:"", height:""});
		$("#img_loading").html("");
		if (typeof imgInfoObj.img_prev_src == "string") {
			$("#img_loading").append('<img src="'+imgInfoObj.img_prev_src+'">');
		}
		if (typeof imgInfoObj.img_next_src == "string") {
			$("#img_loading").append('<img src="'+imgInfoObj.img_next_src+'">');
		}
	}

	function showLoading() {
		var width = 130;
		var height = 25;
		var top = $(document).scrollTop();
		var left = $(document).scrollLeft()+$(window).width()-width-9;
		$("body").append("<div class='div_loading' style='padding:3px 0 0 9px; color:#FFFFFF; background-color:#6699FF; position:absolute; z-index:99;'>载入中..请稍候...</DIV>");
		$(".div_loading").css({"width":width, "height":height, "top":top, "left":left}); //aaaaaaa
	}

	function windo_location(aid, pid) {
		var url = urlFormat;
		url = url.replace("#ALBUMID#", aid);
		url = url.replace("#PAGE#", pid);
		window.location = url;
	}
});

function hiddenLoading() {
	$(".div_loading").fadeOut("slow", function () {
		$(this).remove(); 
	});
}
