$(document).ready(function(){
	$('#gallery li a').fancybox({
		zoomSpeedIn : 200,
		overlayShow : true,
		overlayOpacity : '0.8'
	});
	
	if($('.slideshow').length>0){
		$.get('/sublime/_files/slideshow/default.html',function(d){
			var d = $(d).appendTo('.slideshow .inner').hide();
			var c=0,i=d.find('img');
			i.load(function(){
				if(c==i.length-1) {
					$('.slideshow .inner').children(':first').remove();
					d.show();
					$('.slideshow .inner li').slideShow();
				} 
				c++;
			});
		});
	}
});

$.fn.slideShow = function(){
	
	slideLeft = function(e){
		var width = e.width();
		e.animate({
			marginLeft : '-'+width+'px'				
		},25000,function(){
			e.css('margin-left',0);
			e.appendTo( e.parent() );
		});
	};
	
	var time = b = 20000,s=this;
	var p = $(this).eq(0).parent();
	p.css('width','auto')
	var n = p[0].nodeName.toLowerCase();
	
	return this.each(function(i){
		var t = $(this);
				
		p.width( p.width()+t.width() );
		
		if(i==0){time = 0;}
		if(i == s.length-1){
			setTimeout(function(){
				s.slideShow();
			},time+b);
		}
		setTimeout(function(){ slideLeft(t); },time);
		time += b;
	});
};