var $fw=$fw||jQuery.noConflict();(function(a){a.fn.fwShowcase=function(b){var c={};return this.each(function(){var n=a(this),t=n.attr("id"),g=":not(.fwShowcase_cloned, .fwShowcase_empty)",D=a.extend({overlayBg:"",overlayOp:0.5,galleryBg:"",galleryTxtColor:"#000",borderColor:"",borderWidth:0,padding:0,startW:100,startH:100,captions:false,captionHeight:0,fontFamily:"Helvetica,Arial,sans-serif",roll:"",controls:true,showInfo:true,autohideControls:true,autohideInfo:true,galleryCss:{},imageCss:{},dir:0,thumbs:true,fade:100,playing:false},b);c[t]={curImage:null,curPage:1,duration:null,total:n.find("li").length,s:D};function q(){if(a(n).outerWidth()==0){setTimeout(q,100)}else{a(n).trigger("visible")}}q();if(c[t].s.slideshow){if(c[t].s.thumbs){var w=n.find(".fwShowcase_wrapper"),x=n.find(".fwShowcase_outer"),r=n.find(".fwShowcase_inner"),f=r.find(".fwShowcase_thumbs"),i=f.find("li"),k=c[t].s.itemWidth,z=c[t].s.itemHeight,E=c[t].s.outerHeight,h=c[t].s.outerWidth;visible=(c[t].s.dir?E/z:h/k),pages=Math.ceil(i.length/visible);x.css({overflow:"hidden"}).before('<a href="" class="fwShowcase_prev"></a>').after('<a href="" class="fwShowcase_next"></a><div class="fwShowcase_clearer"></div>');if(!c[t].s.dir){r.css({width:parseInt(r.css("width"))+(h*2)});w.find("> .fwShowcase_prev, > .fwShowcase_next").css({width:27,height:27,display:"block","float":"left",marginTop:(E-27)/2,marginRight:10,background:"url("+c[t].s.controlsPath+") 0px 0px no-repeat"});w.find("> .fwShowcase_next").css({marginLeft:10,marginRight:0,backgroundPosition:"-55px 0px"});n.find(".fwShowcase_clearer").css({clear:"both"})}else{x.css({height:E});r.css({height:(k-c[t].s.padding)+(h*2)});w.find("> .fwShowcase_prev, > .fwShowcase_next").css({width:27,height:27,display:"block",margin:"auto",marginBottom:10,background:"url("+c[t].s.controlsPath+") 0px -27px no-repeat"});w.find("> .fwShowcase_next").css({marginTop:10,marginBottom:0,backgroundPosition:"-55px -27px"})}function o(K,J){return new Array(J+1).join(K)}if((i.length%visible)!=0){i.filter(":last").after(o('<li class="fwShowcase_empty" />',visible-(i.length%visible)));i=f.find("li")}i.filter(":first").before(i.slice(-visible).clone().addClass("fwShowcase_cloned"));i.filter(":last").after(i.slice(0,visible).clone().addClass("fwShowcase_cloned"));function m(){if(!c[t].s.dir){x.scrollLeft(h)}else{x.scrollTop(E)}}if(!a(n).is(":visible")){a(n).bind("visible",m)}else{m()}function I(L){if(L==c[t].curPage){return}var K=L<c[t].curPage?-1:1,M=Math.abs(c[t].curPage-L),J=(!c[t].s.dir?h:E)*M*K;n.find(".fwShowcase_outer:not(:animated)").animate({scrollLeft:"+="+(!c[t].s.dir?J:0),scrollTop:"+="+(!c[t].s.dir?0:J)},500,function(){if(L==0){if(!c[t].s.dir){x.scrollLeft(h*pages)}else{x.scrollTop(E*pages)}L=pages}else{if(L>pages){if(!c[t].s.dir){x.scrollLeft(h)}else{x.scrollTop(E)}L=1}}c[t].curPage=L})}n.find("a.fwShowcase_prev").click(function(){I(c[t].curPage-1);return false});n.find("a.fwShowcase_next").click(function(){I(c[t].curPage+1);return false})}n.find(".fwShowcase_slideshow > .fwShowcase_main").append('<div class="fwShowcase_info"></div><div class="fwShowcase_controls"><div class="fwShowcase_prev"><a href="" title="'+c[t].s.prevTxt+'"></a></div><div class="fwShowcase_play"><a href="" title="'+c[t].s.playTxt+'"></a></div><div class="fwShowcase_next"><a href="" title="'+c[t].s.nextTxt+'"></a></div>')}else{a("body:not(:has(#fwShowcase))").append('<div id="fwShowcase_overlay"></div>').append('<div id="fwShowcase"><div id="fwShowcase_image"><a class="fwShowcase_prev" title="'+c[t].s.prevTxt+'" href=""></a><a class="fwShowcase_next" title="'+c[t].s.nextTxt+'" href=""></a></div><div class="fwShowcase_title"></div><div class="fwShowcase_info"></div><div class="fwShowcase_controls"><div class="fwShowcase_prev"><a href="" title="'+c[t].s.prevTxt+'"></a></div><div class="fwShowcase_play"><a href="" title="'+c[t].s.playTxt+'"></a></div><div class="fwShowcase_next"><a href="" title="'+c[t].s.nextTxt+'"></a></div><div class="fwShowcase_close"><a href="" title="'+c[t].s.closeTxt+'"></a></div></div></div>')}c[t].$info=(c[t].s.slideshow?n.find(".fwShowcase_info"):a("#fwShowcase > .fwShowcase_info"));c[t].$controls=(c[t].s.slideshow?n.find(".fwShowcase_controls"):a("#fwShowcase > .fwShowcase_controls"));c[t].$prev=(c[t].s.slideshow?c[t].$controls.find(".fwShowcase_prev > a"):c[t].$controls.find(".fwShowcase_prev > a").add(a("a.fwShowcase_prev")));c[t].$next=(c[t].s.slideshow?c[t].$controls.find(".fwShowcase_next > a"):c[t].$controls.find(".fwShowcase_next > a").add(a("a.fwShowcase_next")));c[t].$play=(c[t].s.slideshow?c[t].$controls.find(".fwShowcase_play > a"):c[t].$controls.find(".fwShowcase_play > a"));c[t].$close=c[t].$controls.find(".fwShowcase_close > a");c[t].$title=(c[t].s.slideshow?n.find(".fwShowcase_title"):a("#fwShowcase > .fwShowcase_title"));c[t].$caption=(c[t].s.slideshow?n.find(".fwShowcase_caption"):a("#fwShowcase > .fwShowcase_caption"));c[t].$list=f||n.find("ul");c[t].$usableItems=c[t].$list.find("li:not(.fwShowcase_empty, .fwShowcase_cloned)");c[t].$images=c[t].$usableItems.find("> a");c[t].$viewer=(c[t].s.slideshow?a(".fwShowcase_main"):a("#fwShowcase"));c[t].$galleryViewer=a("#fwShowcase");c[t].$overlay=a("#fwShowcase_overlay");if(c[t].s.slideshow){if(!a(n).is(":visible")){a(n).bind("visible",function(){c[t].curImage=c[t].$usableItems.first();a(window).load(function(){F()});v()})}else{c[t].curImage=c[t].$usableItems.first();a(window).load(function(){F()});v()}H();c[t].$controls.css({bottom:(7+c[t].s.padding+c[t].s.captionHeight),right:(7+c[t].s.padding)});c[t].$info.css({top:c[t].s.padding,right:c[t].s.padding});if(!c[t].s.controls||c[t].s.autohideControls){c[t].$controls.hide()}}else{a(window).resize(G).scroll(G)}a(c[t].$title).add(c[t].$caption).css({"text-overflow":"ellipsis"});c[t].$info.css({opacity:0.5});if(c[t].s.showInfo){c[t].$info.text("1 / "+c[t].total);if(c[t].s.autohideInfo){c[t].$info.hide()}}else{c[t].$info.hide()}if(a.browser.msie&&a.browser.version=="6.0"){c[t].$usableItems.mouseenter(function(){a(this).toggleClass("hover")}).mouseleave(function(){a(this).toggleClass("hover")})}c[t].$images.click(function(){if(c[t].s.slideshow){e(a(this).parent())}else{c[t].$controls.css({bottom:(7+c[t].s.padding+c[t].s.captionHeight),right:(7+c[t].s.padding)});c[t].$info.css({top:c[t].s.padding,right:c[t].s.padding});B(this)}return false});function p(){if(c[t].s.autohideInfo){c[t].$info.show()}if(c[t].s.autohideControls){c[t].$controls.show()}}function A(){if(c[t].s.autohideInfo){c[t].$info.add(c[t].s.autohideControls?c[t].$controls:null).hide()}else{if(c[t].s.autohideControls){c[t].$controls.hide()}}}function v(){if(!c[t].s.slideshow){a(c[t].$overlay).add(c[t].$close).click(C)}c[t].$prev.click(u);c[t].$next.click(y);c[t].$play.click(F);if(c[t].s.autohideControls||c[t].s.autohideInfo){c[t].$viewer.hover(p,A)}a(document).keydown(function(J){if(J.which==27&&!c[t].s.slideshow){C()}else{if(J.which==32){return F()}else{if(J.which==37){return u()}else{if(J.which==39){return y()}}}}})}function s(){c[t].$overlay.add(c[t].$close).add(c[t].$prev).add(c[t].$next).add(c[t].$play).unbind("click");c[t].$viewer.unbind();a(document).unbind("keydown")}function F(){if(!c[t].s.playing){c[t].duration=setInterval(y,c[t].s.duration*1000);c[t].$play.css({backgroundPosition:"-27px -27px"})}else{clearInterval(c[t].duration);c[t].$play.css({backgroundPosition:"-27px 0px"})}c[t].s.playing=!c[t].s.playing;return false}function l(){if(c[t].s.playing){clearInterval(c[t].duration);c[t].duration=setInterval(y,c[t].s.duration*1000)}}function H(){if(!c[t].$usableItems.index(c[t].curImage)){a("<img />").attr("src",a(c[t].curImage).next(g).find("> a").attr("href"));a("<img />").attr("src",c[t].$usableItems.last().find("> a").attr("href"))}else{if(c[t].$usableItems.index(c[t].curImage)==(c[t].total-1)){a("<img />").attr("src",c[t].$usableItems.first().find("> a").attr("href"));a("<img />").attr("src",a(c[t].curImage).prev(g).find("> a").attr("href"))}else{a("<img />").attr("src",a(c[t].curImage).next(g).find("> a").attr("href"));a("<img />").attr("src",a(c[t].curImage).prev(g).find("> a").attr("href"))}}}function u(){try{if(c[t].s.slideshow){e(a(c[t].curImage).prev(g))}else{d(a(c[t].curImage).prev())}}catch(J){if(c[t].s.slideshow){e(c[t].$usableItems.last())}else{d(c[t].$usableItems.last())}}return false}function y(){try{c[t].s.slideshow?e(a(c[t].curImage).next(g)):d(a(c[t].curImage).next())}catch(J){c[t].s.slideshow?e(c[t].$usableItems.first()):d(c[t].$usableItems.first())}return false}function G(){if(c[t].curImage===null){return}var K=c[t].$viewer.width(),N=c[t].$viewer.height(),J=(a(window).width()/2+a(window).scrollLeft()),M=(a(window).height()/2+a(window).scrollTop()),L=-(N/2),O=-(K/2);if(M+L<0){M=L=0}if(J+O<0){J=O=0}c[t].$viewer.css({top:M,marginTop:L});c[t].$viewer.css({left:J,marginLeft:O});c[t].$overlay.css({height:a(document).height(),width:a(document).width()})}function C(){c[t].$overlay.stop().hide();c[t].$viewer.stop().hide().removeClass();c[t].$controls.hide();c[t].$viewer.find("img").empty();c[t].$title.empty();c[t].s.playing=false;clearInterval(c[t].duration);c[t].$play.css({backgroundPosition:"-27px 0px"});s();c[t].curImage=null;return false}function j(K){var J=n.height()-(c[t].s.dir?0:(c[t].s.thumbs?w.outerHeight():0));return c[t].s.align==0?0:c[t].s.align==1?(J-((K.height+(c[t].s.captions?c[t].s.captionHeight:0))+((c[t].s.padding+c[t].s.borderWidth)*2)))/2:(J-((K.height+(c[t].s.captions?c[t].s.captionHeight:0))+((c[t].s.padding+c[t].s.borderWidth)*2)))}function e(K){if(a(K).parent().hasClass("fwShowcase_thumbs")){c[t].curImage=K}else{throw"showImage error: Incorrect element passed"}H();a(c[t].$list).find(".hover").removeClass("hover");c[t].curImage.addClass("hover");var L=a(c[t].curImage).find("> a"),N=L.attr("href"),M=new Image(),J=n.find(".fwShowcase_main"),O=n.find(".fwShowcase_image");J.stop();clearInterval(c[t].duration);a(M).load(function(){$image=a(this);$image.css({margin:c[t].s.padding,width:M.width,height:M.height});O.animate({opacity:0},c[t].s.fade,function(){O.empty();O.append(M);J.animate({top:j(M),width:M.width+(c[t].s.padding*2),height:M.height+(c[t].s.captions?c[t].s.captionHeight:0)+(c[t].s.padding*2)},c[t].s.fade,function(){O.animate({opacity:1},c[t].s.fade,function(){a(window).unbind("keydown").keydown(function(Q){if(Q.which==37){u()}else{if(Q.which==39){y()}}});l()})});if(c[t].s.captions){c[t].$title.css({width:M.width}).text(a(L).find("> img").attr("alt"))}if(c[t].s.showInfo){var P=c[t].$list.find("li:not(.fwShowcase_empty, .fwShowcase_cloned)");c[t].$info.text((a(P).index(c[t].curImage)+1)+" / "+c[t].total)}})}).attr("src",N)}function B(J){c[t].$overlay.css({background:c[t].s.overlayBg||"#fff",opacity:0,height:a(document).height(),width:a(document).width()}).show().animate({opacity:c[t].s.overlayBg?c[t].s.overlayOp:0},100,function(){d(a(J).parent())});v()}function d(M){if(a(M).parent().hasClass("fwShowcase_thumbs")){var Q=c[t].curImage;c[t].curImage=M}else{throw"showImage error: Incorrect element passed"}H();c[t].$viewer.stop();clearInterval(c[t].duration);var K=a(c[t].curImage).find("> a"),O=K.attr("href"),N=new Image(),P=c[t].s.padding,J=(a(window).width()/2+a(window).scrollLeft()),L=(a(window).height()/2+a(window).scrollTop());c[t].$image=a("#fwShowcase_image");c[t].$image.find("img").remove();c[t].$title.empty();a("#fwShowcase_image > .fwShowcase_prev, #fwShowcase_image > .fwShowcase_next").hide();c[t].$title.css({color:c[t].s.galleryTxtColor}).hide();a(c[t].$info).add(c[t].$controls).hide();a("#fwShowcase:hidden").css(c[t].s.galleryCss).addClass(n.attr("id")).css({background:c[t].s.galleryBg,width:c[t].s.startW,height:c[t].s.startH,top:L,left:J,marginLeft:-(c[t].s.startW/2),marginTop:-(c[t].s.startH/2),borderWidth:c[t].s.borderWidth,borderColor:c[t].s.borderColor,fontFamily:c[t].s.fontFamily}).show();a(N).load(function(){var V=(P+c[t].s.borderWidth)*2,U=N.height+c[t].s.captionHeight+V,R=N.width+V,T=-U/2,Y=-R/2,W=N.height,S=N.width;if(U>a(window).height()||R>a(window).width()){var X=Math.max(N.width/(a(window).width()-V),N.height/(a(window).height()-(c[t].s.captionHeight+V)));W/=X;S/=X;T=-(W+c[t].s.captionHeight+V)/2;Y=-(S+V)/2}if(L+T<0){L=T=0}if(J+Y<0){J=Y=0}if(c[t].$overlay.is(":visible")){c[t].$image.prepend(N);c[t].$viewer.animate({height:W+c[t].s.captionHeight+(P*2),width:S+(P*2),top:L,left:J,marginLeft:Y,marginTop:T},200,function(){a(N).css(c[t].s.imageCss).css({opacity:0,width:S,height:W,top:P,left:P}).show().animate({opacity:1},200,function(){a("#fwShowcase_image > .fwShowcase_prev, #fwShowcase_image > .fwShowcase_next").css({width:S/2,height:W,top:P,right:P,outline:"none"}).show();a("#fwShowcase_image > .fwShowcase_prev").css({left:P});if(c[t].s.controls){if(c[t].s.autohideControls){c[t].$controls.hide()}else{if((!c[t].s.autohideControls||c[t].s.autohideControls&&Q)||(c[t].s.autohideControls&&!Q)){c[t].$controls.show()}}}if(c[t].s.showInfo){if(c[t].s.autohideInfo){c[t].$info.hide()}else{if((!c[t].s.autohideInfo||c[t].s.autohideInfo&&Q)||(c[t].s.autohideInfo&&!Q)){var Z=c[t].$list.find("li:not(.fwShowcase_empty, .fwShowcase_cloned)");c[t].$info.text((a(Z).index(c[t].curImage)+1)+" / "+c[t].total).show()}}}l()});if(c[t].s.captions){c[t].$title.css({width:N.width}).text(a(K).find("> img").attr("alt")).show()}})}}).attr("src",O).hide()}})}})(jQuery);
