var currentslide = 1;
var prevslide = 1;
var slides = ['foto_1.jpg', 'foto_2.jpg','foto_4.jpg', 'foto_5.jpg'];

slides.sort( randOrd );

var nextwrapper = true;

function fotosliderslide() {
	$('#next-wrapper').css('width', $(window).width());
	
	var img = new Image();
	
	currentslide = Math.floor(Math.random()*(slides.length));
	
	if(prevslide == currentslide)
	{
		fotosliderslide();
		return;
	}
	
	if(currentslide == slides.length)
	{
		currentslide = 0;
	}
	
	$(img).load(function() {
		if(nextwrapper == true)
		{
			$('#next-wrapper img').replaceWith(this);
			$('#next-wrapper').fadeIn('slow');
			nextwrapper = false;
		}else{
			$('#fotoslider > img').replaceWith(this);
			$('#next-wrapper').fadeOut('slow');
			nextwrapper = true;
		}

	}).attr('src', '/images/layout/'+slides[currentslide]);
	
	prevslide = currentslide;
	
	fotosliderstart();
}

function fotosliderstart() {
	var t = setTimeout('fotosliderslide()', 5000);
}

function randOrd() {
	return (Math.round(Math.random())-0.5); 
}

$(function() {
	$('#login-form-open').click(function() {
		$('#login-form').toggleClass('display');
	});
	
	$('.boximg').colorbox();
	
	fotosliderstart();
})
