var submenu_size = new Array();
var box_size = new Array();
$(document).ready(function(){

	$("#main_menu li .submenu div").each(
		function(i) {
			submenu_size[i] = $(this).height();
		}
	);
	
	$("#main_menu li:has(.submenu div)").hover(
		function() {
			var i = $("#main_menu li:has(.submenu div)").index(this);
			$(this).find(".submenu div").css({overflow:'hidden', height:'0px', display:'block'}).stop().animate({height:submenu_size[i]+'px'},'fast');
		},
		function() {
			var i = $("#main_menu li:has(.submenu div)").index(this);
			$(this).find(".submenu div").stop().animate({height:'0px'},'fast');
		}
	);
	
	
	$("#info_box_wrapper .box").each(
		function(i) {
			box_size[i] = $(this).height();
			$(this).css({height:33+'px'});
		}
	);
	
	$("#info_box_wrapper .box").hover(
		function() {
			var i = $("#info_box_wrapper .box").index(this);
			$(this).stop().animate({top:'-150px',height:box_size[i]+'px'},'fast');		
		},
		function() {
			var i = $("#info_box_wrapper .box").index(this);
			$(this).stop().animate({height:33+'px', top:'0'},'fast');
		}
	);
	
	var x = 660;
	var y = 605;	
	var box = $(".karte .map_box").map(function () {
	
		var position_left = $(this).position().left;
		var position_top = $(this).position().top;
		var box_width = $(this).find(".inhalt").outerWidth();
		var box_height = $(this).find(".inhalt").outerHeight();
		var box_2 = $(this).find(".inhalt");
		var postion_x;
		var postion_y;
					
		if(box_width + position_left >= x && box_height + position_top >= y) {
			postion_x = 15 - box_width;
			postion_y = 15 - box_height;
			
			$(this).find(".inhalt_head").clone().appendTo(box_2);
			$(this).find(".inhalt_head:first").remove();
			
			var ecke = '<div style="position:absolute; left:18px; bottom:0px; width:18px; height:18px;"><img src="/images/karte-box-ecke-r-u.gif" style="width:18px; height:18px;" alt="" /></div>';
			$(ecke).appendTo(box_2);
		} else if(box_width + position_left >= x && box_height + position_top < y) {
			postion_y = 15;
			postion_x = 0 - box_width;
			var ecke = '<div style="position:absolute; left:300px; top:-1px; width:18px; height:18px;"><img src="/images/karte-box-ecke-r-o.gif" style="width:18px; height:18px;" alt="" /></div>';
			$(ecke).appendTo(box_2);
		} else if(box_width + position_left < x && box_height + position_top >= y) {
			postion_x = 30;
			postion_y = 15 - box_height;	
			var ecke = '<div style="position:absolute; left:-18px; bottom:0px; width:18px; height:18px;"><img src="/images/karte-box-ecke-l-u.gif" style="width:18px; height:18px;" alt="" /></div>';
			$(ecke).appendTo(box_2);
		} else {
			postion_x = 30;
			postion_y = 15;	
			var ecke = '<div style="position:absolute; left:-18px; top:-1px; width:18px; height:18px;"><img src="/images/karte-box-ecke-l-o.gif" style="width:18px; height:18px;" alt="" /></div>';
			$(ecke).appendTo(box_2);
		}
		
		$(this).find(".inhalt").css({'left':postion_x + 'px','top':postion_y + 'px'});
	});
	
	$(".karte .map_box").hover(
		function () {
			$(this).find(".inhalt").stop(true,true).fadeIn(1000);
		},
		function () {
			$(this).find(".inhalt").stop(true,true).fadeOut(300);
		}
	);
});
