/* Variablen */

var timeout	= 200;
var timeout2	= 200;
var mytimeout	= 0;
var opentimer	= 0;
var opentimer2  = 0;
var closetimer	= 0;
var linkerlink	= 0;
var ddmenuitem	= 0;
var timer	= 0;
var aktmenu	= null;
var aktmenu1	= null;

/* Linkes Hauptmenü dynamisch mit JQuery */

function menulinks_open()
{
	menulinks_canceltimer();
	menulinks_close_last();

	aktmenu		= $(this);
	linkerlink = aktmenu.find('.linker_link');
	linkerlink.css('color','#002f5c');
	linkerlink.css('background-color','#ffffff');
	linkerlink.css('border-left','6px solid #d2d833');
	opentimer2	= window.setTimeout(menulinks_open_2, timeout2);
}

function menulinks_open_2 () {
	if(ddmenuitem) {
		ddmenuitem.css('visibility', 'hidden');
   	}
   	if (typeof window.dhtmlStatus != "undefined") {
		window.dhtmlStatus.menu_shown = true;
		window.dhtmlStatus.submenu_shown = true;
   	}
   	linkerlink = aktmenu.find('.linker_link');
	linkerlink.css('color','#002f5c');
	linkerlink.css('background-color','#ffffff');
	linkerlink.css('border-left','6px solid #d2d833');
	ddmenuitem = aktmenu.find('ul').css('visibility', 'visible');

	//Das Untermenü scrollen bei mouseover über dem Untermenü-Layer
	ddmenuitem.mousemove(function(e) {
		var item_height = ddmenuitem.height();
		if (document.documentElement.clientHeight <= ddmenuitem.height()+59) {

			ddmenuitem.animate({top: -59}, { queue:false, duration:1});

			//Menu Top margin
			var s_top = parseInt(ddmenuitem.css('margin-top'));
			var p_bot = parseInt(ddmenuitem.css('padding-bottom'));

			//Berechnen Faktor Verschiebung (20% der Menühöhe)
			var moveidx = parseInt((ddmenuitem.height())/5);

			//Berechnen des top-margin
			//This equation is not the perfect, but it 's very close
			var top_value = Math.round(((s_top+67 - e.clientY)/100) * moveidx / 2);

			if (top_value < -59) {
			if (top_value*-2 < item_height) {
			ddmenuitem.animate({marginTop: top_value, paddingBottom: top_value*-1+document.documentElement.clientHeight-top_value}, { queue:false, duration:200});
			}
			} else {
			ddmenuitem.animate({marginTop: 0, paddingTop: 57}, { queue:false, duration:200});
			}
		}
	});
}

function menulinks_close_last()
{	if(linkerlink) {
	linkerlink.css('color','#ffffff');
	linkerlink.css('background-color','#002f5c');
	linkerlink.css('border-left','6px solid #002f5c');
	}
}

function menulinks_close_all()
{	if(linkerlink) {
		linkerlink.css('color','#ffffff');
		linkerlink.css('background-color','#002f5c');
		linkerlink.css('border-left','6px solid #002f5c');
	}
	if(ddmenuitem) {
		ddmenuitem.css('visibility', 'hidden');
		ddmenuitem.animate({top: 1, marginTop: 0, paddingTop: 0, paddingBottom: 0}, { queue:false, duration:1});
		if (typeof window.dhtmlStatus != "undefined") {
			window.dhtmlStatus.menu_shown = false;
   			window.dhtmlStatus.submenu_shown = false;
   		}
		if ( typeof hideSearchMenu_Callback == 'function') hideSearchMenu_Callback ();
    }
}

function menulinks_timer()
{
	closetimer = window.setTimeout(menulinks_close_all, timeout);
}


function menulinks_canceltimer()
{
	if(closetimer) {
		window.clearTimeout(closetimer);
      	closetimer = null;
	}
	if(opentimer2) {
		window.clearTimeout(opentimer2);
      	opentimer2 = null;
	}
}

function scrollmenu()
{

}


show_mainmenu = function () {
	document.getElementById('menu').style.display='block';
	window.dhtmlStatus.menu_shown = true;
	window.dhtmlStatus.submenu_shown = false;
}

$(document).ready(function()
{
	$('ul#menulinks li').bind('mouseover', menulinks_open);
   	$('ul#menulinks').bind('mouseout', menulinks_timer);
	$('a.linker_link').click(function () {return false});
});

document.onclick = menulinks_close_all;


