function hide(e)
{
	if (e != false)
		e.style.display = 'none';
	return false;
}

function clone(e)
{
	var n = e.cloneNode(e);
	
	e.parentNode.appendChild(n);
	
	return n;
}

function show(e)
{
	if (e != false)
		e.style.display = 'block';
	return false;
}
function hidden(e)
{
	if (e.style.display == 'block') return false;
	return true;
}
function showing(e)
{
	if (e.style.display == 'none') return false;
	return true;
}

function add_class(e, cn)
{
	if (is_array(e))
	{
		for (var i = 0; i < e.length; i++)
			add_class_name( ge(e[i]), cn );
	}
	else
	{
		add_class_name( ge(e), cn );
	}
}
function remove_class(e, cn)
{
	if (is_array(e))
	{
		for (var i = 0; i < e.length; i++)
			remove_class_name( ge(e[i]), cn );
	}
	else
	{
		remove_class_name( ge(e), cn );
	}
}
function is_class(e, cn)
{
	var cc = " " + e.className + " ";
	if (cc.indexOf(" " + cn + " ")>-1)
	{
		return true;
	}
	else
		return false;
}
function add_class_name(e, cn)
{
	if (e.className != "")
	{
		var cc = " " + e.className + " ";
		if (cc.indexOf(" " + cn + " ") == -1)
		{
			e.className = e.className + " " + cn;
		}
	} else e.className = cn;
}
function remove_class_name(e, cn)
{
	var cc = " " + e.className + " ";
	if (cc.indexOf(" " + cn + " ")>-1)
	{
		cc = cc.split(" " + cn + " ").join(" ");
		cc = cc.substring(1, cc.length-1);
		e.className = cc;
	}
}


function toggle(e, ce)
{
	e = ge(e);
	if (hidden(e))
	{
		add_class(ge(ce), 'active');
		show(e);
	}
	else
	{
		remove_class(ge(ce), 'active');
		hide(e);
	}

	return false;
}
function ge(e)
{

	if (document.getElementById(e))
		return document.getElementById(e);
	else
		return false;
}

function make_tooltip(e)
{
	e = ge(e);
	var ttip = '<table class="ttip"><tr><td class="ttip-tl"></td><td class="ttip-tr"></td></tr><tr><td class="ttip-l">';
	ttip = ttip + e.innerHTML;
	ttip = ttip + '</td><td class="ttip-r"></td></tr><tr><td class="ttip-bl"></td><td class="ttip-br"></td></tr></table>';
	e.innerHTML = ttip;

}


var m_dropdown = function(menu, ce)
{

	var jc = true;
	menu = ge(menu);
	if (hidden(menu))
	{
		show(menu);
		add_class(ce, 'active');
		menu.offclick = function(e)
		{
			if (!jc)
			{
				hide(this);
				remove_class(ce, 'active');
				removeEvent(document, 'click', this.offclick);
			} else jc = false;

		}.bind(menu);
		addEvent(document, 'click', menu.offclick, menu);
	}
	return false;
}


Function.prototype.bind = function() {
	var __method = this;
	var args = arguments;
	if (arguments.length > 1)
		var object = args.shift();
	else
		var object = args[0];
	return function() {
		return __method.apply(object, arguments);
	}
}
function is_array(obj) {
	if (obj.length)
		return true;
	else
		return false;
}

function setText(e, t)
{
	e.innerHTML = t;
	return false;
}

//Ajax Iframe Method
AIM = {

	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('div');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}

		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}
}

/*--------------------[  EVENT HANDLING  ]--------------------*/
function addEvent(e, type, fn)
{
	if (e.attachEvent) {
	//	e['e'+type+fn] = fn;
	//	e[type+fn] = function() { e['e'+type+fn](window.event); }
	//	e.attachEvent('on'+type,e[type+fn]);
		e.attachEvent('on'+type, fn);
	} else
	e.addEventListener(type,fn,false);
}
function removeEvent(e, type, fn)
{
	if (e.detachEvent) {
	//	e.detachEvent('on'+type,e[type+fn]);
	//	e[type+fn] = null;
		e.detachEvent('on'+type,fn);
	} else
	e.removeEventListener(type,fn,false);
}


/*--------------------[  PAGE LOAD  ]--------------------*/
function _gfDOMLoaded() {

	// quit if this function has already been called
	if (arguments.callee.done) return;
	
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;
	
	// kill the timer

	if (typeof _timer != 'undefined') {
		clearInterval(_timer);
		_timer = null;
	}

	//make_tooltip('login_box');

	ge('research-button').onclick = function() { m_dropdown('research-menu', ['research-button', 'nav-research']); return false;};
	ge('nav-options').onclick = function() { m_dropdown('options-menu', 'nav-options'); return false;};

	if (typeof init == 'function') init();

};

/* for Mozilla */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", _gfDOMLoaded, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var _goScript = document.getElementById("__ie_onload");
	_goScript.onreadystatechange = function() {
		if (this.readyState == "complete") {
			_gfDOMLoaded(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _gnTimer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			_gfDOMLoaded(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = _gfDOMLoaded;