$(document).ready(function(){
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
		$('.naviebene').css("display", "block");
//		$('#login_container').css("display", "block");
//		$('#sprachwahl_container').css("display", "block");
		$('.pngImg').ifixpng();
		$('.login_container').ifixpng();
		$('.naviebene').css("display", "none");
//		$('#login_container').css("display", "none");
//		$('#sprachwahl_container').css("display", "none");
	}
	init_mousemove();
	
	footerpos();
	window.onresize = footerpos;
	
	$('.subnavi').mouseover(function(){
		var parent = $(this).attr("id").replace(/^subnavLn/, "subnavEl");
		$(this).css("backgroundColor", "transparent");
		$('#' + parent).css("backgroundColor", "#ff9900");
		$('#' + parent).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/bullet_over.gif)");
		
	});
	$('.subnavi').mouseout(function(){
		var parent = $(this).attr("id").replace(/^subnavLn/, "subnavEl");
		$('#' + parent).css("backgroundColor", "#fff");
		$('#' + parent).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/bullet.gif)");
	});
	
	$('.schnellzugriff-li>a').mouseover(function(){
		var parent = $(this).attr("id").replace(/^schnellzugriffl/, "schnellzugriff");
		$("#" + parent).css("backgroundColor", "#ff9900");
		$("#" + parent).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/bullet_white.gif)");
		$(this).css("color", "#fff");
		
	});
	$('.schnellzugriff-li>a').mouseout(function(){
		var parent = $(this).attr("id").replace(/^schnellzugriffl/, "schnellzugriff");
		$("#" + parent).css("backgroundColor", "transparent");
		$("#" + parent).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/bullet_orange.gif)");
		$(this).css("color", "#2265AC");
	});
	
	if ($('#scroller>div').length > 0) {
		while ($('#scroller>div').length < 12) {
			$('#scroller>div').each(function(){
				$(this).clone().appendTo('#scroller');
			});
		}
	}
	
	
