// 29.04.2008
// Dieses Script wurde von der graphodata AG für MISEREOR produziert
// Copyright - 2008
// AUTOR: Mario Pauly
// EMAIL: Pauly@graphodata.de

window.onload = function() {

//GRUNDEINSTELLUNGEN
	$("#news_slide .csc-frame:eq(0)").hide();
	$("#news_slide .csc-frame:eq(1)").hide();
	$("#news_slide .csc-frame:eq(2)").hide();
	$("#news_slide .csc-frame:eq(3)").hide();

	$("#news_slide img:eq(0)").clone().appendTo("#news_slide_img");
	$("#news_slide img:eq(1)").clone().appendTo("#news_slide_img");
	$("#news_slide img:eq(2)").clone().appendTo("#news_slide_img");
	$("#news_slide img:eq(3)").clone().appendTo("#news_slide_img");

	$("#news_slide .csc-frame:eq(0)").show();
	$("#news_slide .csc-frame:eq(0)").addClass("text_act");
	$("#news_slide_img img:eq(0)").addClass("img_act");
	$(".img_act").fadeTo("fast", 0.5);

//MOUSEOVERFUNKTIONEN
	$("#news_slide_img img:eq(0)").mouseover(function(){
		$("#news_slide .text_act").hide();
		$("#news_slide .csc-frame:eq(0)").show();
		$(".text_act").removeClass("text_act");
		$("#news_slide .csc-frame:eq(0)").addClass("text_act");
		$(".img_act").fadeTo("fast", 1);
		$(".img_act").removeClass("img_act");
		$(this).addClass("img_act");
		$(".img_act").fadeTo("fast", 0.5);
		clearTimeout(timer);
	});

	$("#news_slide_img img:eq(1)").mouseover(function(){
		$("#news_slide .text_act").hide();
		$("#news_slide .csc-frame:eq(1)").show();
		$(".text_act").removeClass("text_act");
		$("#news_slide .csc-frame:eq(1)").addClass("text_act");
		$(".img_act").fadeTo("fast", 1);
		$(".img_act").removeClass("img_act");
		$(this).addClass("img_act");
		$(".img_act").fadeTo("fast", 0.5);
		clearTimeout(timer);
	});

	$("#news_slide_img img:eq(2)").mouseover(function(){
		$("#news_slide .text_act").hide();
		$("#news_slide .csc-frame:eq(2)").show();
		$(".text_act").removeClass("text_act");
		$("#news_slide .csc-frame:eq(2)").addClass("text_act");
		$(".img_act").fadeTo("fast", 1);
		$(".img_act").removeClass("img_act");
		$(this).addClass("img_act");
		$(".img_act").fadeTo("fast", 0.5);
		clearTimeout(timer);
	});

	$("#news_slide_img img:eq(3)").mouseover(function(){
		$("#news_slide .text_act").hide();
		$("#news_slide .csc-frame:eq(3)").show();
		$(".text_act").removeClass("text_act");
		$("#news_slide .csc-frame:eq(3)").addClass("text_act");
		$(".img_act").fadeTo("fast", 1);
		$(".img_act").removeClass("img_act");
		$(this).addClass("img_act");
		$(".img_act").fadeTo("fast", 0.5);
		clearTimeout(timer);
	});

//START UND STOPP-FUNKTIONEN
	$("#news_slide").mouseover(function(){
		clearTimeout(timer);
	});

	$("#news_slide").mouseout(function(){
		if ( $("#news_slide .csc-frame:last").hasClass("text_act") )
			lastchangeinit();

		if ( $("#news_slide .csc-frame:not(:last)").hasClass("text_act") )
			changeinit();
	});

	$("#news_slide_img img:not(:last)").mouseout(function(){
		changeinit();
	});

	$("#news_slide_img img:last").mouseout(function(){
		lastchangeinit();
	});

//INITIALISIERUNG DER WECHSELFUNKTION
	changeinit();

}

//ZEITABSTÄNDE
function changeinit(){
	timer = setTimeout ("change ()", 5000);
}

function lastchangeinit(){
	timer = setTimeout ("lastchange ()", 5000);
}

//WECHSELSCHLEIFEN
function change(){
	$(".img_act").fadeTo("fast", 1);
	$(".img_act").next().addClass("img_act");
	$(".img_act:first").removeClass("img_act");
	$(".img_act").fadeTo("fast", 0.5);

	$("#news_slide .csc-frame:not(:last):visible").hide();
	$(".text_act").next().next().show();
	$(".text_act").removeClass("text_act");
	$("#news_slide .csc-frame:visible").addClass("text_act");

	if ( $("#news_slide .csc-frame:last").hasClass("text_act") )
		lastchangeinit();

	if ( $("#news_slide .csc-frame:not(:last)").hasClass("text_act") )
		changeinit();
}

function lastchange(){
	$(".img_act").fadeTo("fast", 1);
	$(".img_act").removeClass("img_act");
	$("#news_slide_img img:eq(0)").addClass("img_act");
	$(".img_act").fadeTo("fast", 0.5);

	$(".text_act").hide();
	$(".text_act").removeClass("text_act");
	$("#news_slide .csc-frame:eq(0)").show();
	$("#news_slide .csc-frame:eq(0)").addClass("text_act");

	timer = setTimeout ("changeinit ()", 1);
}