$(document).ready(function() {
    
    function resizeColumns() {
	       if(! $.browser.mobile) {
	           $('#body-wrap').height('auto');
	           $('#callouts').height('auto');
            var newHeight = Math.max($('#body-wrap').height(), $('#callouts').height());
	           $('#body-wrap').height(newHeight);
	           $('#callouts').height(newHeight);
        }
    }
    
    function setupDependentMenus() {
        $('ul#page-menu li ul').each(function() {
            var $list = $(this);
            var $parent = $list.parent('li');
            $list.appendTo(document.body);
            $list.addClass('submenu')
            
            var hovercount = 0;
            
            $parent.hover(
                function(eventObject) {
                    $list.css("top",($parent.offset().top+26)+"px");
                    $list.css("left",$parent.offset().left+"px");
                    $list.css("display", "block");
                    hovercount++;
                },
                function(eventObject){
                    hovercount--;
                    setTimeout(function() {
                    if(hovercount == 0) {
                        $list.css("display", "none");
                    }},1);
                });

                $list.hover(
                    function(eventObject) {
                        hovercount++;
                    },
                    function(eventObject){
                        hovercount--;
                        if(hovercount == 0) {
                            $list.css("display", "none");
                        }
                    });

        });
    }

    $(window).resize(resizeColumns);
    setTimeout(function() {resizeColumns()}, 15);
    setupDependentMenus();
	
	var pp = $(".gallery a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',theme:'light_square', slideshow:30000});
	$('.gallery-trigger').click(function(evt) {
		evt.preventDefault();
		$(".gallery-hidden a[rel^='prettyPhoto']:first").click();
	});
	
});
