/*
* @file
* @brief    sigplus Image Gallery Plus image slider engine with MooTools
* @author   Levente Hunyadi
* @version  1.1
* @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
*/
Elements.prototype.getMaxTotalSize=function(){var a=0;var b=0;this.each(function(d){var c=d.getSize().size;a=Math.max(a,c.x+d.getStyle("margin-left").toInt()+d.getStyle("margin-right").toInt());b=Math.max(b,c.y+d.getStyle("margin-top").toInt()+d.getStyle("margin-bottom").toInt())});return{width:a,height:b}};function intdiv(b,a){b=b|0;a=a|0;return(b/a)|0}function imageSlider(o,n){var e={prevText:"Previous",nextText:"Next",navigation:"bottom",orientation:"horizontal",duration:800,itemCount:4};var n=$extend(e,n);n.isVertical=n.orientation=="vertical";var l={width:200,height:200};var b={current:0,count:n.itemCount,total:function(){var q=this.count;var r=h.length;return(r%q?r-r%q:r-q)}};o.addClass("imageSlider");var j=o.getElement("ul");var h=j.getElements("li");var m=j.getElements("li img");if(m.length==h.length){l=m.getMaxTotalSize()}else{l=h.getMaxTotalSize()}var i=new Element("div",{styles:{margin:0,padding:0,overflow:"hidden",position:"relative"}});i.adopt(j);i.injectInside(o);j.setStyle("position","relative");h.each(function(p){p.setStyle("position","absolute")});if(n.isVertical){j.setStyle("width",l.width);j.setStyle("height",n.itemCount*l.height);h.each(function(q,p){q.setStyle("width",l.width);q.setStyle("height",l.height);q.setStyle("left",0);q.setStyle("top",p*l.height)})}else{j.setStyle("width",n.itemCount*l.width);j.setStyle("height",l.height);h.each(function(q,p){q.setStyle("width",l.width);q.setStyle("height",l.height);q.setStyle("left",p*l.width);q.setStyle("top",0)})}var c=new Element("span",{styles:{display:"none"},events:{click:function(){k("prev");f()}}});c.setHTML('<a href="javascript:void(0);">'+n.prevText+"</a>");var g=new Element("span",{styles:{display:"none"},events:{click:function(){k("next");f()}}});g.setHTML('<a href="javascript:void(0);">'+n.nextText+"</a>");var a=new Element("div");a.addClass("imageSliderPaging");c.injectInside(a);a.appendText(" ");g.injectInside(a);switch(n.navigation){case"top":a.injectBefore(o);break;case"bottom":default:a.injectAfter(o);break}d();window.addEvent("resize",d);function d(){var r=o.getSize().size;var t=l.height;var q=l.width;if(n.isVertical){var s=intdiv(r.y,t)}else{var s=intdiv(r.x,q)}var u=n.itemCount;if(u>s){u=(s>1?s:1)}if(n.isVertical){i.setStyle("height",u*t)}else{i.setStyle("width",u*q)}b.count=u;f()}function k(q){var u=b.count;var r=b.total();var w=b.current;switch(q){case"prev":w=(w>=u)?w-u:0;break;case"next":w=(w<r)?w+u:r;break;default:return}b.current=w;if(n.isVertical){var s=new Fx.Style(j,"margin-top",{duration:n.duration});var v=(w*l.height*-1);s.start(v)}else{var s=new Fx.Style(j,"margin-left",{duration:n.duration});var v=(w*l.width*-1);s.start(v)}}function f(){var p=b.current;var q=b.total();if(p>0){c.setStyle("display","inline")}else{c.setStyle("display","none")}if(p<q){g.setStyle("display","inline")}else{g.setStyle("display","none")}}};
