jQuery(document).ready(function($){
	// Overriding prototype's $ function with jQuery-$-handler - inside document.ready only
	// Do jQuery stuff using $



    function start_animation(step) {
	
	// Übergabeparameter vordefinieren
	if (step == undefined) step = 1;

	/* trigger the clicks magically to create an animation */
	var start = 500; /* milliseconds to wait before showing the first animation */
	var pause = 4000; /* milliseconds between each transition */

	
	if (step == 1) {
		/* setting up the default state after loading */
		buttons = new Array("#button1","#button_2","#button_3","#button_4","#button_5"); /**/
		pages = new Array("#seite1","#seite2","#seite3","#seite4","#seite5");

		/* making all buttons inactive */
		for ( i = 0; i < buttons.length; i++ ) {
			$(buttons[i]).removeClass("current_item");
		}
			
		// hide all content divs
		for ( i = 0; i < pages.length; i++ ) {
			$(pages[i]).hide();
		}

		// advance to the next step
		seite1_timer = setTimeout(function(){$("#button_1").trigger('click')},start);
	}

	if (step == 2) {
		seite1_timer = setTimeout(function(){$("#button_2").trigger('click')},(pause+1500)); // Allowing the user a little more time to grasp the first slide
		}
	if (step == 3) {
		seite2_timer = setTimeout(function(){$("#button_3").trigger('click')},pause);
		}
	if (step == 4) {
		seite3_timer = setTimeout(function(){$("#button_4").trigger('click')},pause);
		}
	if (step == 5) {
		seite4_timer = setTimeout(function(){$("#button_5").trigger('click')},pause);
		}
	
	/* Clearing the timers in case the user actually clicks on the buttons himself */
	$("#steuerung a").mouseup(function() {
		clearTimeout(seite1_timer);
		clearTimeout(seite2_timer);
		clearTimeout(seite3_timer);
		clearTimeout(seite4_timer);
	});
	
	}; /* function start_animation */
		
		


	/* Defining the behaviours for the buttons */ 
	$("#button_1").click(function(event) {
		this.blur();
		thisbutton = "#button_1";
		otherbuttons = new Array("#button_2","#button_3","#button_4","#button_5");
		thispage = "#seite1";
		otherpages = new Array("#seite2","#seite3","#seite4","#seite5");
       		
		/* Disabling the default event */
		event.preventDefault();
			
		// disable other buttons
		for ( i = 0; i < otherbuttons.length; i++ ) {
			$(otherbuttons[i]).removeClass("current_item");
		}
			
		// make this button active
		$(thisbutton).addClass("current_item");

		// hide other content
		for ( i = 0; i < otherpages.length; i++ ) {
			$(otherpages[i]).fadeOut("slow");
		}
			
		// show this content only
		$(thispage).fadeIn("slow");

		// advance to next step in the animation
		start_animation(2);
	});
       
       
       
	$("#button_2").click(function(event) {
		this.blur();
		thisbutton = "#button_2";
		otherbuttons = new Array("#button_1","#button_3","#button_4","#button_5");
		thispage = "#seite2";
		otherpages = new Array("#seite1","#seite3","#seite4","#seite5");
       		
		/* Disabling the default event */
		event.preventDefault();
			
		// disable other buttons
		for ( i = 0; i < otherbuttons.length; i++ ) {
			$(otherbuttons[i]).removeClass("current_item");
		}
			
		// make this button active
		$(thisbutton).addClass("current_item");

		// hide other content
		for ( i = 0; i < otherpages.length; i++ ) {
			$(otherpages[i]).fadeOut("slow");
		}
			
		// show this content only
			$(thispage).fadeIn("slow");

		// advance to next step in the animation
		start_animation(3);
	});
       
       
       
	$("#button_3").click(function(event) {
		this.blur();
		thisbutton = "#button_3";
		otherbuttons = new Array("#button_1","#button_2","#button_4","#button_5");
		thispage = "#seite3";
		otherpages = new Array("#seite1","#seite2","#seite4","#seite5");
       		
		/* Disabling the default event */
		event.preventDefault();
			
		// disable other buttons
		for ( i = 0; i < otherbuttons.length; i++ ) {
			$(otherbuttons[i]).removeClass("current_item");
		}
			
		// make this button active
		$(thisbutton).addClass("current_item");

		// hide other content
		for ( i = 0; i < otherpages.length; i++ ) {
			$(otherpages[i]).fadeOut("slow");
		}
			
		// show this content only
		$(thispage).fadeIn("slow");

		// advance to next step in the animation
		start_animation(4);
	});
       
       
       
	$("#button_4").click(function(event) {
		this.blur();
		thisbutton = "#button_4";
		otherbuttons = new Array("#button_1","#button_2","#button_3","#button_5");
		thispage = "#seite4";
		otherpages = new Array("#seite1","#seite2","#seite3","#seite5");
       		
		/* Disabling the default event */
		event.preventDefault();
			
		// disable other buttons
		for ( i = 0; i < otherbuttons.length; i++ ) {
			$(otherbuttons[i]).removeClass("current_item");
		}
			
		// make this button active
		$(thisbutton).addClass("current_item");

		// hide other content
		for ( i = 0; i < otherpages.length; i++ ) {
			$(otherpages[i]).fadeOut("slow");
		}
			
		// show this content only
		$(thispage).fadeIn("slow");
	
		// advance to next step in the animation
		start_animation(5);
	});
       
       
       
	$("#button_5").click(function(event) {
		this.blur();
		thisbutton = "#button_5";
		otherbuttons = new Array("#button_1","#button_2","#button_3","#button_4");
		thispage = "#seite5";
		otherpages = new Array("#seite1","#seite2","#seite3","#seite4");
       		
		/* Disabling the default event */
		event.preventDefault();
			
		// disable other buttons
		for ( i = 0; i < otherbuttons.length; i++ ) {
			$(otherbuttons[i]).removeClass("current_item");
		}
			
		// make this button active
		$(thisbutton).addClass("current_item");

		// hide other content
		for ( i = 0; i < otherpages.length; i++ ) {
			$(otherpages[i]).fadeOut("slow");
		}
			
		// show this content only
		$(thispage).fadeIn("slow");

		// advance to next step in the animation
		// reached the end, nothing to do here
	});
	

	$(".teaserbox a").click(function(event) {
		this.blur();
	});


	// Animation starten
	start_animation(1);

}); /* end jQuery.ready(function());*/
     
     
     
     


 
     
     
     
     
/* Modifying the livesearch function of K2 just for the homepage */
Livesearch.prototype.readyLivesearch = function(event) {
		var code = event.keyCode;
		if (code == Event.KEY_ESC || ((code == Event.KEY_DELETE || code == Event.KEY_BACKSPACE) && $F(this.attachitem) == '')) {
			this.resetLivesearch.bind(this);
		} else if (code != Event.KEY_LEFT && code != Event.KEY_RIGHT && code != Event.KEY_DOWN && code != Event.KEY_UP && code != Event.KEY_RETURN) {
			/* no liveSearch for these events */
		}
	};