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

(function(c){var d=function(){};d.prototype=c.extend(d.prototype,{name:"galleryslideshow",options:{index:0,width:"auto",height:"auto",autoplay:!0,interval:3E3,navbar_items:4,caption_animation_duration:500},nav:null,navbar:null,captions:null,caption:null,initialize:function(b,g){var a=this,e=0,d=0;this.options=c.extend({},c.widgetkit.effects.defaults,this.options,g);this.element=this.wrapper=b;this.ul=this.wrapper.find("ul.slides:first");this.ul.children().each(function(){e=Math.max(e,c(this).height());
d=Math.max(d,c(this).width())});if(this.options.height=="auto")this.options.height=e;if(this.options.width=="auto")this.options.width=d;this.wrapper.css({position:"relative",width:this.options.width});this.slides=this.ul.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.index=this.slides[this.options.index]?this.options.index:0;c(".next",this.wrapper).bind("click",
function(){a.stop();a.nextSlide()});c(".prev",this.wrapper).bind("click",function(){a.stop();a.prevSlide()});c(this.slides.get(this.index)).show();if(this.wrapper.find(".nav:first").length){this.nav=this.wrapper.find(".nav:first");var f=this.nav.children();this.nav.parent().hasClass("navbar")&&this.initNavbar(f);f.children().each(function(b){c(this).bind("click",function(){a.stop();a.slides[b]&&a.show(b)})});b.bind("slideshow-show",function(b,a,d){c(f.removeClass("active").get(d)).addClass("active")})}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&&c(this.nav.children().get(this.index)).addClass("active");this.navbar&&c(this.navbar.children().get(this.index)).addClass("active");this.showCaption(this.index);this.timer=null;this.hover=!1;this.wrapper.hover(function(){a.hover=!0},function(){a.hover=!1});this.options.autoplay&&this.start();"ontouchend"in document&&(b.bind("touchstart",
function(a){function d(b){if(e){var a=b.originalEvent.touches?b.originalEvent.touches[0]:b;f={time:(new Date).getTime(),coords:[a.pageX,a.pageY]};Math.abs(e.coords[0]-f.coords[0])>10&&b.preventDefault()}}var g=a.originalEvent.touches?a.originalEvent.touches[0]:a,e={time:(new Date).getTime(),coords:[g.pageX,g.pageY],origin:c(a.target)},f;b.bind("touchmove",d).one("touchend",function(){b.unbind("touchmove",d);e&&f&&f.time-e.time<1E3&&Math.abs(e.coords[0]-f.coords[0])>30&&Math.abs(e.coords[1]-f.coords[1])<
75&&e.origin.trigger("swipe").trigger(e.coords[0]>f.coords[0]?"swipeleft":"swiperight");e=f=void 0})}),this.wrapper.bind("swipeleft",function(){a.stop();a.nextSlide()}).bind("swiperight",function(){a.stop();a.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=c(this.slides.get(this.index)),this.next=c(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.showCaption(b),this.element.trigger("slideshow-show",[this.index,b]),this.index=b,c.widgetkit.effects.show.apply(this)},showCaption:function(b){if(this.caption&&this.captions[b]){var d=c(this.captions.get(b)).html();c.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(){c(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 b=this;this.timer=setInterval(function(){b.hover||b.nextSlide()},this.options.interval)}},stop:function(){this.timer&&clearInterval(this.timer)},initNavbar:function(b){this.nav.wrap('<div class="navbar-container" />');var d=this.options.navbar_items,a=this.nav.parent().width();itemwidth=Math.round(a/d);$this=
this;this.nav.width(itemwidth*b.length).data("basewidth",a).data("itemwidth",itemwidth);b.each(function(){c(this).css("min-width",itemwidth)});this.element.bind("slideshow-show",function(a,d,c){a=$this.options.navbar_items;Math.ceil(b.length/a);d=Math.ceil((d+1)/a);c=Math.ceil((c+1)/a);a=$this.nav.data("basewidth");c!=d&&$this.nav.animate({"margin-left":(c-1)*-1*a})})}});c.fn[d.prototype.name]=function(){var b=arguments,g=b[0]?b[0]:null;return this.each(function(){var a=c(this);if(d.prototype[g]&&
a.data(d.prototype.name)&&g!="initialize")a.data(d.prototype.name)[g].apply(a.data(d.prototype.name),Array.prototype.slice.call(b,1));else if(!g||c.isPlainObject(g)){var e=new d;d.prototype.initialize&&e.initialize.apply(e,c.merge([a],b));a.data(d.prototype.name,e)}else c.error("Method "+g+" does not exist on jQuery."+d.name)})}})(jQuery);
