(function(A){if(!A.fn.c1){A.fn.c1=function(C,B){if(this.c1[C]){return this.c1[C].call(this,B)}return this}}A.fn.c1.gallery=function(D){D=A.extend({selector:".c1-gallery",speed:"normal",animation:"fade",zIndex:1},D);function G(P){var N=(D.position!=null?A(B.images[D.position]):null);var M=A(B.images[P]);if(M==null){return }if(D.animation=="slide"){var O=A("ul",B.scroll);var L=O.offset().left-M.offset().left;O.animate({left:L+"px"},D.speed)}else{if(N){N.css("z-index",D.zIndex)}M.css("z-index",D.zIndex+1).fadeIn(D.speed,function(){if(N){N.hide()}})}if(C.images[D.position]){A(C.images[D.position]).removeClass(D.selector.replace(".","")+"-thumb-active")}if(C.images[P]){var J=A(C.images[P]);J.addClass(D.selector.replace(".","")+"-thumb-active");var Q=C.scroll.offset();Q.right=Q.left+C.scroll.width();var I=J.offset();I.right=I.left+J.width();var K=0;if(I.left<Q.left){K=Q.left-I.left}else{if(I.right>Q.right){K=Q.right-I.right}}var L=parseInt(A("ul",C.scroll).css("left"));L=(isNaN(L)?0:L)+K;if(K!=0){A("ul",C.scroll).animate({left:L+"px"},D.speed)}}D.position=P;A("a",B.prev)[P==0?"hide":"show"]();A("a",B.next)[P>=(B.images.length-1)?"hide":"show"]()}function H(K){var I=A("ul",C.scroll);var J=parseInt(I.css("left"));J=Math.floor((isNaN(J)?0:J)-(C.scrollWidth/2*K));if(J<C.bounds.right){J=C.bounds.right}else{if(J>C.bounds.left){J=C.bounds.left}}I.animate({left:J+"px"},"slow");A("a",C.prev)[J==C.bounds.left?"hide":"show"]();A("a",C.next)[J==C.bounds.right?"hide":"show"]()}function E(){var J=A("ul",B.scroll);var I=0;if(D.animation=="slide"){var K=0;B.images.each(function(){K+=A(this).width()});I=J.width(K).height()}else{B.images.each(function(){var L=A(this).height();if(L>I){I=L}})}B.scrollWidth=B.scroll.width();if(B.scroll.height()==0){B.scroll.height(I)}B.prev.append('<a href="#" title="View previous image" style="display:none"></a>').find("a").width(B.prev.width()).height(B.prev.height()).click(function(){G(D.position-1);return false});B.next.append('<a href="#" title="View next image" style="display:none"></a>').find("a").width(B.next.width()).height(B.next.height()).click(function(){G(D.position+1);return false});if(B.images.length>1){A("a",B.next).fadeIn(D.speed)}}function F(){if(C.images.length==0){return }var J=A("ul",C.scroll);var L=0;C.images.each(function(){L+=A(this).width()});J.width(L);C.scrollWidth=C.scroll.width();if(C.scroll.height()==0){C.scroll.height(J.height())}var I=J.offset();var K=A("li:first-child",J).offset();C.bounds={left:I.left-K.left};C.bounds.right=C.bounds.left-L+C.scrollWidth;C.prev.append('<a href="#" title="Scroll thumbnails to the left"></a>').find("a").css("display","none").width(C.prev.width()).height(C.next.height()).click(function(){H(-1);return false}).fadeIn(D.speed);C.next.append('<a href="#" title="Scroll thumbnails to the right"></a>').find("a").css("display","none").width(C.next.width()).height(C.next.height()).click(function(){H(1);return false});if(C.images.length>1){A("a",C.next).fadeIn(D.speed)}}var B={images:A(D.selector+"-image",this),next:A(D.selector+"-image-next",this),prev:A(D.selector+"-image-prev",this),scroll:A(D.selector+"-image-scroll",this)};E();var C={images:A(D.selector+"-thumb",this),next:A(D.selector+"-thumb-next",this),prev:A(D.selector+"-thumb-prev",this),scroll:A(D.selector+"-thumb-scroll",this)};F();D.position=null;G(0);A(D.selector+"-thumb a",this).each(function(I){A(this).click(function(){G(I);return false})});return this}})(jQuery);