$.fn.prettyPhoto=function(S){var O=false;var P=0;var B=0;var W=0;var G=false;var N=0;var C=true;var L=[];$(window).resize(function(){A();Q()});$(document).keyup(function(X){switch(X.keyCode){case 37:if(B==1){return }K("previous");break;case 39:if(B==P){return }K("next");break;case 27:J();break}});S=jQuery.extend({animationSpeed:"normal",padding:40,opacity:0.35,showTitle:true,allowresize:true,counter_separator_label:"/"},S);$(this).each(function(){L[L.length]=this;$(this).bind("click",function(){H(this);return false})});function H(X){N=$(X);theRel=$(N).attr("rel");galleryRegExp=/\[(?:.*)\]/;theGallery=galleryRegExp.exec(theRel);contentType="image";if($(N).attr("href").indexOf(".swf")>0){G=false;contentType="flash"}O=false;P=0;for(i=0;i<L.length;i++){if($(L[i]).attr("rel").indexOf(theGallery)!=-1){P++;if(P>1){O=true}if($(L[i]).attr("href")==$(X).attr("href")){B=P;W=i}}}T(O);$("div.pictureHolder p.currentTextHolder").text(B+S.counter_separator_label+P);A();$("div.pictureHolder #fullResImageContainer").hide();$(".loaderIcon").show();(contentType=="image")?U():F()}showimage=function(a,X,d,c,b,Y,Z){$(".loaderIcon").hide();var e=E();if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth}else{windowHeight=$(window).height();windowWidth=$(window).width()}$("div.pictureHolder .content").animate({height:b,width:d},S.animationSpeed);projectedTop=e.scrollTop+((windowHeight/2)-(c/2));if(projectedTop<0){projectedTop=0+$("div.prettyPhotoTitle").height()}$("div.pictureHolder").animate({top:projectedTop,left:((windowWidth/2)-(d/2)),width:d},S.animationSpeed,function(){$("#fullResImage").attr({width:a,height:X});$("div.pictureHolder").width(d);$("div.pictureHolder .hoverContainer").height(X).width(a);D();$("div.pictureHolder #fullResImageContainer").fadeIn(S.animationSpeed);if(Z){$("a.expand,a.contract").fadeIn(S.animationSpeed)}})};function K(X){if(X=="previous"){W--;B--}else{W++;B++}if(!C){C=true}$("div.pictureHolder .hoverContainer,div.pictureHolder .details").fadeOut(S.animationSpeed);$("div.pictureHolder #fullResImageContainer").fadeOut(S.animationSpeed,function(){$(".loaderIcon").show();U()});V();$("a.expand,a.contract").fadeOut(S.animationSpeed,function(){$(this).removeClass("contract").addClass("expand")})}function J(){$("div.pictureHolder,div.prettyPhotoTitle").fadeOut(S.animationSpeed,function(){$("div.prettyPhotoOverlay").fadeOut(S.animationSpeed,function(){$("div.prettyPhotoOverlay,div.pictureHolder,div.prettyPhotoTitle").remove();if($.browser.msie&&$.browser.version==6){$("select").css("visibility","visible")}})})}function I(){if(B==P){$("div.pictureHolder a.next").css("visibility","hidden");$("div.pictureHolder a.arrow_next").addClass("disabled").unbind("click")}else{$("div.pictureHolder a.next").css("visibility","visible");$("div.pictureHolder a.arrow_next.disabled").removeClass("disabled").bind("click",function(){K("next");return false})}if(B==1){$("div.pictureHolder a.previous").css("visibility","hidden");$("div.pictureHolder a.arrow_previous").addClass("disabled").unbind("click")}else{$("div.pictureHolder a.previous").css("visibility","visible");$("div.pictureHolder a.arrow_previous.disabled").removeClass("disabled").bind("click",function(){K("previous");return false})}$("div.pictureHolder p.currentTextHolder").text(B+S.counter_separator_label+P);(O)?$c=$(L[W]):$c=$(N);if($c.attr("title")){$("div.pictureHolder .description").show().html(unescape($c.attr("title")))}else{$("div.pictureHolder .description").hide().text("")}if($c.find("img").attr("alt")&&S.showTitle){G=true;$("div.prettyPhotoTitle .prettyPhotoTitleContent").html(unescape($c.find("img").attr("alt")))}else{G=false}}function M(a,Y){hasBeenResized=false;$("div.pictureHolder .details").width(a);$("div.pictureHolder .details p.description").width(a-parseFloat($("div.pictureHolder a.close").css("width")));contentHeight=Y+parseFloat($("div.pictureHolder .details").height())+parseFloat($("div.pictureHolder .details").css("margin-top"))+parseFloat($("div.pictureHolder .details").css("margin-bottom"));contentWidth=a;containerHeight=Y+parseFloat($("div.prettyPhotoTitle").height())+parseFloat($("div.pictureHolder .top").height())+parseFloat($("div.pictureHolder .bottom").height());containerWidth=a+S.padding;imageWidth=a;imageHeight=Y;if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth}else{windowHeight=$(window).height();windowWidth=$(window).width()}if(((containerWidth>windowWidth)||(containerHeight>windowHeight))&&C&&S.allowresize){hasBeenResized=true;if((containerWidth>windowWidth)&&(containerHeight>windowHeight)){var Z=(containerWidth+200)/windowWidth;var X=(containerHeight+200)/windowHeight}else{var Z=windowWidth/containerWidth;var X=windowHeight/containerHeight}if(X>Z){imageWidth=Math.round(a*(1/X));imageHeight=Math.round(Y*(1/X))}else{imageWidth=Math.round(a*(1/Z));imageHeight=Math.round(Y*(1/Z))}contentHeight=imageHeight+parseFloat($("div.pictureHolder .details").height())+parseFloat($("div.pictureHolder .details").css("margin-top"))+parseFloat($("div.pictureHolder .details").css("margin-bottom"));contentWidth=imageWidth;containerHeight=imageHeight+parseFloat($("div.prettyPhotoTitle").height())+parseFloat($("div.pictureHolder .top").height())+parseFloat($("div.pictureHolder .bottom").height());containerWidth=imageWidth+S.padding;$("div.pictureHolder .details").width(contentWidth);$("div.pictureHolder .details p.description").width(contentWidth-parseFloat($("div.pictureHolder a.close").css("width")))}return{width:imageWidth,height:imageHeight,containerHeight:containerHeight,containerWidth:containerWidth,contentHeight:contentHeight,contentWidth:contentWidth,resized:hasBeenResized}}function A(){if($("div.pictureHolder").size()>0){var X=E();if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth}else{windowHeight=$(window).height();windowWidth=$(window).width()}if(C){projectedTop=(windowHeight/2)+X.scrollTop-($("div.pictureHolder").height()/2);if(projectedTop<0){projectedTop=0+$("div.prettyPhotoTitle").height()}$("div.pictureHolder").css({top:projectedTop,left:(windowWidth/2)+X.scrollLeft-($("div.pictureHolder").width()/2)});$("div.prettyPhotoTitle").css({top:$("div.pictureHolder").offset().top-$("div.prettyPhotoTitle").height(),left:$("div.pictureHolder").offset().left+(S.padding/2)})}}}function D(){if(O){$("div.pictureHolder .hoverContainer").fadeIn(S.animationSpeed)}$("div.pictureHolder .details").fadeIn(S.animationSpeed);R()}function R(){if(S.showTitle&&G){$("div.prettyPhotoTitle").css({top:$("div.pictureHolder").offset().top,left:$("div.pictureHolder").offset().left+(S.padding/2),display:"block"});$("div.prettyPhotoTitle div.prettyPhotoTitleContent").css("width","auto");if($("div.prettyPhotoTitle").width()>$("div.pictureHolder").width()){$("div.prettyPhotoTitle div.prettyPhotoTitleContent").css("width",$("div.pictureHolder").width()-(S.padding*2))}else{$("div.prettyPhotoTitle div.prettyPhotoTitleContent").css("width","")}$("div.prettyPhotoTitle").animate({top:($("div.pictureHolder").offset().top-22)},S.animationSpeed)}}function V(){$("div.prettyPhotoTitle").animate({top:($("div.pictureHolder").offset().top)},S.animationSpeed,function(){$(this).css("display","none")})}function U(){I();imgPreloader=new Image();nextImage=new Image();if(O){nextImage.src=$(L[W+1]).attr("href")}prevImage=new Image();if(O&&L[W-1]){prevImage.src=$(L[W-1]).attr("href")}$("div.pictureHolder .content").css("overflow","hidden");if(O){$("div.pictureHolder #fullResImage").attr("src",$(L[W]).attr("href"))}else{$("div.pictureHolder #fullResImage").attr("src",$(N).attr("href"))}imgPreloader.onload=function(){var X=M(imgPreloader.width,imgPreloader.height);imgPreloader.width=X.width;imgPreloader.height=X.height;setTimeout("showimage(imgPreloader.width,imgPreloader.height,"+X.containerWidth+","+X.containerHeight+","+X.contentHeight+","+X.contentWidth+","+X.resized+")",500)};(O)?imgPreloader.src=$(L[W]).attr("href"):imgPreloader.src=$(N).attr("href")}function E(){scrollTop=window.pageYOffset||document.documentElement.scrollTop||0;scrollLeft=window.pageXOffset||document.documentElement.scrollLeft||0;return{scrollTop:scrollTop,scrollLeft:scrollLeft}}function Q(){$("div.prettyPhotoOverlay").css({height:$(document).height(),width:$(window).width()})}function F(){flashParams=$(N).attr("rel").split(";");$(flashParams).each(function(X){if(flashParams[X].indexOf("width")>=0){flashWidth=flashParams[X].substring(flashParams[X].indexOf("width")+6,flashParams[X].length)}if(flashParams[X].indexOf("height")>=0){flashHeight=flashParams[X].substring(flashParams[X].indexOf("height")+7,flashParams[X].length)}if(flashParams[X].indexOf("flashvars")>=0){flashVars=flashParams[X].substring(flashParams[X].indexOf("flashvars")+10,flashParams[X].length)}});$(".pictureHolder #fullResImageContainer").append('<embed width="'+flashWidth+'" height="'+flashHeight+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="opaque" name="prettyFlash" flashvars="'+flashVars+'" allowscriptaccess="always" bgcolor="#FFFFFF" quality="high" src="'+$(N).attr("href")+'"/>');$("#fullResImage").hide();contentHeight=parseFloat(flashHeight)+parseFloat($("div.pictureHolder .details").height())+parseFloat($("div.pictureHolder .details").css("margin-top"))+parseFloat($("div.pictureHolder .details").css("margin-bottom"));contentWidth=parseFloat(flashWidth)+parseFloat($("div.pictureHolder .details").width())+parseFloat($("div.pictureHolder .details").css("margin-left"))+parseFloat($("div.pictureHolder .details").css("margin-right"));containerHeight=contentHeight+parseFloat($("div.pictureHolder .top").height())+parseFloat($("div.pictureHolder .bottom").height());containerWidth=parseFloat(flashWidth)+parseFloat($("div.pictureHolder .content").css("padding-left"))+parseFloat($("div.pictureHolder .content").css("padding-right"))+S.padding;setTimeout("showimage("+flashWidth+","+flashHeight+","+containerWidth+","+containerHeight+","+contentHeight+","+contentWidth+")",500)}function T(){backgroundDiv="<div class='prettyPhotoOverlay'></div>";$("body").append(backgroundDiv);$("div.prettyPhotoOverlay").css("height",$(document).height()).bind("click",function(){J()});pictureHolder='<div class="pictureHolder"><div class="top"><div class="left"></div><div class="middle"></div><div class="right"></div></div><div class="content"><a href="#" class="expand" title="Expand the image">Expand</a><div class="loaderIcon"></div><div class="hoverContainer"><a class="next" href="#">next</a><a class="previous" href="#">previous</a></div><div id="fullResImageContainer"><img id="fullResImage" src="" /></div><div class="details clearfix"><a class="close" href="#">Close</a><p class="description"></p><div class="nav"><a href="#" class="arrow_previous">Previous</a><p class="currentTextHolder">0'+S.counter_separator_label+'0</p><a href="#" class="arrow_next">Next</a></div></div></div><div class="bottom"><div class="left"></div><div class="middle"></div><div class="right"></div></div></div>';titleHolder='<div class="prettyPhotoTitle"><div class="prettyPhotoTitleLeft"></div><div class="prettyPhotoTitleContent"></div><div class="prettyPhotoTitleRight"></div></div>';$("body").append(pictureHolder).append(titleHolder);$(".pictureHolder,.titleHolder").css({opacity:0});$("a.close").bind("click",function(){J();return false});$("a.expand").bind("click",function(){if($(this).hasClass("expand")){$(this).removeClass("expand").addClass("contract");C=false}else{$(this).removeClass("contract").addClass("expand");C=true}V();$("div.pictureHolder .hoverContainer,div.pictureHolder #fullResImageContainer").fadeOut(S.animationSpeed);$("div.pictureHolder .details").fadeOut(S.animationSpeed,function(){U()});return false});$(".pictureHolder .previous,.pictureHolder .arrow_previous").bind("click",function(){K("previous");return false});$(".pictureHolder .next,.pictureHolder .arrow_next").bind("click",function(){K("next");return false});$(".hoverContainer").css({"margin-left":S.padding/2});if(!O){$(".hoverContainer,.nav").hide()}if($.browser.msie&&$.browser.version==6){$("select").css("visibility","hidden")}$("div.prettyPhotoOverlay").css("opacity",0).fadeTo(S.animationSpeed,S.opacity,function(){$("div.pictureHolder").css("opacity",0).fadeIn(S.animationSpeed,function(){$("div.pictureHolder").attr("style","left:"+$("div.pictureHolder").css("left")+";top:"+$("div.pictureHolder").css("top")+";")})})}};