$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};
$(document).ready(function() {
	//Number of 'gallery-item's -1 to make things function the way they should
	var image_number=($('#container5 .karmic_flow_slides').size()-1);
	var num=0;
	
	$.preloadCssImages();
        $('#container5 .karmic_flow_slides').hide();
        $('#container5 .karmic_flow_slider').css('display', 'block');
        $('#container5 .karmic_flow_slides:eq(0)').fadeIn(2000); //show only the gallery-item we want
        slide();
        
        $(function() {			
			$('.lightbox').lightBox();
		});

		function slide()
		{
			if ( image_number > 0 ) {
				$('#container5').everyTime(2000, "slide",function()
				 {				 	
				 	var imgWidth = $(".karmic_flow_slides img:eq("+num+")").width();
					if ( num >= 4 && !(num >= image_number)) { //if the image we're currently on is greater than the number of images
						$('#container5 .karmic_flow_slides').pause(2000);
						$('#container5 .karmic_flow_slides').fadeOut(1000);
						//num=0; //set the number to 0 to reset					
					}else if ( imgWidth > 200 && !(num >= image_number))
					{
						
						$('#container5 .karmic_flow_slides:eq('+num+')').hide();										
					}
					
					if (!(num >= image_number))
					{
						num++;						
						$('#container5 .karmic_flow_slides:eq('+num+')').fadeIn(2000);								
					}			
				});
			}
      	}  
});