document.observe('dom:loaded', function() {
	if($("bgpic" + actual) != null){
		Effect.Appear("bgpic" + actual, {duration: 0});
		window.setTimeout("startAnimation()", 3500);
	}
});

function getRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
	return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}

var anzahl = 0;

// Startbild
var actual = 0;

function startAnimation(){
	changeBackground();
	window.setInterval("changeBackground()", 7000);
}

function changeBackground(){
	var pic = getRandom(0, anzahl-1);
	if(anzahl > 1){
		while(pic == actual){
			pic = getRandom(0, anzahl-1);
		}
	}
	Effect.Fade("bgpic" + actual, {duration: 2});
	Effect.Appear("bgpic" + pic, {delay: 0.5, duration: 2});
	actual = pic;
}

function loadPage(url, id){
	url = url.replace(/http:\/\/www.rutishauser-wein.ch/, "");
	$$('a#active_menu').each(function(s){
		s.id = "";
	});
	$$('div#active_menu').each(function(s){
		s.id = "";
	});
	$$('a#active_menu').each(function(s){
		s.id = "";
	});
	$$('.nav' + id).each(function(s){
		s.id = "active_menu";
	});
	new Ajax.Updater('newsContent', url);
	

//	new Ajax.Request(url, {
//		onComplete: function(req) { alert(req.responseText); }
//		on404: function(req) { alert("file not found"); }
//		on500: function(req) { alert("something went wrong"); }
//	});
}