$(function(){$("div.slideshow").slideshow()});
jQuery.fn.slideshow=function(){var msie=navigator.appVersion.match(/MSIE ([^;]*)/);if(msie&&parseFloat(msie[1])<7)return;this.each(function(){var imageAppended=false;var imageLoaded=false;var root=$(this);if(root.find("a img").length==0)return;root.click(function(e){var browserWidth;var n=0;var lightbox=$.lightbox("#222",100,0.9,appendSlideshow);var slideshow=$("<div>").attr("id","slideshow");var ol=$("<ol>");var maxHeight=100;var count=root.find("a").each(function(i){var li=$("<li>");var img=$("<img>");
img.data("src",$(this).attr("href"));if(this==e.target.parentNode)n=i;li.append(img);var desc=$("<p>");desc.text($(this).find("img").attr("title"));li.append(desc);ol.append(li)}).length;slideshow.append(ol);var p=$("<p>");p.append($("<a>").addClass("prev").click(function(){move(-1);return false}));var counter=$("<span>");p.append(counter);p.append($("<a>").addClass("next").click(function(){move(1);return false}));p.append($("<a>").addClass("stop").click(function(){slideshow.remove();lightbox.remove();
return false}));p.find("a").bind("selectstart",function(){return false});slideshow.append(p);var img=loadImage(n);updateCounter(n);$(window).resize(resize);resize();$().hover(function(){p.children("a").animate({bottom:"10px"},"normal","easeOutCubic");p.children("span").animate({bottom:"35px"},"normal","easeOutCubic")},function(){if((window.innerHeight||document.body.clientHeight)<700)p.children().animate({bottom:"-100px"},"normal","easeOutCubic")});$().keyup(function(evt){switch(evt.keyCode){case 27:case 9:case 88:slideshow.remove();
lightbox.remove();break;case 37:move(-1);break;case 39:move(1);break}});return false;function resize(){browserWidth=$("html").width();ol.css({width:count*browserWidth+"px"});ol.css({marginLeft:-n*browserWidth});ol.find("li").css({width:browserWidth});return true}function appendSlideshow(){$("body").append(slideshow);if(imageLoaded)img.next().width(img.width());loadImage(n+1);updateCounter(n);imageAppended=true}function updateCounter(n){counter.text(n+1+"/"+count);if(n==0)$("a.prev").addClass("disabled").animate({opacity:0.3});
else $("a.prev").removeClass("disabled").animate({opacity:1});if(n==count-1)$("a.next").addClass("disabled").animate({opacity:0.3});else $("a.next").removeClass("disabled").animate({opacity:1})}function loadImage(n){var img=$(slideshow.find("img").get(n));if(img&&!img.attr("src")){img.bind("load",function(){if(imageAppended)img.next().width(img.width());imageLoaded=true});img.attr("src",img.data("src"))}return img}function move(d){var newN=n+d;if(newN<0||newN>=count)return;n=newN;updateCounter(n);
loadImage(n);loadImage(n+1);var offset=-n*browserWidth;ol.stop();ol.animate({marginLeft:offset},2E3,"easeOutCubic",done);function done(){ol.css({marginLeft:offset})}}})})};jQuery.easing.easeOutCubic=function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b};
jQuery.lightbox=function(color,zIndex,opacity,callback){zIndex=zIndex||100;color=color||"black";opacity=opacity||"0.7";var div=$("<div>");div.css({position:"absolute",top:"0",left:"0",width:"100%",height:$("body").height()+"px",backgroundColor:color,zIndex:zIndex,opacity:0});$("body").append(div);div.animate({opacity:opacity},"slow",callback);return{layer:div,remove:function(){div.animate({opacity:0},"slow",function(){div.remove()})}}};
