/*
* @file
* @brief    sigplus Image Gallery Plus image slider engine with jQuery
* @author   Levente Hunyadi
* @version  1.2.8
* @remarks  Copyright (C) 2009-2010 Levente Hunyadi
* @remarks  Licensed under GNU/GPLv3, see http://www.gnu.org/licenses/gpl-3.0.html
* @see      http://hunyadi.info.hu/projects/sigplus
*/
(function(a){a.fn.maxWidth=function(){var b=0;this.each(function(c,d){b=Math.max(b,a(d).outerWidth(true))});return b};a.fn.maxHeight=function(){var b=0;this.each(function(c,d){b=Math.max(b,a(d).outerHeight(true))});return b};a.fn.imageSlider=function(f){var g={rowCount:1,columnCount:4,showButtons:true,showLinks:true,showPageCounter:true,showOverlayButtons:true,alignment:"left",orientation:"horizontal",navigation:"top",firstText:"First",prevText:"Previous",nextText:"Next",lastText:"Last",pageText:"%1$d of %2$d",duration:800,animationDelay:0,opacity:1};f=a.extend(g,f);if(f.itemCount){switch(f.orientation){case"vertical":f.rowCount=f.itemCount;f.columnCount=1;break;default:f.rowCount=1;f.columnCount=f.itemCount}}var p=this;var o;var l;var m;var b=0;function n(q){switch(f.alignment){case"center":q.addClass("imageSliderCenter");break;case"right":q.addClass("imageSliderRight");break;default:q.addClass("imageSliderLeft")}}function k(){var q=a("ul:first li",p);if(a("img:first",q).length==q.length){var r=a("img:first",q).maxWidth();var s=a("img:first",q).maxHeight()}else{var r=q.maxWidth();var s=q.maxHeight()}return{width:r,height:s}}function h(){p.addClass("imageSlider");switch(f.alignment){case"left":p.addClass("imageGalleryLeft");break;case"center":p.addClass("imageGalleryCenter");break;case"right":p.addClass("imageGalleryRight");break}var t=a("div.imageSliderViewportArea",p);if(!t){a("ul:first",p).wrap('<div class="imageSliderViewportArea"></div>');t=a("div.imageSliderViewportArea",p)}t.addClass("imageSliderScrollableViewportArea");var q=a("div.imageSliderViewport",p);if(!q){t.wrap('<div class="imageSliderViewport"></div>');q=a("div.imageSliderViewport",p)}q.addClass("imageSliderScrollableViewport");var v=a("ul:first",p);var u=a("li",p).length;o=k();m={width:f.columnCount*o.width,height:f.rowCount*o.height};switch(f.orientation){case"vertical":l={width:f.columnCount*o.width,height:Math.ceil(u/f.columnCount)*o.height};break;default:l={width:Math.ceil(u/f.rowCount)*o.width,height:f.rowCount*o.height};if(f.rowCount>1&&f.columnCount>1){var r=a("li",v);r.detach();for(var s=0;s<f.rowCount;s++){r.each(function(w){if(w%f.rowCount==s){v.append(this)}})}}}var r=a("li",v);r.each(function(){a(this).css({width:o.width,height:o.height})});r.wrapInner('<div class="imageSliderAlignment"></div>');r.wrapInner('<div class="imageSliderAlignment"></div>');a("div.imageSliderAlignment",r).each(function(){a(this).css({width:a("img:first",this).outerWidth(true),height:a("img:first",this).outerHeight(true)})});t.removeClass("imageSliderViewportAreaFlow");if(f.rowCount>1&&f.columnCount>1){t.addClass("imageSliderViewportAreaMatrix")}else{switch(f.orientation){case"vertical":t.addClass("imageSliderViewportAreaColumn");break;default:t.addClass("imageSliderViewportAreaRow")}}t.css({width:l.width,height:l.height});q.css({width:m.width,height:m.height});n(q);c();if(f.opacity<1){a("img:first",r).css("opacity",f.opacity);a("img:first",r).hover(function(){a(this).stop();a(this).animate({opacity:1},"slow")},function(){a(this).stop();a(this).animate({opacity:f.opacity},"slow")})}}function c(){if(f.showButtons||f.showLinks||f.showPageCounter){var u=Math.ceil(a("ul:first li",p).length/(f.rowCount*f.columnCount));var t='<a class="pg_first" href="#" title="'+f.firstText+'">'+(f.showButtons?"<span></span>":"")+(f.showLinks?f.firstText:"")+"</a>";var A='<a class="pg_prev" href="#" title="'+f.prevText+'">'+(f.showButtons?"<span></span>":"")+(f.showLinks?f.prevText:"")+"</a>";var B='<a class="pg_next" href="#" title="'+f.nextText+'">'+(f.showLinks?f.nextText:"")+(f.showButtons?"<span></span>":"")+"</a>";var v='<a class="pg_last" href="#" title="'+f.lastText+'">'+(f.showLinks?f.lastText:"")+(f.showButtons?"<span></span>":"")+"</a>";var z=f.showPageCounter?f.pageText.replace("%1$d",'<span class="current">1</span>').replace("%2$d",'<span class="total">'+u+"</span>"):"";var q='<div class="imageSliderPaging">'+t+" "+A+" "+z+" "+B+" "+v+"</div>";switch(f.navigation){case"both":a(p).prepend(q);a(p).append(q);break;case"top":a(p).prepend(q);break;default:a(p).append(q)}var r=a(".imageSliderPaging",p);r.width(m.width);n(r)}if(f.showOverlayButtons){var s=a('<div class="pg_prev"></div>');var y=a('<div class="pg_prev" title="'+f.prevText+'"></div>');s.append(y);var w=a('<div class="pg_next"></div>');var x=a('<div class="pg_next" title="'+f.nextText+'"></div>');w.append(x);switch(f.orientation){case"vertical":if(o.height<120){s.addClass("pg_top_small");w.addClass("pg_bottom_small")}else{s.addClass("pg_top_large");w.addClass("pg_bottom_large")}break;default:if(o.width<120){s.addClass("pg_left_small");w.addClass("pg_right_small")}else{s.addClass("pg_left_large");w.addClass("pg_right_large")}}a("div.imageSliderViewport",p).prepend(w);a("div.imageSliderViewport",p).prepend(s)}if(f.showButtons||f.showLinks||f.showOverlayButtons){a(".pg_first",p).click(function(){d("first");return false});a(".pg_prev",p).click(function(){d("prev");return false});a(".pg_next",p).click(function(){d("next");return false});a(".pg_last",p).click(function(){d("last");return false})}}function d(q){var u=f.rowCount*f.columnCount;var v=a("ul:first li",p).length;var r=(v%u?v-v%u:v-u);switch(q){case"first":b=0;break;case"prev":b=(b>=u)?b-u:0;break;case"next":b=(b<r)?b+u:r;break;case"last":b=r;break;case"cycle":b=(b>=r)?0:b+u;break;default:return}switch(f.orientation){case"vertical":var s=b/f.columnCount*o.height;a("div.imageSliderViewportArea",p).animate({top:-s},f.duration);break;default:var s=b/f.rowCount*o.width;a("div.imageSliderViewportArea",p).animate({left:-s},f.duration)}j()}function i(){d("cycle")}function j(){var r=f.rowCount*f.columnCount;var s=a("ul:first li",p).length;var q=(s%r?s-s%r:s-r);if(f.showPageCounter){a("span.current",p).text(Math.ceil(b/(f.rowCount*f.columnCount))+1)}if(f.showButtons||f.showLinks||f.showOverlayButtons){if(b>0){a(".pg_first",p).removeClass("imageSliderPagingDisabled");a(".pg_prev",p).removeClass("imageSliderPagingDisabled")}else{a(".pg_first",p).addClass("imageSliderPagingDisabled");a(".pg_prev",p).addClass("imageSliderPagingDisabled")}if(b<q){a(".pg_next",p).removeClass("imageSliderPagingDisabled");a(".pg_last",p).removeClass("imageSliderPagingDisabled")}else{a(".pg_next",p).addClass("imageSliderPagingDisabled");a(".pg_last",p).addClass("imageSliderPagingDisabled")}}}a(p).removeClass("imageGalleryHidden");h();j();if(f.animationDelay>0){var e=window.setInterval(i,f.animationDelay);a(p).hover(function(){window.clearInterval(e)},function(){e=window.setInterval(i,f.animationDelay)})}}})(jQuery);
