/* 
 * MobilySlider
 * date: 20.1.2010
 * author: Marcin Dziewulski
 * last update: 11.04.2011
 * web: http://www.mobily.pl or http://playground.mobily.pl
 * email: hello@mobily.pl
 * Free to use under the MIT license.
 */
(function(g){g.fn.mobilyslider=function(l){var a=g.extend({},{content:".sliderContent",children:"div",transition:"horizontal",animationSpeed:300,autoplay:!1,autoplaySpeed:3E3,pauseOnHover:!1,bullets:!0,arrows:!0,arrowsHide:!0,prev:"prev",next:"next",carousel:!0,animationStart:function(){},animationComplete:function(){}},l);return this.each(function(){var h=g(this),d=h.children(a.content).children(a.children),c=d.length-1,l=d.width(),p=d.height(),e=0,o,m,f,j,n,k,b={init:function(){b.data();a.bullets&& b.bullets.create();a.arrows&&b.arrows.create();a.autoplay&&b.autoplay();a.carousel||b.carousel.init();b.triggers()},data:function(){d.each(function(a){g(this).css("z-index",-(a-c))});a.transition=="fade"&&d.hide().eq(0).show()},zindex:{prev:function(){e==c?d.eq(0).css("z-index",c+3):d.css("z-index",c+1);d.eq(e).css("z-index",c+4).next(d).css("z-index",c+2)},next:function(){d.css("z-index",c+1).eq(e).css("z-index",c+3).prev(d).css("z-index",c+2)},bullets:function(){d.css("z-index",c+1).eq(n).css("z-index", c+2);d.eq(e).css("z-index",c+3)},trigger:function(){j==1?b.zindex.next():j==-1?b.zindex.prev():j==0&&b.zindex.bullets()}},slide:{left:function(c){a.animationStart.call(this);d.eq(e).animate({left:c+"="+l},a.animationSpeed,function(){b.zindex.trigger()}).animate({left:0},a.animationSpeed+200,function(){a.animationComplete.call(this)});a.carousel||b.carousel.check()},top:function(c){a.animationStart.call(this);d.eq(e).animate({top:c+"="+p},a.animationSpeed,function(){b.zindex.trigger()}).animate({top:0}, a.animationSpeed+200,function(){a.animationComplete.call(this)});a.carousel||b.carousel.check()},fade:function(){a.animationStart.call(this);d.fadeOut(a.animationSpeed).eq(e).fadeIn(a.animationSpeed,function(){a.animationComplete.call(this)});a.carousel||b.carousel.check()}},animation:{previous:function(){e==0?e=c:e--;j=-1;switch(a.transition){case "horizontal":b.slide.left("-");break;case "vertical":b.slide.top("+");break;case "fade":b.slide.fade()}},next:function(){e==c?e=0:e++;j=1;switch(a.transition){case "horizontal":b.slide.left("+"); break;case "vertical":b.slide.top("-");break;case "fade":b.slide.fade()}}},autoplay:function(){o=setTimeout(function(){b.animation.next();a.bullets&&setTimeout(function(){b.bullets.update()},a.animationSpeed+300);b.autoplay()},a.autoplaySpeed)},pause:function(){clearTimeout(o)},bullets:{create:function(){h.append(g("<div />").addClass("sliderBullets"));m=h.find(".sliderBullets");for(i=0;i<=c;i++)m.append(g("<a />").attr({href:"#",rel:i}).text(i))},trigger:function(){k=m.find("a");k.eq(0).addClass("active"); k.click(function(){var c=g(this),d=c.attr("rel");n=k.filter(".active").attr("rel");e=d;sign=d>n?"+":"-";j=0;if(!c.hasClass("active"))switch(a.transition){case "horizontal":b.slide.left(sign);break;case "vertical":b.slide.top(sign);break;case "fade":b.slide.fade()}k.removeClass("active");c.addClass("active");return!1})},update:function(){k.removeClass("active").eq(e).addClass("active")}},arrows:{create:function(){h.append(g("<div />").addClass("sliderArrows"));f=h.find(".sliderArrows");f.append(g("<a />").attr("href", "#").addClass(a.prev).text("Previous"));f.append(g("<a />").attr("href","#").addClass(a.next).text("Next"))},trigger:function(){f.find("."+a.prev).click(function(){b.animation.previous();a.bullets&&b.bullets.update();return!1});f.find("."+a.next).click(function(){b.animation.next();a.bullets&&b.bullets.update();return!1});a.arrowsHide&&(f.hide(),h.hover(function(){f.show()},function(){f.hide()}))}},carousel:{init:function(){f=h.find(".sliderArrows");f.find("."+a.prev).hide()},check:function(){e== c?(f.find("."+a.next).hide(),a.autoplay&&b.pause()):f.find("."+a.next).show();e==0?f.find("."+a.prev).hide():f.find("."+a.prev).show()}},triggers:function(){a.arrows&&b.arrows.trigger();a.bullets&&b.bullets.trigger();a.pauseOnHover&&h.hover(function(){b.pause()},function(){b.autoplay()})}};b.init()})}})(jQuery);
