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

(function($){var instances=[],Plugin=function(){},defaults={width:200,height:"auto",total_width:"auto",sticky:false,spacing:0,easing:"easeOutCirc",duration:500};Plugin.prototype=$.extend(Plugin.prototype,{name:"galleryslider",initialize:function(options){this.options=$.extend({},defaults,options);this.init_options=$.extend({},this.options);var $this=this;this.ul=this.element.find(".slides:first");this.items=this.ul.children();this.wrapper=this.element;this.resize();this.items.each(function(i){var item=$(this);item.bind("mouseover",function(){$this.items.stop().removeClass("active");var preW=[],startW=item.width(),others=$this.items.not(item).filter(function(){return $(this).width()>$this.min2});others.each(function(){preW.push($(this).width())});item.animate({width:$this.options.width},{complete:function(){others.css("width",$this.min2)},easing:$this.options.easing,duration:$this.options.duration}).addClass("active");others.animate({width:$this.min2},{easing:$this.options.easing,duration:$this.options.duration})})});if(!this.options.sticky){this.wrapper.bind("mouseleave",function(){$this.items.stop().animate({width:$this.min}).removeClass("active")})}$(window).bind("debouncedresize",function(){$this.resize()})},resize:function(){this.items.stop().removeClass("active");this.ul.css({width:"",height:""});this.wrapper.css({width:"",height:""});var totalW=this.init_options.total_width=="auto"?this.wrapper.width():this.init_options.total_width>this.wrapper.width()?this.wrapper.width():this.init_options.total_width;this.min=totalW/this.items.length-this.options.spacing;this.options.width=this.init_options.width;this.options.height=this.init_options.height;this.items.css("background-size","");if(totalW<this.options.width){var ratio=this.init_options.width/(totalW/2),ratio_height=this.init_options.height/ratio;this.items.css("background-size",this.init_options.width/ratio+"px "+this.init_options.height/ratio+"px");this.options.width=this.init_options.width/ratio;this.options.height=this.init_options.height/ratio}this.min2=(totalW-this.options.width)/(this.items.length-1)-this.options.spacing;this.items.css({width:this.min,"margin-right":this.options.spacing});this.ul.width(this.items.eq(0).width()*this.items.length*2);this.wrapper.css({width:totalW,height:this.options.height})}});$.fn[Plugin.prototype.name]=function(){var args=arguments;var method=args[0]?args[0]:null;return this.each(function(){var element=$(this);if(Plugin.prototype[method]&&element.data(Plugin.prototype.name)&&method!="initialize"){element.data(Plugin.prototype.name)[method].apply(element.data(Plugin.prototype.name),Array.prototype.slice.call(args,1))}else if(!method||$.isPlainObject(method)){var plugin=new Plugin;plugin.element=element;instances.push(plugin);if(Plugin.prototype["initialize"])plugin.initialize.apply(plugin,args);element.data(Plugin.prototype.name,plugin)}else{$.error("Method "+method+" does not exist on jQuery."+Plugin.prototype.name)}})}})(jQuery);