$(document).ready(function(){
	init_overlay();
});

function init_overlay() {
	var direction = 0;
	
	clickFunction = function() {
		if (direction == 1 && $(".overlay_right").length) {
			window.location = $(".overlay_right").attr("href");
		}
		
		if (direction == -1 && $(".overlay_left").length) {
			window.location = $(".overlay_left").attr("href");
		}
	}
	
	showFunction = function(event) {
		mouseX = event.pageX - $(".ad_multimedia_imgbig").offset().left;
		center = $(".ad_multimedia_imgbig").width() / 2;
				
		// $(?).length prüft ob das Element ? existiert
		
		if ($(".overlay_right").length) {
			if (mouseX > center || !$(".overlay_left").length) {
				$(".overlay_right").show("slow");
				$(".overlay_left").hide("slow");
				direction = 1;
			}
		}
		
		if ($(".overlay_left").length) {
			if (mouseX < center || !$(".overlay_right").length) {
				$(".overlay_left").show("slow");			
				$(".overlay_right").hide("slow");
				direction = -1;
			}
		}
	};
	
	hideFunction = function(event) { 
		$(".overlay_left").hide("slow");
		$(".overlay_right").hide("slow");
	};

	$(".ad_multimedia_imgbig").css("cursor", "pointer");
	$(".ad_multimedia_imgbig:visible").click(clickFunction);

	
	$(".ad_multimedia_imgbig").mousemove(showFunction);
	
	$(".ad_multimedia_imgbig").hover(null, hideFunction);

}

