$(function(){
/***************************/


function crossFader(sel,fit,fot,pt,r){
	var els=$(sel);
	function swap(el){
		if(els.length>1){
			var current=jQuery.inArray(el,els);
			var next=(current+1);
/*			if( r ){
				next = Math.floor(Math.random() * els.length);
				while( next === current ){ next = Math.floor(Math.random() * els.length); }
			}*/
			next = next%els.length;
			$(el).fadeOut(fot);
			$(els.get(next)).fadeIn(fit,function(){
				var self=this;
				setTimeout(
					function(){
						swap(self);
					},
					pt
				);
			});
		}
	}
	var start=0;
	if( r ){
		start = Math.floor(Math.random() * els.length);
	}
	start = start%els.length;
	els.hide().slice(start,start+1).show();
	setTimeout(
		function(){
			swap(els.get(start));
		},
		pt
	);
};

$("#images").hide();
$(window).load(function(){
	$("#images").show();
	crossFader("#images img",1000,1000,1000,1);
});


/***************************/
});
