jQuery('body').addClass('jQuery-enabled');jQuery(document).ready(function(){var speed=100;jQuery(window).load(function(){jQuery("#gallery-wrap img").hide();timer=setInterval(function(){$notLoaded=jQuery("#gallery-wrap img").not(".loaded");$notLoaded.eq(Math.floor(Math.random()*$notLoaded.length)).fadeIn().addClass("loaded");if($notLoaded.length==0){clearInterval(timer);}},speed);});jQuery('#gallery-wrap li img, .post-thumb a img, .flickr_badge_image a img').hover(function(){jQuery(this).stop().animate({opacity:0.5},200);},function(){jQuery(this).stop().animate({opacity:1},200);});function sortPhotos(cat){if(jQuery('#gallery-wrap li').hasClass(cat)){jQuery('#gallery-wrap li').not('.'+cat).removeClass('visible').find('a').fadeOut(500);jQuery('.'+cat).addClass('visible').find('a').fadeIn(800);}}
jQuery('#gallery-terms li a').click(function(){var cat=jQuery(this).attr('data-value')
sortPhotos(cat);jQuery('#gallery-terms li a').removeClass("current");jQuery(this).addClass("current");return false;});jQuery('#gallery-terms li a.all').click(function(e){jQuery('#gallery-wrap li').addClass('visible').find('a').fadeIn(500);return false;});if(jQuery('#gallery-overlay').hasClass('true')){jQuery('#gallery-wrap li a').click(function(e){var postId=jQuery(this).parent().attr('id').split('photo-')[1];getPhoto(postId,this);e.preventDefault();});}
function galleryInit(){jQuery('#next-post, #prev-post').click(function(){var postId=jQuery(this).attr('data-id');getPhoto(postId,jQuery('li#photo-'+postId+' a'));return false;});jQuery('.gallery-close a').click(function(){jQuery('body').css({overflow:'auto'});jQuery('#gallery-overlay, #body-overlay').fadeOut(500);return false;});}
jQuery('#loader').click(function(){jQuery('#gallery-overlay').fadeOut(1,function(){jQuery('#loader').fadeOut(200);});});function getPhoto(postId,hasSelector){var next=jQuery('#gallery-wrap li.visible').first().attr('id').split('photo-')[1];var prev=jQuery('#gallery-wrap li.visible').last().attr('id').split('photo-')[1];var hasNext=jQuery(hasSelector).parent().next();var hasPrev=jQuery(hasSelector).parent().prev();if(hasNext.length!=0){while(hasNext.hasClass('visible')==false&&hasNext.length!=0){hasNext=hasNext.next();}
if(hasNext.length!=0){var next=hasNext.attr('id').split('photo-')[1];}}
if(hasPrev.length!=0){while(hasPrev.hasClass('visible')==false&&hasPrev.length!=0){hasPrev=hasPrev.prev();}
if(hasPrev.length!=0){var prev=hasPrev.attr('id').split('photo-')[1];}}
jQuery('#loader').fadeIn(200,function(){jQuery.ajax({url:jQuery('#theme-url').attr('data-id'),data:{id:postId,next:next,prev:prev},success:function(data){var gallery=jQuery('#gallery-overlay');gallery.html(data);jQuery('#next-post').attr('data-id',next);jQuery('body').css({overflow:'hidden'});jQuery('#gallery-overlay, #body-overlay').fadeIn(500,function(){jQuery('#loader').fadeOut(500);});galleryInit();}});});}
var width=0;jQuery('#gallery-wrap li').each(function(){width+=jQuery(this).width();});function handleSliderChange(e,ui){var maxScroll=jQuery("#gallery-wrap").attr("scrollWidth")-jQuery("#gallery-wrap").width();jQuery("#gallery-wrap").stop().animate({scrollLeft:ui.value*(maxScroll/100),duration:1000,specialEasing:{marginLeft:"easeInOutCirc"}});}
function handleSliderSlide(e,ui){var maxScroll=jQuery("#gallery-wrap").attr("scrollWidth")-jQuery("#gallery-wrap").width();jQuery("#gallery-wrap").stop().animate({scrollLeft:ui.value*(maxScroll/100),duration:1000,specialEasing:{marginLeft:"easeInOutCirc"}});}
function hideSlider(){if(width<jQuery(window).width()||jQuery("#gallery-wrap ul").width()<jQuery(window).width()){jQuery('#content-slider').fadeOut(200);}else{jQuery('#content-slider').fadeIn(200);return true;}}
jQuery("#content-slider").slider({animate:true,change:handleSliderChange,slide:handleSliderSlide,max:100});jQuery(window).resize(function(){hideSlider();});hideSlider();});
