$(document).ready(function() {

	$("#maincontent_gallery .slide img").hide();	

	init();
	
	$("#next").click(function(){
		clearInterval(showSlideShow);
		$("#pause").hide();
		$("#play").show();
		slideShow("m_active");
		return false;
	});
	$("#prev").click(function(){
		clearInterval(showSlideShow);
		$("#pause").hide();
		$("#play").show();
		slideShow("m_prev");
		return false;
	});
	$("#pause").click(function(){
		clearInterval(showSlideShow);
		$("#pause").hide();
		$("#play").show();
		return false;
	});
	$("#play").click(function(){
		init();
		$("#play").hide();
		$("#pause").show();
		return false;
	});
	
	

});

function init(){

	slideShow("m_active");
	showSlideShow = setInterval( 'slideShow("m_active")', 4000 );

}

function slideShow(modus){
	
	var active = $("#maincontent_gallery .slide img.active").next();
	if (active.length == 0){ var active = $("#maincontent_gallery .slide img:first"); };
	
	var next = $(active);
	if (next.length == 0){ var next = $("#maincontent_gallery .slide img:first"); };
	
	var prev = $(active).prev();
	if (prev.length == 0){ var prev = $("#maincontent_gallery .slide img:last"); };
	
	$("#maincontent_gallery .slide img").animate({"opacity": "hide"}, { "duration": "slow" });
	
	if( modus == "m_active" ){
		//$("#maincontent_gallery .slide img").animate({"opacity": "hide"}, { "duration": "slow" });
		$(prev).removeClass("active");
		$(active).addClass("active");
		$(active).animate({"opacity": "show"}, { "duration": "slow" });
		//$(prev).removeClass("active");
		//$(active).addClass("active");
	}else if( modus == "m_next" ){
		
	}else if( modus == "m_prev" ){
		if( $(prev).prev().length == 0 ){
			
			$("#maincontent_gallery .slide img:last").animate({"opacity": "show"}, { "duration": "slow" });
		}else{ 
			$(prev).prev().show();
			//alert("jetzt");
		}
		if( $(next).prev().length == 0 ){ $("#maincontent_gallery .slide img").removeClass("active"); }else{ $(next).prev().removeClass("active"); }
		if( $(prev).prev().length == 0 ){ $("#maincontent_gallery .slide img:last").addClass("active"); }else{ $(prev).prev().addClass("active"); }	
	}
	
}





