var intval = '';

var menuState = 0;
// 0 - Closed State
// 1 - Open State

var cursorLoc = 0;
// 0 - Cursor out of active area
// 1 - Cursor in active area

var animActive = 0;
// 0 - Animation not happening
// 1 - Animation happening

function doaction(parentId) {
	clearTimeout(intval);
	if (menuState==0 && cursorLoc == 1) {
		animActive = 1;
		menuState=1; // open menu
		$('#'+parentId+' ul').css({ display: "block" })
		.animate({width: "160px"}, 100, '', function(){ 
			$(this).animate({height: "156px"}, 200, '', function() {
		 		animActive = 0;
				if (cursorLoc==0) { doaction(parentId); }
		 	}); 
		});	
	} else if (menuState==1 && cursorLoc == 0) {
		animActive = 1;
		menuState = 0;
		$('#'+parentId+' ul')
		.animate({height: "0px"}, 100, '', function(){ $(this).animate({width: "0px"}, 200, '', function(){ 
			$(this).css({ display: "none" });
			animActive = 0;
			if (cursorLoc==1) { doaction(parentId); }
		}); } );
	}
}
	
$(document).ready(function(){
						   
	$(".external").click(function(){
			window.open($(this).href); return false;					  
	  });
	
	$("#corporate-links").hover(function() {
		cursorLoc = 1;
		if (animActive==0) {
			clearTimeout(intval);
			intval = self.setTimeout('doaction("corporate-links")',200);
		}
	},function() {
		cursorLoc = 0;
		if (animActive==0) {
			clearTimeout(intval);
			intval = self.setTimeout('doaction("corporate-links")',400);
		}
	});	
});