


var ltie7 = ($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent));

/**
 * Onload
 */
$(document).ready(function() {

	windowAutoResize.init();
	menuLeftBehavior.init();
	menuMsie.init();

});



/*
son of suckerfish menu script from:
http://www.htmldog.com/articles/suckerfish/dropdowns/
 */
var menuMsie = function () {
	function _init() {
		if ($.browser.msie && window.attachEvent)
			window.attachEvent("onload", menuMsie.sfHover);
	}
	function _sfHover(){
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
				this.style.zIndex=200; //this line added to force flyout to be above relatively positioned stuff in IE
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	return {init:_init,sfHover:_sfHover};
}();


var preloader = function() {
	function _preload() {
		for(var i=0; i<arguments.length; i++) {
			jQuery("<img>").attr("src", arguments[i]);
		}
	}
	return {preload:_preload};
}();


var menuLeftBehavior = function() {
	var delais = 4000;
	var stack = $("#back div.image");
	function _init() {
		for(var i=0; i<stack.length; i++) {
			preloader.preload($("img", stack.get(i)).attr("src"));
		}
		setTimeout("menuLeftBehavior.swapElements();", delais);
		menuLeftBehavior.showCaption();
	}
	function _swapElements() {
//		var stack = $("#back div.image");
		if (stack.length > 0) {
			var index =  Math.round(Math.random()*(stack.length-1));
	//		stack.fadeOut();
	//		$(stack.get(index)).fadeIn();
			stack.hide();
			var elem = $(stack.get(index));
			menuLeftBehavior.verticalAlignCenter(elem);
			elem.show();
			$("#left_image_legend").html($(".legend", elem).html());
			setTimeout("menuLeftBehavior.swapElements();", delais);
		}
	}
	function _showCaption() {
		$("#utility").mouseover(function() {
			$("#left_image_legend", this).css("display", "block");
		});
		$("#utility").mouseout(function() {
			$("#left_image_legend", this).hide();
		});
	}
	function _verticalAlignCenter(image) {
		var availableHeight = $("div#utility").height() - $("div#utility div.content").height();
		var heightToDeal = image.height();
		if (availableHeight > heightToDeal) {
			image.css("top", ((availableHeight - heightToDeal) /2)+"px");
		}
	}
	return {init:_init,swapElements:_swapElements,showCaption:_showCaption,verticalAlignCenter:_verticalAlignCenter};
}();


var windowAutoResize = function() {
	function _init() {
		$(window).resize(function () {
			windowAutoResize.resize();
		});
		windowAutoResize.resize();
	}
	function _resize() {
		var elemCorps = $("#articleContent");
		var topHeight = $("#header").height() +35;
		var bottomHeight = $("#footer").height();
		var newHeight = window.innerHeight - topHeight - bottomHeight;
		if ($.browser.msie) {
			newHeight = document.documentElement.clientHeight - topHeight - bottomHeight;
			elemCorps.height(newHeight);
			$("#contentRight").height(newHeight);
		} else {
			elemCorps.height(newHeight>200 ? newHeight : 200);
		}
		menuLeftBehavior.verticalAlignCenter($("#back div.image:visible"));
	};
	return {init:_init,resize:_resize};
}();




