$.fn.prettyPhoto=function(_1){
var _2=false;
var _3=0;
var _4=0;
var _5=0;
var _6=false;
var _7=0;
var _8=true;
var _9=[];
$(window).scroll(function(){
_centerPicture();
});
$(window).resize(function(){
_centerPicture();
_resizeOverlay();
});
$(document).keyup(function(e){
switch(e.keyCode){
case 37:
if(_4==1){
return;
}
changePicture("previous");
break;
case 39:
if(_4==_3){
return;
}
changePicture("next");
break;
case 27:
close();
break;
}
});
_1=jQuery.extend({animationSpeed:"normal",padding:40,opacity:0.35,showTitle:true,allowresize:true,counter_separator_label:"/"},_1);
$(this).each(function(){
_9[_9.length]=this;
$(this).bind("click",function(){
open(this);
return false;
});
});
function open(el){
_7=$(el);
theRel=$(_7).attr("rel");
galleryRegExp=/\[(?:.*)\]/;
theGallery=galleryRegExp.exec(theRel);
contentType="image";
if($(_7).attr("href").indexOf(".swf")>0){
_6=false;
contentType="flash";
}
_2=false;
_3=0;
for(i=0;i<_9.length;i++){
if($(_9[i]).attr("rel").indexOf(theGallery)!=-1){
_3++;
if(_3>1){
_2=true;
}
if($(_9[i]).attr("href")==$(el).attr("href")){
_4=_3;
_5=i;
}
}
}
_buildOverlay(_2);
$("div.pictureHolder p.currentTextHolder").text(_4+_1.counter_separator_label+_3);
_centerPicture();
$("div.pictureHolder #fullResImageContainer").hide();
$(".loaderIcon").show();
(contentType=="image")?_preload():_writeFlash();
};
showimage=function(_c,_d,_e,_f,_10,_11,_12){
$(".loaderIcon").hide();
var _13=_getScroll();
if($.browser.opera){
windowHeight=window.innerHeight;
windowWidth=window.innerWidth;
}else{
windowHeight=$(window).height();
windowWidth=$(window).width();
}
$("div.pictureHolder .content").animate({"height":_10,"width":_e},_1.animationSpeed);
projectedTop=_13["scrollTop"]+((windowHeight/2)-(_f/2));
if(projectedTop<0){
projectedTop=0+$("div.prettyPhotoTitle").height();
}
$("div.pictureHolder").animate({"top":projectedTop,"left":((windowWidth/2)-(_e/2)),"width":_e},_1.animationSpeed,function(){
$("#fullResImage").attr({"width":_c,"height":_d});
$("div.pictureHolder").width(_e);
$("div.pictureHolder .hoverContainer").height(_d).width(_c);
_shownav();
$("div.pictureHolder #fullResImageContainer").fadeIn(_1.animationSpeed);
if(_12){
$("a.expand,a.contract").fadeIn(_1.animationSpeed);
}
});
};
function changePicture(_14){
if(_14=="previous"){
_5--;
_4--;
}else{
_5++;
_4++;
}
if(!_8){
_8=true;
}
$("div.pictureHolder .hoverContainer,div.pictureHolder .details").fadeOut(_1.animationSpeed);
$("div.pictureHolder #fullResImageContainer").fadeOut(_1.animationSpeed,function(){
$(".loaderIcon").show();
_preload();
});
_hideTitle();
$("a.expand,a.contract").fadeOut(_1.animationSpeed,function(){
$(this).removeClass("contract").addClass("expand");
});
};
function close(){
$("div.pictureHolder,div.prettyPhotoTitle").fadeOut(_1.animationSpeed,function(){
$("div.prettyPhotoOverlay").fadeOut(_1.animationSpeed,function(){
$("div.prettyPhotoOverlay,div.pictureHolder,div.prettyPhotoTitle").remove();
if($.browser.msie&&$.browser.version==6){
$("select").css("visibility","visible");
}
});
});
};
function _checkPosition(){
if(_4==_3){
$("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(){
changePicture("next");
return false;
});
}
if(_4==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(){
changePicture("previous");
return false;
});
}
$("div.pictureHolder p.currentTextHolder").text(_4+_1.counter_separator_label+_3);
(_2)?$c=$(_9[_5]):$c=$(_7);
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")&&_1.showTitle){
_6=true;
$("div.prettyPhotoTitle .prettyPhotoTitleContent").html(unescape($c.find("img").attr("alt")));
}else{
_6=false;
}
};
function _fitToViewport(_15,_16){
hasBeenResized=false;
$("div.pictureHolder .details").width(_15);
$("div.pictureHolder .details p.description").width(_15-parseFloat($("div.pictureHolder a.close").css("width")));
contentHeight=_16+parseFloat($("div.pictureHolder .details").height())+parseFloat($("div.pictureHolder .details").css("margin-top"))+parseFloat($("div.pictureHolder .details").css("margin-bottom"));
contentWidth=_15;
containerHeight=_16+parseFloat($("div.prettyPhotoTitle").height())+parseFloat($("div.pictureHolder .top").height())+parseFloat($("div.pictureHolder .bottom").height());
containerWidth=_15+_1.padding;
imageWidth=_15;
imageHeight=_16;
if($.browser.opera){
windowHeight=window.innerHeight;
windowWidth=window.innerWidth;
}else{
windowHeight=$(window).height();
windowWidth=$(window).width();
}
if(((containerWidth>windowWidth)||(containerHeight>windowHeight))&&_8&&_1.allowresize){
hasBeenResized=true;
if((containerWidth>windowWidth)&&(containerHeight>windowHeight)){
var _17=(containerWidth+200)/windowWidth;
var _18=(containerHeight+200)/windowHeight;
}else{
var _17=windowWidth/containerWidth;
var _18=windowHeight/containerHeight;
}
if(_18>_17){
imageWidth=Math.round(_15*(1/_18));
imageHeight=Math.round(_16*(1/_18));
}else{
imageWidth=Math.round(_15*(1/_17));
imageHeight=Math.round(_16*(1/_17));
}
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+_1.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 _centerPicture(){
if($("div.pictureHolder").size()>0){
var _19=_getScroll();
if($.browser.opera){
windowHeight=window.innerHeight;
windowWidth=window.innerWidth;
}else{
windowHeight=$(window).height();
windowWidth=$(window).width();
}
if(_8){
projectedTop=(windowHeight/2)+_19["scrollTop"]-($("div.pictureHolder").height()/2);
if(projectedTop<0){
projectedTop=0+$("div.prettyPhotoTitle").height();
}
$("div.pictureHolder").css({"top":projectedTop,"left":(windowWidth/2)+_19["scrollLeft"]-($("div.pictureHolder").width()/2)});
$("div.prettyPhotoTitle").css({"top":$("div.pictureHolder").offset().top-$("div.prettyPhotoTitle").height(),"left":$("div.pictureHolder").offset().left+(_1.padding/2)});
}
}
};
function _shownav(){
if(_2){
$("div.pictureHolder .hoverContainer").fadeIn(_1.animationSpeed);
}
$("div.pictureHolder .details").fadeIn(_1.animationSpeed);
_showTitle();
};
function _showTitle(){
if(_1.showTitle&&_6){
$("div.prettyPhotoTitle").css({"top":$("div.pictureHolder").offset().top,"left":$("div.pictureHolder").offset().left+(_1.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()-(_1.padding*2));
}else{
$("div.prettyPhotoTitle div.prettyPhotoTitleContent").css("width","");
}
$("div.prettyPhotoTitle").animate({"top":($("div.pictureHolder").offset().top-22)},_1.animationSpeed);
}
};
function _hideTitle(){
$("div.prettyPhotoTitle").animate({"top":($("div.pictureHolder").offset().top)},_1.animationSpeed,function(){
$(this).css("display","none");
});
};
function _preload(){
_checkPosition();
imgPreloader=new Image();
nextImage=new Image();
if(_2){
nextImage.src=$(_9[_5+1]).attr("href");
}
prevImage=new Image();
if(_2&&_9[_5-1]){
prevImage.src=$(_9[_5-1]).attr("href");
}
$("div.pictureHolder .content").css("overflow","hidden");
if(_2){
$("div.pictureHolder #fullResImage").attr("src",$(_9[_5]).attr("href"));
}else{
$("div.pictureHolder #fullResImage").attr("src",$(_7).attr("href"));
}
imgPreloader.onload=function(){
var _1a=_fitToViewport(imgPreloader.width,imgPreloader.height);
imgPreloader.width=_1a["width"];
imgPreloader.height=_1a["height"];
setTimeout("showimage(imgPreloader.width,imgPreloader.height,"+_1a["containerWidth"]+","+_1a["containerHeight"]+","+_1a["contentHeight"]+","+_1a["contentWidth"]+","+_1a["resized"]+")",500);
};
(_2)?imgPreloader.src=$(_9[_5]).attr("href"):imgPreloader.src=$(_7).attr("href");
};
function _getScroll(){
scrollTop=window.pageYOffset||document.documentElement.scrollTop||0;
scrollLeft=window.pageXOffset||document.documentElement.scrollLeft||0;
return {scrollTop:scrollTop,scrollLeft:scrollLeft};
};
function _resizeOverlay(){
$("div.prettyPhotoOverlay").css({"height":$(document).height(),"width":$(window).width()});
};
function _writeFlash(){
flashParams=$(_7).attr("rel").split(";");
$(flashParams).each(function(i){
if(flashParams[i].indexOf("width")>=0){
flashWidth=flashParams[i].substring(flashParams[i].indexOf("width")+6,flashParams[i].length);
}
if(flashParams[i].indexOf("height")>=0){
flashHeight=flashParams[i].substring(flashParams[i].indexOf("height")+7,flashParams[i].length);
}
if(flashParams[i].indexOf("flashvars")>=0){
flashVars=flashParams[i].substring(flashParams[i].indexOf("flashvars")+10,flashParams[i].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=\""+$(_7).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"))+_1.padding;
setTimeout("showimage("+flashWidth+","+flashHeight+","+containerWidth+","+containerHeight+","+contentHeight+","+contentWidth+")",500);
};
function _buildOverlay(){
backgroundDiv="<div class='prettyPhotoOverlay'></div>";
$("body").append(backgroundDiv);
$("div.prettyPhotoOverlay").css("height",$(document).height()).bind("click",function(){
close();
});
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=\"javascript: void(0)\" class=\"expand\" title=\"Expand the image\">Expand</a><div class=\"loaderIcon\"></div><div class=\"hoverContainer\"><a class=\"next\" href=\"javascript: void(0)\">next</a><a class=\"previous\" href=\"javascript: void(0)\">previous</a></div><div id=\"fullResImageContainer\"><img id=\"fullResImage\" src=\"\" /></div><div class=\"details clearfix\"><a class=\"close\" href=\"javascript: void(0)\">Close</a><p class=\"description\"></p><div class=\"nav\"><a href=\"javascript: void(0)\" class=\"arrow_previous\">Previous</a><p class=\"currentTextHolder\">0"+_1.counter_separator_label+"0</p><a href=\"javascript: void(0)\" 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(){
close();
return false;
});
$("a.expand").bind("click",function(){
if($(this).hasClass("expand")){
$(this).removeClass("expand").addClass("contract");
_8=false;
}else{
$(this).removeClass("contract").addClass("expand");
_8=true;
}
_hideTitle();
$("div.pictureHolder .hoverContainer,div.pictureHolder #fullResImageContainer").fadeOut(_1.animationSpeed);
$("div.pictureHolder .details").fadeOut(_1.animationSpeed,function(){
_preload();
});
return false;
});
$(".pictureHolder .previous,.pictureHolder .arrow_previous").bind("click",function(){
changePicture("previous");
return false;
});
$(".pictureHolder .next,.pictureHolder .arrow_next").bind("click",function(){
changePicture("next");
return false;
});
$(".hoverContainer").css({"margin-left":_1.padding/2});
if(!_2){
$(".hoverContainer,.nav").hide();
}
if($.browser.msie&&$.browser.version==6){
$("select").css("visibility","hidden");
}
$("div.prettyPhotoOverlay").css("opacity",0).fadeTo(_1.animationSpeed,_1.opacity,function(){
$("div.pictureHolder").css("opacity",0).fadeIn(_1.animationSpeed,function(){
$("div.pictureHolder").attr("style","left:"+$("div.pictureHolder").css("left")+";top:"+$("div.pictureHolder").css("top")+";");
});
});
};
};

