(function(a){jQuery.fn.maxImage=function(d){var u={show:false,location:"before",message:"Original: ([w]w x [h]h)"};var n=jQuery.extend({wait:true,imageArray:[],maxFollows:"both",verticalOffset:0,horizontalOffset:0,leftSpace:0,topSpace:0,rightSpace:0,bottomSpace:0,overflow:"hidden",position:"absolute",isBackground:false,zIndex:-1,verticalAlign:"center",horizontalAlign:"center",maxAtOrigImageSize:false,slideShow:false,slideDelay:5,slideShowTitle:true,loaderClass:"loader",resizeMsg:u},d);n.resizeMsg=jQuery.extend(u,d.resizeMsg);var f=this;function x(){t(this,f);return false}function t(z,y){if(n.slideShow){s(y)}else{if(n.isBackground){Background._setup_background(z)}else{Others._setup_others(z,n)}}}Others={_setup_others:function(z,y){$this=a(z);a(window).load(function(){c($this);m($this);w($this);Others._configure_css(z,y);a(window).resize(function(){m($this);w($this)})})},_configure_css:function(z,y){if(y.position=="absolute"){a(z).css({overflow:"hidden",left:y.leftSpace,top:y.topSpace,position:"absolute"});if(y.verticalAlign=="bottom"){a(z).css({bottom:y.bottomSpace})}if(y.horizontalAlign=="right"){a(z).css({right:y.rightSpace})}}else{a(z).css({"margin-top":y.topSpace,"margin-right":y.rightSpace,"margin-bottom":y.bottomSpace,"margin-left":y.leftSpace,position:y.position})}}};Background={_setup_background:function(y){$this=a(y);$this.hide();Background._configure_css(y);a(window).load(function(){c($this);m($this);w($this);$this.show();a(window).resize(function(){m($this);w($this)})})},_configure_css:function(y){a(y).css({"z-index":n.zIndex});if(n.position=="absolute"){a(y).css({overflow:"hidden",left:n.leftSpace,top:n.topSpace,position:"absolute"});a("html").css({"overflow-y":n.overflow});if(n.verticalAlign=="bottom"){a(y).css({bottom:n.bottomSpace})}if(n.horizontalAlign=="right"){a(y).css({right:n.rightSpace})}}else{a(y).css({"margin-top":n.topSpace,"margin-right":n.rightSpace,"margin-bottom":n.bottomSpace,"margin-left":n.leftSpace,position:n.position})}}};function s(z){l(z);n.imageArray.length=0;if(z.length==1){n.imageArray.push(new Array(objClicked.getAttribute("src"),objClicked.getAttribute("title")))}else{for(var y=0;y<z.length;y++){n.imageArray.push(new Array(z[y].getAttribute("src"),z[y].getAttribute("title")));a(z[y]).attr("original",a(z[y]).attr("src")).attr("src","")}}h();v(0)}function l(){for(var y=0;y<f.length;y++){a(f[y]).addClass("slides slide-"+y).after('<div class="slideTitle">'+a(f[y]).attr("title")+"</div>")}a(".slideTitle").hide().css({padding:"10px",background:"#e0e0e0",position:"absolute",bottom:"0",right:"5%",opacity:"0.8"})}function v(A){var z=A;var y=new Image();y.onload=function(){a(".slide-"+z).attr("src",n.imageArray[z][0]);c(a(".slide-"+z));m(a(".slide-"+z));w(a(".slide-"+z));a(window).resize(function(){m(a(".slide-"+(z)));w(a(".slide-"+z))});if(z==0){k()}if(z<n.imageArray.length-1){v(z+1)}};y.src=n.imageArray[z][0]}function k(){var z=0;a("."+n.loaderClass).hide();a(".slide-"+z).css({"z-index":n.zIndex}).fadeIn();if(n.slideShowTitle){a(".slide-"+z).next(".slideTitle").css({"z-index":n.zIndex+1}).fadeIn()}var y=setInterval(function(){if(z<n.imageArray.length-1){z++;lastSlide=z-1}else{z=0;lastSlide=n.imageArray.length-1}a(".slide-"+lastSlide).css({"z-index":n.zIndex-1}).fadeOut("slow");a(".slide-"+z).css({"z-index":n.zIndex}).fadeIn("slow");if(n.slideShowTitle){b(z,lastSlide)}},(n.slideDelay*1000))}function h(){for(i=0;i<n.imageArray.length;i++){if(n.position=="absolute"){a(".slide-"+i).css({position:"absolute",overflow:"hidden"});a("html").css({"overflow-y":n.overflow});if(n.verticalAlign=="bottom"){a(".slide-"+i).css({bottom:n.bottomSpace})}else{a(".slide-"+i).css({top:n.topSpace})}if(n.horizontalAlign=="right"){a(".slide-"+i).css({right:n.rightSpace})}else{a(".slide-"+i).css({left:n.leftSpace})}}else{a(".slide-"+i).css({"margin-top":n.topSpace,"margin-right":n.rightSpace,"margin-bottom":n.bottomSpace,"margin-left":n.leftSpace,position:n.position})}a(".slide-"+i).next(".slideTitle").css({position:"absolute",bottom:0,right:"5%"})}}function b(z,y){a(".slide-"+y).next(".slideTitle").fadeOut();a(".slide-"+z).next(".slideTitle").fadeIn()}function w(C){$this=C;if(n.horizontalAlign=="center"){var z=a(window).width()-n.horizontalOffset;var B=-1*($this.width()-z)/2;a(C).css({left:B})}if(n.verticalAlign=="center"){var A=a(window).height()-n.verticalOffset;var y=-1*($this.height()-A)/2;a(C).css({top:y})}}function c(y){$this=y;$this.attr("origWidth",$this.width());$this.attr("origHeight",$this.height());$this.attr("ratio",p($this.width(),$this.height()))}function m(B){$this=B;var C=r($this.attr("origWidth"));var A=r($this.attr("origHeight"));var z=$this.attr("ratio");if(C==0||A==0){setTimeout(function(){c(B);m(B)},100);return}var y=[];y=j(C,A,z);$this.width(y[0]);$this.height(y[1]);g(C,A,B)}function g(B,z,A){if((r($this.width())!=B||r($this.height())!=z)&&n.resizeMsg.show){a(".maximage_resized").remove();n.resizeMsg.message=n.resizeMsg.message.replace("[w]",B).replace("[h]",z);var y='<div class="maximage_resized">'+n.resizeMsg.message+"</div>";if(n.resizeMsg.location.toLowerCase()=="before"){$this.before(y)}else{$this.after(y)}}}function j(C,B,z){var y=a(window).width()-n.horizontalOffset;var A=a(window).height()-n.verticalOffset;if(!n.isBackground){if(n.maxFollows=="both"){e(y,z);if(height>A){q(A,z)}}else{if(n.maxFollows=="width"){e(y,z)}else{if(n.maxFollows=="height"){q(A,z)}}}}else{width=y+40;height=width/z;if(height<A){height=A-(n.topSpace+n.bottomSpace);width=height*z}}if(n.maxAtOrigImageSize&&width>C){arrayImageSize=new Array(C,B)}else{arrayImageSize=new Array(width,height)}return arrayImageSize}function q(z,y){height=z-(n.topSpace+n.bottomSpace);width=height*y}function e(y,z){width=y-(n.leftSpace+n.rightSpace);height=width/z}function p(A,y){A=r(A);y=r(y);var z=A/y;z=z.toFixed(2);return z}function r(y){last=parseInt(y);return last}function o(y){if(window.console&&window.console.log){window.console.log(y)}}return this.each(x)}})(jQuery);
