var HEIGHT_ONE = 40
var HEIGHT_TWO = 70
var HEIGHT_THREE = 95
var HEIGHT_FOUR = 120
var DEFAULT_HEIGHT = 159

var MARGIN_ONE = -40
var MARGIN_TWO = -70
var MARGIN_THREE = -95
var MARGIN_FOUR = -120
var DEFAULT_MARGIN = -159


$(document).ready(function() {
	var allItems = $("#rightSide>li>ul")
	hideMenu(allItems)
	var subItems = $("#rightSide>li>ul>li>ol")
	hideSubMenu(subItems)

	$("#rightSide>li:not(.divider):not(.eyes)").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
  		}
  	);
	
	$("#rightSide>li:not(.divider)").hover(
		function() {
			var siblingItems = $('li.eyes').children('ul.rollover');
			hideMenu(siblingItems)
			if($(this).hasClass('eyes')){
				hideMenu(allItems)	
				hideSubMenu(subItems)
					$('li.mascara').parent('ul.rollover').animate({ 
    				opacity: "show",
					marginTop: -120, 
    				height: 120
        		}, 600);
			}
			
			},
  		function() {
  			return false
  		}
  	);
	
});



/*$(document).ready(function() {
						  // var allItems = $("#rightSide>li>ul")
	var subItems = $("#rightSide>li>ul>li>ol")
	hideSubMenu(subItems)
	$("#rightSide>li>ul>li.mascara").hover(
		function() {
			var subItem = $(this).find("ol")
			var subitemHeight = subItem.css("height")			
			
			if (subitemHeight == '0px') {
				//hideMenu(allItems)	
				hideSubMenu(subItems)
				subItem.animate({ 
    				opacity: "show",
					marginLeft: 150, 
    				height: 60
        		}, 600);			
				
        	} 
		},
  		function() {
  			return false;		
  		}
  	);
});*/

$(document).ready(function() {
	$("#rightSide").hover(
		function() {
			return false
		},
		function() {
			var allItems = $("#rightSide>li>ul")
			var subItems = $("#rightSide>li>ul>li>ol")
			hideMenu(allItems)
			hideSubMenu(subItems)
		}
	);
});	

$(document).ready(function() {
	$("#rightSide>li>ul").hover(
		function() {
			return false
		},
		function() {
			var item = $(this)
			var itemHeight = item.height()
			if (itemHeight <= 120) {
				hideMenu(item)
			}
		}
	);
	
	$("#rightSide>li>ul>li").hover(
		function() {
			return false
			},
		function() {
			var item = $(this).find('ol')
			var itemHeight = item.height()
			if (itemHeight <= 100) {
				hideSubMenu(item)
			}
		});
});

function hideMenu(obj) {
	$(obj).animate({ 
		opacity: "hide",
		marginTop: "0px", 
	    height: "0px"
	}, 350); 
}


function hideSubMenu(obj) {
	$(obj).animate({ 
		opacity: "hide",
		marginLeft: "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;
		case 4: 
			result = HEIGHT_FOUR
			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;
		case 4: 
			result = MARGIN_FOUR
			break;
		default: 
			result = DEFAULT_MARGIN
			break;
	}
	return result 
}


