var HEIGHT_ONE = 40
var HEIGHT_TWO = 90
var HEIGHT_THREE = 95
var DEFAULT_HEIGHT = 120

var MARGIN_ONE = -40
var MARGIN_TWO = -90
var MARGIN_THREE = -95
var DEFAULT_MARGIN = -120


$(document).ready(function() {
	var allItems = $("#leftSide>li>ul")
	hideMenu(allItems)
	$("#leftSide>li:not(.divider)").hover(
		function() {
			var item = $(this).find("ul")
			var itemHeight = item.css("height")
			var newItemHeight = adjustMenuHeight(item)
			var newItemMargin = adjustMenuMargin(item)
			if (itemHeight == '0px') {
				hideMenu(allItems)
				item.animate({ 
    				opacity: "show",
					marginTop: newItemMargin, 
    				height: newItemHeight
        		}, 600);
        	} 
		},
  		function() {
  			return false
  		}
  	);
});

$(document).ready(function() {
	$("#leftSide").hover(
		function() {
			return false
		},
		function() {
			var allItems = $("#leftSide>li>ul")
			hideMenu(allItems)
		}
	);
});	

$(document).ready(function() {
	$("#leftSide>li>ul").hover(
		function() {
			return false
		},
		function() {
			var item = $(this)
			var itemHeight = item.height()
			if (itemHeight <= 120) {
				hideMenu(item)
			}
		}
	);
});

function hideMenu(obj) {
	$(obj).animate({ 
		opacity: "hide",
		marginTop: "0px", 
	    height: "0px"
	}, 350); 
}

function adjustMenuHeight(obj) {
	var objCount = parseInt($(obj).find("li").length)
	var result = ''
	switch(objCount) {
		case 1: 
			result = HEIGHT_ONE
			break;
		case 2: 
			result = HEIGHT_TWO
			break;
		case 3: 
			result = HEIGHT_THREE
			break;
		default: 
			result = DEFAULT_HEIGHT
			break;
	}
	return result 
}

function adjustMenuMargin(obj) {
	var objCount = parseInt($(obj).find("li").length)
	var result = ''
	switch(objCount) {
		case 1: 
			result = MARGIN_ONE
			break;
		case 2: 
			result = MARGIN_TWO
			break;
		case 3: 
			result = MARGIN_THREE
			break;
		default: 
			result = DEFAULT_MARGIN
			break;
	}
	return result 
}

