/**
* sigplus Image Gallery Plus
* Image slider
*
* This code is derived from and fixes browser incompatibility issues
* present in the original prettyGallery by Stephane Caron.
*
* @version     1.0
* @author      Levente Hunyadi
* @copyright   Copyright (C) 2009 Levente Hunyadi
* @license     GNU/GPLv3, see http://www.gnu.org/licenses/gpl-3.0.html
* @link        http://www.no-margin-for-errors.com
*/
(function($){$.fn.maxWidth=function(){return Math.max.apply(Math,$.makeArray(this.map(function(){return $(this).outerWidth()})))};$.fn.maxHeight=function(){return Math.max.apply(Math,$.makeArray(this.map(function(){return $(this).outerHeight()})))};$.fn.prettyGallery=function(settings){settings=jQuery.extend({itemsPerPage:4,animationSpeed:"normal",navigation:"top",of_label:"%1$d of %2$d",previous_title_label:"Previous page",next_title_label:"Next page",previous_label:"Previous",next_label:"Next"},settings);return this.each(function(){var currentPage=1;var itemWidth=0;var itemHeight=0;var galleryWidth=0;var pageCount=0;var animated=false;var $gallery=$(this);var _scrollGallery=function(caller,dir){if(animated||$(caller).hasClass("imageSliderPagingDisabled")){return}animated=true;$gallery.find("li:lt("+(currentPage*settings.itemsPerPage)+")").each(function(i){$(this).animate({left:$(this).position().left-dir*galleryWidth},settings.animationSpeed,function(){animated=false})});$gallery.find("li:gt("+(currentPage*settings.itemsPerPage-1)+")").each(function(i){$(this).animate({left:$(this).position().left-dir*galleryWidth},settings.animationSpeed)});currentPage+=dir;_displayPaging()};var _formatGallery=function(){if($("li img",$gallery).size()==$("li",$gallery).size()){itemWidth=$("li img",$gallery).maxWidth();itemHeight=$("li img",$gallery).maxHeight()}else{itemWidth=$("li",$gallery).maxWidth();itemHeight=$("li",$gallery).maxHeight()}galleryWidth=itemWidth*settings.itemsPerPage;$gallery.css({width:galleryWidth,height:itemHeight,overflow:"hidden",position:"relative",clear:"left"});$gallery.find("li").each(function(i){$(this).css({position:"absolute",top:0,left:i*itemWidth})});$gallery.wrap("<div></div>")};var _displayPaging=function(){var nav=$gallery.parent().find("p.imageSliderPaging");$("span.current",nav).text(currentPage);$("span.total",nav).text(pageCount);$("a",nav).removeClass("imageSliderPagingDisabled");if(currentPage==1){$("a.pg_prev",nav).addClass("imageSliderPagingDisabled")}else{if(currentPage==pageCount){$("a.pg_next",nav).addClass("imageSliderPagingDisabled")}}};var _applyNav=function(){var template="";template+='<p class="imageSliderPaging">';template+='<a class="pg_prev" href="#" title="'+settings.previous_title_label+'"><span></span>'+settings.previous_label+"</a>&nbsp;";template+=settings.of_label.replace("%1$d",'<span class="current">1</span>').replace("%2$d",'<span class="total">1</span>');template+='&nbsp;<a class="pg_next" href="#" title="'+settings.next_title_label+'">'+settings.next_label+"<span></span></a>";template+="</p>";switch(settings.navigation){case"top":$gallery.before(template);break;case"bottom":$gallery.after(template);break;case"both":$gallery.before(template);$gallery.after(template);break}var nav=$gallery.parent().find("p.imageSliderPaging");nav.width(galleryWidth);nav.find("a.pg_prev").bind("click",function(){_scrollGallery(this,-1);return false});nav.find("a.pg_next").bind("click",function(){_scrollGallery(this,1);return false})};if($(this).find("li").size()>settings.itemsPerPage){pageCount=Math.ceil($(this).find("li").size()/settings.itemsPerPage);_formatGallery();_applyNav();_displayPaging(this);currentPage=1}})}})(jQuery);
