

var ___BASEPATH = '/';
if (typeof BASE_PATH === 'undefined') {
	// ok 
} else {
	___BASEPATH = BASE_PATH + '/';
}

var overlappingMenu = ($.url.param("ms") == "ol") || (!(typeof XMENU_OVERLAPPING_MENU === 'undefined'));
var menuAnimateClose =  ($.url.param("mc") == "2");
var menuInitiallyClosed = ($.url.param("mc") == "1") || ((!(typeof XMENU_INIT_CLOSED === 'undefined')) && (!menuAnimateClose));

var xmenuWidth = "180";
var xmenuWidthInPx = xmenuWidth + "px";
var xmenuWidthInPxNegative = "-" + xmenuWidthInPx;

function markMenuClosed() {
    $("#xmenu_topMenuImage").html('<div>&raquo;</div><div class="spacer">&nbsp;</div><div>&raquo;</div>');
    $("#xmenu_openCloseIdentifier").hide();
    pulsateMenuTab(3);
}

function pulsateMenuTab(times) {
	for (var i = 0; i < times; ++i) {
		$("#xmenu_openCloseWrap").fadeOut(200).fadeIn(200);
	}
}

function hideMenuTab() {
	$("#xmenu_openCloseWrap").fadeOut(200);
}

function showMenuTab() {
	$("#xmenu_openCloseWrap").fadeOut(200);
}

function closeMenu(closeDelay) {
    $("#xmenu_wrap").fadeIn().delay(closeDelay).animate({
        left: xmenuWidthInPxNegative
        }, 
        {duration: 500,
        	complete: markMenuClosed
        }
        
    	);
    if (!overlappingMenu) {
    	$("#page_content_wrapper").fadeIn().delay(closeDelay).animate({
    		"padding-left": "0px"
        	}, 500 );
    }
}

if (menuInitiallyClosed) {
	$(document).ready(function() {
		$("#xmenu_openCloseIdentifier").hide();
        $("#xmenu_topMenuImage").html('<div>&raquo;</div><div class="spacer">&nbsp;</div><div>&raquo;</div>');
        $("#page_content_wrapper").css("padding-left", "0");
		$("#xmenu_wrap").css('left', xmenuWidthInPxNegative); 
		$("#xmenu_wrap").show();
	    pulsateMenuTab(3);
	});
} else if (menuAnimateClose) {
	$(document).ready(function() {
		var docHeight = $(document).height();
		$("#xmenu_wrap").css("height", docHeight);  
		$("#xmenu_wrap").show();
		closeMenu(700);
	});
} else {
	$(document).ready(function() {
		$("#xmenu_wrap").show();
	});
}

$(window).resize(function() {
	var docHeight = $(document).height();
	$("#xmenu_wrap").css("height", docHeight);  
});

$(document).ready(function() {
	var docHeight = $(document).height();
	$("#xmenu_wrap").css("height", docHeight);
	if (overlappingMenu) {
		$("#page_content_wrapper").css("padding-left", "0");
	}
	
    $(".xmenu_topMenuAction").click( function() {
        if ($("#xmenu_openCloseIdentifier").is(":hidden")) {
            $("#xmenu_wrap").animate({
                left: "0px"
                }, 500 );
            if (!overlappingMenu) {
            	$("#page_content_wrapper").animate({
            		"padding-left": xmenuWidthInPx 
            		}, 500 );
            }
            //$("#xmenu_topMenuImage").html('<img src="' + ___BASEPATH + 'structure/close.png"/>');
            $("#xmenu_topMenuImage").html('<div>&laquo;</div><div class="spacer">&nbsp;</div><div>&laquo;</div>');
            $("#xmenu_openCloseIdentifier").show();
            hideMenuTab();
        } else {
            $("#xmenu_wrap").animate({
                left: xmenuWidthInPxNegative
                }, 500 );
            if (!overlappingMenu) {
            	$("#page_content_wrapper").animate({
            		"padding-left": "0px"
                	}, 500 );
            }
            //$("#xmenu_topMenuImage").html('<img src="' + ___BASEPATH + 'structure/open.png"/>');
            $("#xmenu_topMenuImage").html('<div>&raquo;</div><div class="spacer">&nbsp;</div><div>&raquo;</div>');
            $("#xmenu_openCloseIdentifier").hide();
            pulsateMenuTab(3);
        }
    }); 
});
