$(document).ready(function () {
	//>> set the mouseover action for the top nav items
	var navs = $('#PageWrapper #TopNav ul li a');
	var lis = $('#PageWrapper #TopNav ul li');
	for(var i = 0; i < navs.length; i++) {
		//>> extract the correct page id from the class name
		var id = -1;
		var cls = lis[i].className.split(' ');
		for(var j = 0; j < cls.length; j++) {
			if(cls[j].indexOf('page-item-') >= 0) {
				id = cls[j].substring(cls[j].indexOf('page-item-') + 10);
				break;
			}
		}
		if(id > -1) {
			navs[i].onmouseover = new Function("TriggerHover('in'," + id + ");");
			navs[i].onmouseout = new Function("TriggerHover('out'," + id + ");");
			navs[i].onclick = function() { ToggleHover(); }
		}
	}
});

function FadeInBody(pageID) {
	if(pageID != 9 && pageID != 7) {
		var body = $('#PageBody');
		body.fadeIn(2000);
	}
}
function FadeOutBody() {
	var body = $('#PageBody');
	body.fadeOut(2000);
}

var tspan_hover_freeze = false;
var tspan_fade_delay = 700;
function TriggerContent(mode,id) {
	if(!tspan_hover_freeze) {
		var content = $('#HoverContainer #hover_' + id);
		$('#HoverContainer div').css('display','none');
		if(content != null) {
			switch(mode) {
				case 'in':
					content.css('display','block');
					break;
				case 'out':
					content.css('display','none');
					break;
			}
		}
	}
}
function ToggleHover() {
	var container = $('#HoverContainer');
	if($('#HoverContainer:animated').length > 0) {
		container.stop(true, true);
	}
	if(container.css('display') == 'block' && tspan_hover_freeze) {
		//>> don't ever hide by clicking
	} else {
		//>> show it
		container.fadeIn(tspan_fade_delay);
		tspan_hover_freeze = true;
	}
}
function TriggerHover(mode,id) {
	TriggerContent(mode,id);
	if(!tspan_hover_freeze) {
		var container = $('#HoverContainer');
		//>> Need to an an animation queue here - don't stack up the animations, just run the last one
		if($('#HoverContainer:animated').length > 0) {
			container.css('display','none');
			container.stop(true, true);
		}
		switch(mode) {
			case 'in':
				container.fadeIn(tspan_fade_delay);
				break;
			case 'out':
				container.fadeOut(tspan_fade_delay);
				break;
		}
	}
}

