/* Make the nav position fixed, but only if it fits in the browser window.
Tested in IE7 and Firefox, exclludes IE5.5. To work in IE6 or higher, 
the browser should be forced to standards mode by adding a doctype declaration to the html page, eg:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
*/


neoarchaic.Taichi = function(){
	//Check for ie 5.5 and exclude it from the script
	if (!document.getElementById){
		return;
	}

	var ver=navigator.appVersion.split("MSIE")
	ver=parseFloat(ver[1])
	this.supIE = (ver >=6)
	this.nav = null;
	this.footer = null;
	this.header = null;
	this.content = null;
	this.menu = null;
	this.headerheight = null;
	this.width = 1000;
	this.navheight =50;
	
	//Hide elements with a noscript class - if JavaScript is not present, these elements will be displayed, otherwise they will remain hidden.
	document.write ("<style id='noscript'> .noscript{display:none;} </style>");
	//register window events
	this.addLoadEvents();
	this.addEvent(window, "resize", "fixNav");
	this.addEvent(window, "scroll", "onscroll");
}

neoarchaic.protoObj = {
	className: "Taichi",
	
	init: function(){
		if (this.isInit) return;
		this.isInit = true;
		this.nav = document.getElementById("nav");
		this.footer = document.getElementById("footer");
		this.header = document.getElementById("header");
		this.content = document.getElementById("content");
		this.menu = document.getElementById("menu");
		this.subnav = document.getElementById("subnav")
		this.fixNav();
		//window.scroll(0,0);
		var me = this;
		setTimeout(function () { me.checkFlash(); }, 500);
	},
	
	checkFlash: function(){
		if (neoarchaic.objswap != undefined){
			if (!neoarchaic.objswap.hasFlash){
				this.menu.style.display = "block";
				return false;
			}
		}
		return true;
	},
	
	//Make the nav position fixed, but only if it fits in the browser window.
	fixNav: function (){
		//alert (this.className)
		if (!this.nav || document.body.className == "home"){
			return;
		}
		this.headerheight = this.header.clientHeight;
				
		var dif;
		var footerHeight = this.footer.clientHeight
		var height = this.nav.clientHeight + footerHeight + this.navheight ;
		if (window.innerHeight){
			//Firefox  etc.
			dif = Math.max(0, (window.innerWidth/2 - this.width/2))
			//hdif = Math.max(0, ((window.innerHeight-footerHeight)/2 - this.nav.clientHeight/2));
			if (window.innerHeight >= height){
				this.fixElements();
			}else{
				this.unfixElements();
			}
			this.centerElements(dif);
		} else if (document.body.clientHeight && this.supIE){
			//Windows
			dif = Math.max(0, (document.body.clientWidth/2 - this.width/2))
			//hdif = Math.max(0, ((document.body.clientHeight-footerHeight)/2 - this.nav.clientHeight/2));
			if (document.body.clientHeight >= height){
				this.fixElements();
			}else{
				this.unfixElements();
			}
			this.centerElements(dif);
		}
		this.menulink = document.getElementById("menulink");
		this.addEvent(this.menulink, "click", "toggleMenu");
	},
	
	toggleMenu: function(){
		if (this.menu.style.display == "block"){
			this.menu.style.display = "none";
		}else{
			this.menu.style.display = "block";
		}
	},

	fixElements:  function(){
		this.nav.style.position = "fixed";
		this.footer.style.position = "fixed";
		this.header.style.position = "fixed";
		this.content.style.paddingBottom = String(this.footer.clientHeight) + "px"
		this.content.style.paddingTop = String(this.header.clientHeight) + "px";
	},
	
	unfixElements: function(){
		this.nav.style.position = "absolute";
		this.footer.style.position = "relative";
		this.header.style.position = "relative";
		this.content.style.paddingBottom = "0px"	
		this.content.style.paddingTop = "0px";
	},
	
	centerElements: function(dif){	
		this.content.style.left = dif +"px";
		this.header.style.left = dif +"px";
		this.footer.style.left = dif +"px";
		this.nav.style.left = dif + this.width/2 +"px";
	},
	
	onscroll: function(){
		if (this.header == undefined){
			return;
		}
		if (this.headerheight != this.header.clientHeight){
			this.fixNav();
		}
	}
}
	
neoarchaic.Core.extend(neoarchaic.Taichi, null, neoarchaic.protoObj);
delete neoarchaic.protoObj;

neoarchaic.Core.newObject("chi", "Taichi")


