jQuery(function(){var a=jQuery,i=a("#slideshow");i.find(".thumb").mouseover(function(){r(a(this).data("thumb-id"))}),i.find("#prev-btn").on("click",function(){n()}),i.find("#next-btn").on("click",function(){t()}),a(document).keydown(function(a){switch(a.keyCode){case 37:n();break;case 39:t()}});var t=function(){var a=i.find(".img-wrapper.active");0===a.length&&(a=i.find(".img-wrapper:last")),e(a)},e=function(a){var t=a.next(".img-wrapper").length?a.next(".img-wrapper"):i.find(".img-wrapper:first"),e=i.find('[data-thumb-id="'+t.data("img-id")+'"]');i.find(".thumb").removeClass("active"),e.addClass("active"),a.addClass("last-active"),d(e),t.css({opacity:0}).addClass("active").animate({opacity:1},1e3,function(){a.removeClass("active last-active")})},n=function(){var a=i.find(".img-wrapper.active");0===a.length&&(a=i.find(".img-wrapper:last")),s(a)},s=function(a){var t=a.prev(".img-wrapper").length?a.prev(".img-wrapper"):i.find(".img-wrapper:last"),e=i.find('[data-thumb-id="'+t.data("img-id")+'"]');i.find(".thumb").removeClass("active"),e.addClass("active"),a.addClass("last-active"),d(e),t.css({opacity:0}).addClass("active").animate({opacity:1},1e3,function(){a.removeClass("active last-active")})},r=function(a){var t=i.find('[data-img-id="'+a+'"]'),e=i.find('[data-thumb-id="'+a+'"]'),n=i.find(".img-wrapper.active");i.find(".thumb").removeClass("active"),n.addClass("last-active").removeClass("active"),e.addClass("active"),d(e),t.css({opacity:0}).addClass("active").animate({opacity:1},1e3,function(){n.removeClass("last-active")})},d=function(a){var t,e,n=a.position().left+parseInt(a.css("margin-left"),10);if(n<0)e=i.find(".thumb:first"),t=parseInt(e.css("margin-left"),10)-n,e.animate({marginLeft:t},1e3);else{var s=(n=a.position().left)+140-a.parent().width();s>0&&(e=i.find(".thumb:first"),t=parseInt(e.css("margin-left"),10)-s,e.animate({marginLeft:t},1e3))}}});