$(function() {

    resize ();

    centerOverlayContainer ();
    $(window).resize (function(){
	centerOverlayContainer();
	resize();
    });

    $(document).keydown(function(e) {

        if (e.keyCode == 27)
            {
                if ($("#overlayContainer").is(":visible"))
                {                    
                    $("#overlay").fadeOut(1000);
                    $("#overlayContainer").fadeOut(500);
                }

                    
            }
    })

    $(".navigationItemWrapper").hover( function () {
	    var offset = $(this).offset ();
	    var width = $(this).width ();

	    $(this).find (".subMenuContainer").css ("left", offset.left).css ("width", width).fadeIn ();
    }, function () {
	    $(this).find (".subMenuContainer").fadeOut ();
    });

    $(".searchInput").focus(function() {
       if (this.value == "Suchbegriff")
       {
           $(this).val("");
       }
    });
    $(".searchInput").blur(function() {
       if (this.value == "")
       {
           $(this).val("Suchbegriff");
       }
    });

    $(".subnavigationItemWrapper").hover( function () {
	    var offset = $(this).offset ();
            var position = $(this).position ();
	    var width = $(this).width ();
            var height = ($(this).height () + 6);

            //alert("height:" + height + "\noffset.top:" + offset.top + "\nposition.top:" + position.top);

	    $(this).find (".subSubMenuContainer").css ("top", position.top - height).css ("left", width).css ("width", width).fadeIn ();
    }, function () {
	    $(this).find (".subSubMenuContainer").fadeOut ();
    });


    $(".searchInput").click ( function () {
	    $("#searchOverlay").toggle ("fast");
    });
	
});

function centerOverlayContainer ()
{
	var overlay = $("#overlayContainer");
	overlay.css ("left", ($(window).width ()/2)-(overlay.outerWidth ()/2));
}

function resize ()
{
	var dHeight = $(document).height();
	var wHeight = $(window).height();

	if ($.browser.msie)
	{
		newHeight = wHeight-241;
	}
	else
	{
		newHeight = wHeight-211;
	}

	$("#contentContainer").height (newHeight);
	if (wHeight > dHeight)
	{
		//if (!$.browser.msie)
		//{
		//$("#positionContainer").height (dHeight+121);

			//alert (wHeight);
			//$("#rightContent").height (wHeight-291);
		//}
	}
}