/* */
last = 0;
maxbild = 0;
bilboxhoehe = 518;
var autoplay = true;
// Delay Plugin for jQuery
// - http://www.evanbot.com
// - ï¾ƒã¤ï½© 2008 Evan Byrne

/*
jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	return this;
};
*/

function blend(i) {
	var dist = bilboxhoehe+100;
	if ( last == i)	 { return false; }

	function doreset(i) {
		$("#bildbox_" + (i+1)).css("top",  dist + "px" );
		$("#bildbox_" + (i-1)).css("top",  -dist + "px" );
	}

	if (last > i) {
		$("#bildbox_" + last).animate({"top": dist + "px"}, bilboxhoehe);
		$("#bildbox_" + i).css("top",  -dist + "px" );
		$("#bildbox_" + i).animate({"top": "0"}, bilboxhoehe, function () {
			doreset(i);
		});	
	}

	if (last < i) {
		$("#bildbox_" + last).animate({"top": -dist + "px"}, bilboxhoehe);
		$("#bildbox_" + i).css("top",  dist + "px" );
		$("#bildbox_" + i).animate({"top": "0"}, bilboxhoehe, function () {
			doreset(i);
	    });	
	}
	$("#button_" + i).addClass('navion');
	$("#button_" + last).removeClass('navion');
	last = i;
}

function thewait(cond) {
    if (autoplay) {
        if (last<maxbild) {
            var callme = last+1;
        } else {
            var callme = 1;
        }
        blend(callme);
        clearTimeout(mywait);
        mywait = setTimeout('thewait()',4000);
    }

}

$(document).ready(function(){
	last = 1;
    mywait = setTimeout('thewait()',4000);
	$("#header").hover(
        function() {
            autoplay = false;
        },
        function() {
            autoplay = true;
            clearTimeout(mywait);
            thewait();
        }
    );
});
