/*
* Miscellaneous functions used in main page (jQuery related)
* Fier Concept & Design - 
*
* Project: Staatsbosbeheer jaarverslag
* Author: Gest
* Version: february 2010
*/

$(document).ready(function() {

    initMenu();

    initFancyBox();

    try {

        setLeftOverlayHeight();

        //var windowheight = jQuery('window').height() - 50;
        //jQuery('#myMap').css({height: windowheight + 'px'});

        $(window).resize(function() {
            setLeftOverlayHeight();
        });

    } catch (e) { alert(e);  }

});

function setLeftOverlayHeight() {
    var elem = $(".map-left-overlay");
    var mapHeight = $("#myMap").height();
    var menuHeight = $(".menu-container").height();
    var targetHeight =  mapHeight - menuHeight - 20;
    elem.css({ 'height': targetHeight, 'min-height': targetHeight });
    /*
    var currentTallest = 0;
    $(this).children().each(function(i) {
        if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
    });
    if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
    // for ie6, set height since min-height isn't supported
    if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({ 'height': currentTallest }); }
    $(this).children().css({ 'min-height': currentTallest }); 
    */
}

function initFancyBox() {
    if (!($.browser.msie && $.browser.version == 6.0)) {
        $("a.iframe").fancybox({
            'hideOnContentClick': true,
            'overlayColor': '#000000',
            'overlayOpacity': 0.7,
            'width': 787,
            'height': 520,
            'padding': 0
        });
    }
  
}

function closeFancyBox() {
    $('#fancybox-close').trigger("click");    
}

function showWelcomePage() {
    if (!($.browser.msie && $.browser.version == 6.0)) {
        $('#welcome-link').trigger('click');
    }
}


function initMenu() {
    var timeout = 750;
    $(".menu-item")
		.mouseover(function() {
		    // Hide all other submenus
		    $(this).siblings().find('.submenu').hide();

		    // Show current submenu
		    $(this).find('.submenu').show();

		    t = $(this).find('.submenu').data('timer');
		    if (t)
		        clearTimeout(t);		    

		    $(this).addClass("active");

		    $(this).prev().removeClass("margin-right");
		})
		.mouseout(function() {
		    var elem = $(this).find('.submenu');
		    //elem.hide();
		    
		    t = setTimeout(function() {
		        elem.hide(); // hide  submenu('s)

		        }, timeout
		    );

	        $(this).removeClass("active");
	        $(this).prev().addClass("margin-right");
		        		    
		    elem.data('timer', t);		    
		});

    /*
    $(".sidebarsub").hover(function() {
        t = $(this).data('timer');
        if (t)
            clearTimeout(t);
    }, function() {
        t = setTimeout(function() {
            $(this).hide();
        },
							timeout
						);
        $(this).data('timer', t);
    });
    */
}