//	$('.BESuperPrint').click(function(){
//		alert(1);
//	})
	
	/*
	$('#right_content').css("cursor", "pointer").click(function(){
		window.location = "http://www.herma.de/eao/";
	});
	*/
});

	function footerpos() {
		var fpos = 620;
		var pos = $('#pagefooter').offset();
		if (pos.top < fpos) {
			$('#pagefooter').css("bottom", "auto");
			$('#pagefooter').css("top", fpos + "px");
		}
		else{
			$('#pagefooter').css("top", "auto");
			$('#pagefooter').css("bottom", "0px");
		}
	}

	function init_mousemove() {
    	if(document.layers) document.captureEvents(Event.MOUSEMOVE);
   		document.onmousemove =	dpl_mouse_pos;
	}

	var hideMe = false;
	var xPos = 0;
	var yPos = 0;
	function dpl_mouse_pos(e) {

    	var ua = navigator.userAgent;
		if(ua.indexOf("MSIE") >=0) { 
		
			xPos = navigator.userAgent.indexOf('MSIE') == -1 ? mouse.pageX : window.event.clientX;
			yPos = navigator.userAgent.indexOf('MSIE') == -1 ? mouse.pageY : window.event.clientY;
		} else {
			
			xPos = e? e.pageX : window.event.x;
			yPos = e? e.pageY : window.event.y;
		}
    	document.getElementById('ypos').value = yPos;
    	document.getElementById('xpos').value = xPos;
    	
    	var border = 10;
    	
    	var offset1 = $('#menu1st').offset();
    	var offset2 = $('#submenu').offset();
    	var height1 = $('#menu1st').outerHeight();
    	var height2 = $('#submenu').outerHeight();
    	
    	var mTop = Math.min(offset1.top, offset2.top);
    	var mBottom = Math.max(mTop + height1, mTop + height2);
    	var mLeft = offset1.left;
    	var mRight = offset2.left + $('#submenu').outerWidth();
    	
    	    mLeft   -= border;
    	    mTop    -= border;
    	    mRight  += border;
    	    mBottom += border;
    	
    	if (xPos < mLeft || xPos > mRight || yPos < mTop || yPos > mBottom) {
			hideMe = window.setTimeout("hideMenu()", 500);
    	}
	}
	
	function moveLeft() {
		if ($("#scroller > .bottomElements:first").is(":animated") || $("#scroller > .bottomElements:last").is(":animated")) {
			return;
		}
		lastIsFirst();
		$("#scroller > .bottomElements:first").animate({
			width: "189px"
		}, 400);	
		$('.BESuperPrint').click(function(){
			alert(1);
		})
	}
	function moveRight() {
		if ($("#scroller > .bottomElements:first").is(":animated") || $("#scroller > .bottomElements:last").is(":animated")) {
			return;
		}
		$("#scroller > .bottomElements:first").animate({
			width: "0px"
		}, 400);
		window.setTimeout("firstIsLast()", 400);
	}
	function firstIsLast() {
		var html = $("#scroller > .bottomElements:first").html();
		$("#scroller > .bottomElements:first").remove();
		$("#scroller").append("<div class='bottomElements'>" + html + "</div>");
	}
	function lastIsFirst() {
		var html = $("#scroller > .bottomElements:last").html();
		$("#scroller > .bottomElements:last").remove();
		$("#scroller").prepend("<div class='bottomElements' style='width:0px;'>" + html + "</div>");
	}

	
	var slideMax = 126; // maximale Höhe von aktivem element im hauptmenü
	var subMax   = $('#left_content').outerHeight(); // Submenü darf nicht über diese Kante rausragen
	
	var menuActive = -1;
	function menuOvr(id) {
		window.clearTimeout(hideMe);
		if (id != menuActive) {
			if (menuActive != -1) {
				$("#menuObj" + menuActive).css("height", "22px");
				$("#menuObj" + menuActive).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/blank.png)");
				$("#menuObj" + menuActive).ifixpng();
				$("#ebene" + menuActive).hide();
			}
			
			$('#submenu').show();
			$("#ebene" + id).show();
			var h = $('#submenu').outerHeight();
			
			var h2 = h > slideMax ? slideMax : h;
			h2 -= 8;
			$('#menuObj' + id).css("height", h2 + "px");
			$("#menuObj" + id).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/bg" + id + ".png)");
			$("#menuObj" + id).ifixpng();
			
			var pos = $('#menuObj' + id).offset();
			var t = pos['top'];
			
			if (t + h > subMax) {
				t = subMax - h;
				t = t < 0 ? 0 : t;
			}
			$("#submenu").css("top", t + "px");
			
			menuActive = id;
		}
		
		
	}
	
	function hideMenu() {
		if (menuActive != -1) {
	    	var border = 10;
	    	
	    	var offset1 = $('#menu1st').offset();
	    	var offset2 = $('#submenu').offset();
	    	var height1 = $('#menu1st').outerHeight();
	    	var height2 = $('#submenu').outerHeight();
	    	
	    	var mTop = Math.min(offset1.top, offset2.top);
	    	var mBottom = Math.max(mTop + height1, mTop + height2);
	    	var mLeft = offset1.left;
	    	var mRight = offset2.left + $('#submenu').outerWidth();
	    	
	    	    mLeft   -= border;
	    	    mTop    -= border;
	    	    mRight  += border;
	    	    mBottom += border;
	    	
	    	if (xPos < mLeft || xPos > mRight || yPos < mTop || yPos > mBottom) {
				$("#menuObj" + menuActive).css("height", "22px");
				$("#menuObj" + menuActive).css("backgroundImage", "url(/fileadmin/Herma/Templates/images/startseite/blank.png)");
				$("#menuObj" + menuActive).ifixpng();
				$("#ebene" + menuActive).hide();
				menuActive = -1;
	    	}
		}
	}
	
	function followLink(el) {
		var url = findElement(el, "A");
		if( $(el).find('a:first').length ) {
			var target = $(el).find('a:first').attr('target')
		}
		var blank = typeof(target) != "undefined";
		if (url && !blank) {
			window.location = url;
		}
		else if (url) {
			window.open(url, "_blank", "dependent=no,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes")
		}
	}
	function findElement(el, name) {
		var match = false;
		for (var i = 0; i < el.childNodes.length; i++) {
			if (el.childNodes[i].nodeName == name) {
				match = el.childNodes[i];
			}
			else if (!match && el.childNodes[i].childNodes.length > 0) {
				match = findElement(el.childNodes[i], name);
			}
		}
		return match;
	}

