var css_nav_margin = 75;
var css_nav_height = 493;

if (!HSD) { var HSD = new Object(); };

function Search(index){
    if(document.forms[0].keywords.value != '')
    {
		document.forms[index].submit();
	}
}


log = function(message)
{
	//alert(message);
}

NavGo = function()
{
    log("navGo");
	HSD.Navigation.toggle(HSD.Navigation.top,this);
}


HSD.hasRequired 	= function() { 
	if (document.getElementById && document.getElementsByTagName) {
		var html = document.getElementsByTagName('html')[0];
		html.className += ((html.className=='')?'':' ')+'has-dom';
		return true;
		};
	return false;
	}();


HSD.onbeforeload	= function() {
	if (this.hasRequired) {
		//this.CSSattach();
		var attachOnSubmit = false;

		for (var module in this) { 
			if (this[module].onbeforeload) { 
				this[module].onbeforeload();
				};
			if (this[module].onsubmit) { attachOnSubmit = true; };
			};
		
		if (attachOnSubmit) {
			var forms = document.getElementsByTagName('form');
			for (var i=0; form=forms[i]; i++) {
				if (typeof form.onsubmit!='function') {
					form.onsubmit = function() { return HSD.onsubmit(this); };
					};
				};
			};
		};

	};
HSD.onload		= function() { if (this.hasRequired) { for (var module in this) { if (this[module].onload) { this[module].onload(); };};};};
HSD.onresize		= function() {  if (this.hasRequired) { for (var module in this) { if (this[module].onresize) { this[module].onresize(); };};};};
HSD.onsubmit		= function(form) { for (var module in this) { if (this[module].onsubmit) { if (this[module].onsubmit(form)==false) { return false; };};}; return true; };
//HSD.oncssload	= function() {  if (this.hasRequired) { for (var module in this) { if (this[module].oncssload) { this[module].oncssload(); };};};};

	
HSD.Navigation = {
	
	content		: {id:'nav-main'},
	top			: {id:'nav-top',state:0},
	bottom		: {id:'nav-bottom',state:1}, // state is 1 because the navigation defaults to display block
	revealInit	: false,
	revealLoop	: false,
	revealId	: null,
	
	getScrollTop	: function() {
		if (document.all) { return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop; }
		else { return window.pageYOffset; }
		},
	
	/*
	 * 
	 */
	toggle		: function(navElem,e) {
		log("Navigation:toggle");
		if (!document.removeChild || !document.appendChild) return;

		//lost focus
		//e.blur();
		
		this.top.e.parentNode.className = this.top.e.parentNode.className.replace(/ open/,'');
		this.bottom.e.parentNode.className	= this.bottom.e.parentNode.className.replace(/ open/,'');
		
		if (navElem.state) {
			navElem.state = 0;
		} else {
			navElem.e.appendChild(this.content.e);
			navElem.state = 1;
			navElem.opp.state = 0;
			navElem.opp.e.style.height = css_nav_margin + 'px';
			navElem.e.parentNode.className += ' open';
		}
		// Now grow the container
		this.reveal(navElem);
	},
		
	/*
	 *
	 */
	reveal		: function(navElem) {

		if(this.revealLoop){
			clearInterval(this.revealId);
			this.revealLoop = false;
			this.revealId = null;
		}
		//this.revealTo(navElem.id.replace(/^nav-/,''),(navElem.state)?this.content.e.offsetHeight:0);
		this.revealTo(navElem.id.replace(/^nav-/,''),(navElem.state)?css_nav_height:css_nav_margin);
		
	},
	
	/*
	 *
	 */
	revealTo	: function(navRef,h) {
		
		var navElem = eval('this.'+navRef);
		//if (h == 0) { 
		//	h=css_nav_margin; 
		//}
		if (this.revealLoop) {
			log(h);
			var c = navElem.e.offsetHeight 
			if (Math.abs(c + h) <=1) {
			    //loop complete
				navElem.e.style.height = h + 'px';
				//if (!navElem.state) { this.content.e = this.content.e.parentNode.removeChild(this.content.e); }
				clearInterval(this.revealId);
				this.revealLoop = false;
				this.revealId = null;
				if (!this.revealInit) { 
					this.revealInit = true; 
				}
			}
			else {
				navElem.e.style.height = (c+(h-c)/2)+'px';
				if (navElem.e.offsetTop < 0 && this.revealInit) 
				{ 
					window.scrollTo(0,this.getScrollTop()); 
				}
			}
		}
		else {
		    //log("Navigation:revealTo->setInterval" + "HSD.Navigation.revealTo('"+navRef+"',"+h+")");
			this.revealId = setInterval("HSD.Navigation.revealTo('"+navRef+"',"+h+")",100);
			this.revealLoop = true;
		}

	},
	
	/*
	 * initialize
	 */
	onbeforeload	: function() {
	
	    
		// Assemble our container element references
		this.content.e	= document.getElementById(this.content.id);
		this.top.e		= document.getElementById(this.top.id).getElementsByTagName('div')[0];
		this.bottom.e	= document.getElementById(this.bottom.id).getElementsByTagName('div')[1];
		
		// Assemble our link references
		this.top.a		= document.getElementById(this.top.id).getElementsByTagName('a')[0];
		this.bottom.a	= document.getElementById(this.bottom.id).getElementsByTagName('a')[0];
		
		// Add a reference to the opposite element
		this.top.opp	= this.bottom;
		this.bottom.opp	= this.top;
		
		// Attach event handlers to links
		/*
		this.top.a.onclick		= function() { 
			//HSD.Navigation.toggle(HSD.Navigation.top,this); 
			return false; 
		}
		
		this.bottom.a.onclick	= function() { 
			//HSD.Navigation.toggle(HSD.Navigation.bottom,this); 
			return false; 
		}
		
		// Testing
		this.top.a.onmouseover		= function() { 
			HSD.Navigation.toggle(HSD.Navigation.top,this); 
			return false; 
		}
		
		this.bottom.a.onmouseover	= function() { 
			HSD.Navigation.toggle(HSD.Navigation.bottom,this); 
			return false; 
		}*/
		
		if (this.content.e && this.top.e && this.bottom.e) {
			this.toggle(this.bottom,this.bottom.a);
		};
	}
		
	,
	/*
	 * WindowResize
	 */

	onresize	: function() {

		if (this.revealInit) {
			if (this.top.state) { 
				this.reveal(this.top); 
			}
			else if (this.bottom.state) 
			{ 
				this.reveal(this.bottom); 
			}
		}
	}
};





window.onload	= function() { HSD.onload(); };
window.onresize	= function() { HSD.onresize(); };
/**/