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

(function(b){var d=function(){};d.prototype=b.extend(d.prototype,{name:"slideshow",options:{index:0,width:"auto",height:"auto",autoplay:!0,interval:3E3,caption_animation_duration:500,tpl:'<div class="slideshow"><div class="element" /><div class="next"></div><div class="prev"></div>'},nav:null,captions:null,caption:null,initialize:function(a,e){var c=this,d=0,i=0;this.options=b.extend({},b.widgetkit.effects.defaults,this.options,e);this.element=a;this.wrapper=b.tmpl(this.options.tpl,b.extend({element:a},
this.options)).insertAfter(a);b(".element",this.wrapper).replaceWith(a);a.children().each(function(){d=Math.max(d,b(this).height());i=Math.max(i,b(this).width())});if(this.options.height=="auto")this.options.height=d;if(this.options.width=="auto")this.options.width=i;this.wrapper.css({position:"relative",width:this.options.width});this.slides=b("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=b("div.next:first",this.wrapper).bind("click",function(){c.stop();c.nextSlide()});this.button.prev=b("div.prev:first",this.wrapper).bind("click",function(){c.stop();c.prevSlide()});b(this.slides.get(this.index)).show();if(this.wrapper.find(".nav:first").length)this.nav=this.wrapper.find(".nav:first"),this.nav.children().each(function(a){b(this).bind("click",
function(){c.stop();c.slides[a]&&c.show(a)})});if(this.wrapper.find(".captions:first").length&&this.wrapper.find(".caption:first").length)this.captions=this.wrapper.find(".captions:first").hide().children(),this.caption=this.wrapper.find(".caption:first").hide();this.nav&&b(this.nav.children().get(this.index)).addClass("active");this.showCaption(this.index);this.timer=null;this.hover=!1;this.wrapper.hover(function(){c.hover=!0},function(){c.hover=!1});this.options.autoplay&&this.start();"ontouchend"in
document&&(a.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:b(c.target)},g;a.bind("touchmove",d).one("touchend",function(){a.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(a){if(!(this.index==a||this.fx))this.current=b(this.slides.get(this.index)),
this.next=b(this.slides.get(a)),this.animated=this.options.animated,this.duration=this.options.duration,this.easing=this.options.easing,this.dir=a>this.index?"right":"left",this.nav&&b(this.nav.children().removeClass("active").get(a)).addClass("active"),this.showCaption(a),this.index=a,b.widgetkit.effects.show.apply(this)},showCaption:function(a){if(this.caption&&this.captions[a]){var d=b(this.captions.get(a)).html();b.trim(d)==""?this.caption.is(":visible")&&this.caption.fadeOut(this.options.caption_animation_duration):
this.caption.is(":visible")?this.caption.fadeOut(this.options.caption_animation_duration,function(){b(this).html(d)}).delay(200).fadeIn(this.options.caption_animation_duration):this.caption.html(d).fadeIn(this.options.caption_animation_duration)}},start:function(){if(!this.timer){var a=this;this.timer=setInterval(function(){a.hover||a.nextSlide()},this.options.interval)}},stop:function(){this.timer&&clearInterval(this.timer)}});b.fn[d.prototype.name]=function(){var a=arguments,e=a[0]?a[0]:null;return this.each(function(){var c=
b(this);if(d.prototype[e]&&c.data(d.prototype.name)&&e!="initialize")c.data(d.prototype.name)[e].apply(c.data(d.prototype.name),Array.prototype.slice.call(a,1));else if(!e||b.isPlainObject(e)){var h=new d;d.prototype.initialize&&h.initialize.apply(h,b.merge([c],a));c.data(d.prototype.name,h)}else b.error("Method "+e+" does not exist on jQuery."+d.name)})}})(jQuery);

