﻿/*!
 * http://www.ipow.cn/
 * Copyright (c) 2009
 * iPow
 */
jQuery.fn.photoBox=function(A){A=jQuery.extend({width:94,height:400,_width:128,_height:128,type:"ajax"},A);return this.each(function(){$local=$(this);var D=[],H=0,L=0,E=0,F=null,N=function(C){try{$("<div id=\"PhotoWin\" class=\"showPhoto\"></div>").appendTo("body");L=$local.find("a").size();$local.find("a").each(function(A){this.onclick=function(){E=A;O(C);B(this,A);return false}})}catch(A){}},O=function(C){var A="<div id=\"TB_WinBg\"></div>";D=getAllPosition(C);$("#TB_WinBg").remove();$("body").append(A);var B=document.body.scrollHeight>document.body.offsetHeight?document.body.scrollHeight:document.body.offsetHeight;$("#TB_WinBg").remove();$("body").append(A);if((typeof document.body.style.maxHeight==="undefined")&&jQuery.browser.version!=6){$("body","html").css({height:"100%",width:"100%"});$("html").css("overflow","hidden")}else $("#TB_WinBg").css("height",""+B+"px")},B=function(H,I){try{if(I>0)H=$local.find("a:eq("+E+")");D=getAllPosition(H);var G=parseInt(D.scrTop),B=0;if(!$("#PhotoWin").is(":hidden"))C(H);else{$("#PhotoWin").css({"left":D.offLeft,"top":D.offTop});if(D.offWidth>A._width)B=parseInt((D.offWidth-A._width)/2);if(D.offHeight>A._height)G=G+parseInt((D.offHeight-A._height)/2);$("#PhotoWin").animate({opacity:"show",width:A._width,height:A._height,top:G,left:B},500,"easeInOutCubic",function(){C(H)})}}catch(F){}},C=function(B){try{I(B)}catch(A){}},I=function(D){var C="<a href=\"javascript:;\" id=\"closeWin\" class=\"picclose\" title=\"\u5173\u95ed\"></a>\t\t\t<div id=\"TbPContainer\" style=\"height:"+parseInt(A._height)+"px;\"><img src=\"/images/loading.gif\" class=\"imgLoading\" align=\"middle\" ></div>";$("#PhotoWin").html(C);var E=$(D).attr("href"),B=$(D).attr("title");$("#TbPContainer").fadeIn("fast",function(){G(E,B)});$("#closeWin").click(function(){J()})},G=function(F,A){var G=new Image();G.src=F;var C;if(G.complete)H();else C=setInterval(function(){if(G.complete){H();clearInterval(C)}},1000);function H(){try{var R={width:G.width,height:G.width},J=G.width/G.height,C=document.body.clientWidth*0.95;C=G.width>C?C:G.width;var P=C/J,Q=D.offHeight,N=D.scrTop;if(P>parseInt(Q-56)){P=parseInt(Q-56)*0.95;C=P*J}var O=parseInt((D.offWidth-C)/2),I=parseInt((D.offHeight-P-56)/2)+parseInt(D.scrTop);$("#PhotoWin").animate({width:C,height:P,left:O,top:I},750,"easeOutSine",function(){$("#TbPContainer").html("<div class=\"TbPhoto\"><img src = \""+F+"\" width=\""+parseInt(C)+"\" height=\""+parseInt(P)+"\"><span>"+A+"</span></div>");$("#TbPContainer").append("<a href=\"javascript:;\" class=\"picPrev\" id=\"PicPrev\"></a><a href=\"javascript:;\" id=\"PicNext\" class=\"picNext\"></a>");$("#TbPContainer").mousemove(function(A){M(O,C,A)});$local.unbind("keyup");$local.keyup(function(C){var A=K(C);if(A==32&&E<L-1){E=E+1;B(this,1)}else{E=0;B(this,1)}});$(this).animate({height:parseInt(P+40)},500,"easeOutSine")})}catch(H){}}},K=function(B){var C=(document.all)?true:false,A=0;if(C)A=window.event.keyCode;else A=B.which;return A},M=function(G,C,D){D=D||event;var A=D.clientX,F=G;if(A>G&&A<G+C/2-40&&E>0)$("#PicPrev").show(1,function(){$(this).one("click",function(){E=E-1;B(this,1)})});else $("#PicPrev").hide();if(A>G+C/2+40&&A<G+C&&E<L-1)$("#PicNext").show(1,function(){$(this).one("click",function(){E=E+1;B(this,1)})});else $("#PicNext").hide()},J=function(){var B=0;if(D.offWidth>A._width)B=parseInt((D.offWidth-A._width)/2);var C=parseInt(D.offTop);$("#PhotoWin").animate({opacity:"hide",width:0,height:0,left:D.offLeft,top:C},500,function(){$("#PhotoWin").html("");$("#TB_WinBg").remove()})};N(this)})}