/* Copyright (C) 2007 - 2011 YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

(function(a){var d=function(){};d.prototype=a.extend(d.prototype,{name:"slideshow",options:{index:0,width:"auto",height:"auto",autoplay:!0,interval:3E3,tpl:'<div class="slideshow"><div class="element" /><div class="next"></div><div class="prev"></div>'},nav:null,initialize:function(b,d){var c=this,e=0,i=0;this.options=a.extend({},a.widgetkit.effects.defaults,this.options,d);this.element=b;this.wrapper=a.tmpl(this.options.tpl,a.extend({element:b},this.options)).insertAfter(b);a(".element",this.wrapper).replaceWith(b);
b.children().each(function(){e=Math.max(e,a(this).height());i=Math.max(i,a(this).width())});if(this.options.height=="auto")this.options.height=e;if(this.options.width=="auto")this.options.width=i;this.wrapper.css({position:"relative",width:this.options.width});this.slides=a("ul.slides:first",this.wrapper).css({position:"relative",overflow:"hidden",height:this.options.height}).children().css({top:"0px",left:"0px",position:"absolute",width:this.wrapper.width(),height:this.options.height}).hide();this.button=
{};this.index=this.slides[this.options.index]?this.options.index:0;this.button.next=a("div.next:first",this.wrapper).bind("click",function(){c.stop();c.nextSlide()});this.button.prev=a("div.prev:first",this.wrapper).bind("click",function(){c.stop();c.prevSlide()});if(this.wrapper.find(".nav:first").length)this.nav=this.wrapper.find(".nav:first"),this.nav.children().each(function(b){a(this).bind("click",function(){c.stop();c.slides[b]&&c.show(b)})}),a(this.nav.children().get(this.index)).addClass("active");
a(this.slides.get(this.index)).show();this.timer=null;this.options.autoplay&&this.start();"ontouchend"in document&&(b.bind("touchstart",function(c){function d(a){if(f){var b=a.originalEvent.touches?a.originalEvent.touches[0]:a;g={time:(new Date).getTime(),coords:[b.pageX,b.pageY]};Math.abs(f.coords[0]-g.coords[0])>10&&a.preventDefault()}}var e=c.originalEvent.touches?c.originalEvent.touches[0]:c,f={time:(new Date).getTime(),coords:[e.pageX,e.pageY],origin:a(c.target)},g;b.bind("touchmove",d).one("touchend",
function(){b.unbind("touchmove",d);f&&g&&g.time-f.time<1E3&&Math.abs(f.coords[0]-g.coords[0])>30&&Math.abs(f.coords[1]-g.coords[1])<75&&f.origin.trigger("swipe").trigger(f.coords[0]>g.coords[0]?"swipeleft":"swiperight");f=g=void 0})}),this.wrapper.bind("swipeleft",function(){c.stop();c.nextSlide()}).bind("swiperight",function(){c.stop();c.prevSlide()}))},nextSlide:function(){this.show(this.slides[this.index+1]?this.index+1:0)},prevSlide:function(){this.show(this.index-1>-1?this.index-1:this.slides.length-
1)},show:function(b){if(!(this.index==b||this.fx))this.current=a(this.slides.get(this.index)),this.next=a(this.slides.get(b)),this.animated=this.options.animated,this.duration=this.options.duration,this.easing=this.options.easing,this.dir=b>this.index?"right":"left",this.nav&&a(this.nav.children().removeClass("active").get(b)).addClass("active"),this.index=b,a.widgetkit.effects.show.apply(this)},start:function(){if(!this.timer){var a=this;this.timer=setInterval(function(){a.nextSlide()},this.options.interval)}},
stop:function(){this.timer&&clearInterval(this.timer)}});a.fn[d.prototype.name]=function(){var b=arguments,h=b[0]?b[0]:null;return this.each(function(){var c=a(this);if(d.prototype[h]&&c.data(d.prototype.name)&&h!="initialize")c.data(d.prototype.name)[h].apply(c.data(d.prototype.name),Array.prototype.slice.call(b,1));else if(!h||a.isPlainObject(h)){var e=new d;d.prototype.initialize&&e.initialize.apply(e,a.merge([c],b));c.data(d.prototype.name,e)}else a.error("Method "+h+" does not exist on jQuery."+
d.name)})}})(jQuery);

