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

var menuHeight = '165px';
var menuWidth = '154px';

function doaction(parentId) {
	clearTimeout(intval);
	if (menuState==0 && cursorLoc == 1) {
		animActive = 1;
		menuState=1; // open menu
		$('#'+parentId+' ul li').css({ display: "none" })
		$('#'+parentId+' ul').css({ display: "block" })
		.animate({height: menuHeight}, 400, '', function() {
			animActive = 0;
			if (cursorLoc==0) { doaction(parentId); }
			$(this).children("li").css({ display: "block" });
		}); 
	} else if (menuState==1 && cursorLoc == 0) {
		animActive = 1;
		menuState = 0;
		$('#'+parentId+' ul')		
		.animate({height: "0px"}, 100, '', function(){ 
			$(this).css({ display: "none" });
			animActive = 0;
			if (cursorLoc==1) { doaction(parentId); }
		}).children("li").css({ display: "none" });
	}
}
	
$(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);
		}
	});	
});

function initgallery() {
	$('a').each(function() {
		if (this.getAttribute('href') && (this.getAttribute('rel') == 'slide')){
			this.onclick = function () {
				$("#slide").toggle();
				$("#slideimg").html('<img src="'+this.href+'" width="450" height="450" alt="'+this.getAttribute("title")+'" title="'+this.getAttribute("title")+'" />');
				$("#slidecaption").html("<em>"+this.getAttribute("title")+"</em>");
				setTimeout("$('#slide').show('slow')", 2000);
				return false;
			}
		}
	});
	
	var allThumbs = $("#thumbs a").get();
	thumbLength = allThumbs.length;
	tOffset = 0;
}