
// Sam's DOM abstraction.

var DOM = new Object();
DOM.Obj = new Object();



DOM.Obj.get = function(id) {
	if(typeof(id) != 'string') return id;
	if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
		return document.getElementById(id); }
	if( document.all ) { //Proprietary DOM; IE4
		return document.all[id]; }
	if( document[divID] ) { //Netscape alternative
		return document[id]; }
   	if( document.layers ) { //Netscape layers
		return document.layers[id]; }
	return false; // failure.
}
DOM.Obj.style = function(obj){
	if(typeof(this.get(obj).style)!='undefined') return this.get(obj).style;
	else return this.get(obj);
}

// Object display features

var Display = new Object();

function DisplayHandler(obj){
	this.obj = DOM.Obj.get(obj);
	this.style = DOM.Obj.style(obj);
		
	this.handle = function(mode, setCookie){
		if(typeof(mode) == 'undefined')		return this.style.display;
		else if(typeof(mode) == 'string') 	this.style.display = mode;
		else if(typeof(mode) == 'boolean')	this.style.display = (mode == true) ? 'block' : 'none';
		else if(typeof(mode) == 'null' || (typeof(mode) == 'object' && !mode))
			this.style.display = (this.style.display == 'none') ? 'block' : 'none';
	
		if(setCookie === true){
			if(!Cookie) { alert('Cookie handling not supported.'); return false; }
			Cookie.del(this.cookieID(obj));
			Cookie.set(this.cookieID(obj), this.style.display);
		}
		return this.style.display;	
	}	


	this.cookieID = function(obj){
		return ('Display_' + this.obj.id);
	}

}

Display.handler = function(obj, mode, setCookie){
	var d = new DisplayHandler(obj);
	return d.handle(mode, setCookie);
}

Display.toggle = function(obj){
	return this.handler(obj, null, true);
}

Display.isVisible = function(obj){
	return (this.handler(obj) != 'none');
}

Display.initialize = function(obj){
	return this.handler(obj, getCookie(this.cookieID(obj)));
}
 
 
