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

(function($){$widgetkit.lazyloaders["slideshow"]=function(element,options){if($widgetkit.support.canvas){element.find("img[data-src]").each(function(){var img=$(this),canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");canvas.width=img.attr("width");canvas.height=img.attr("height");ctx.drawImage(this,0,0);img.attr("src",canvas.toDataURL("image/png"))})}element.css("visibility","hidden");var o_width=options.width,o_height=options.height,ul=element.find("ul.slides:first"),slides=ul.children(),delayed=false;slides.css("width","");slides.css("height","");ul.css("height","");element.css("width","");if(o_width!="auto"&&element.width()<o_width){o_width="auto";o_height="auto";delayed=true}element.css({width:o_width=="auto"?element.width():o_width});var width=ul.width(),height=o_height;if(height=="auto"){height=slides.eq(0).show().height()}slides.css({height:height});ul.css("height",height);$widgetkit.load(WIDGETKIT_URL+"/widgets/slideshow/js/slideshow.js").done(function(){element.find("img[data-src]").each(function(){var img=$(this),src=img.data("src");setTimeout(function(){img.attr("src",src)},1)});element.slideshow(options).css("visibility","visible")})};$widgetkit.lazyloaders["showcase"]=function(element,options){var slideshow=element.find(".wk-slideshow").css("visibility","hidden"),slideset=element.find(".wk-slideset").css("visibility","hidden"),setlis=slideset.find("ul.set > li"),width=options.width;$widgetkit.lazyloaders["slideshow"](slideshow,options);$widgetkit.lazyloaders["slideset"](slideset,$.extend({},options,{width:"auto",height:"auto",autoplay:false,duration:options.slideset_effect_duration,index:parseInt(options.index/options.items_per_set)}));$(window).bind("resize",function(){var resize=function(){element.css("width","");if(options.width=="auto"||options.width>element.width()){element.width(element.width())}else{element.width(options.width)}};resize();return resize}());$.when($widgetkit.load(WIDGETKIT_URL+"/widgets/slideset/js/slideset.js"),$widgetkit.load(WIDGETKIT_URL+"/widgets/slideshow/js/slideshow.js")).done(function(){slideshow.css("visibility","visible");slideset.css("visibility","visible");var sshow=slideshow.data("slideshow"),sset=slideset.data("slideset");setlis.eq(sshow.index).addClass("active");slideshow.bind("slideshow-show",function(e,currentindex,newindex){var li=setlis.removeClass("active").eq(newindex).addClass("active");if(!li.parent().is(":visible")){switch(newindex){case 0:sset.show(0);break;case setlis.length-1:sset.show(sset.sets.length-1);break;default:sset[newindex>currentindex?"next":"previous"]()}}});setlis.each(function(index){$(this).bind("click",function(){sshow.stop();sshow.show(index)})})})}})(jQuery);