var DOMUtilities = {
	// XHTML 1.0 Strict work around for external links
	// ========================================================
	// locality		[string] CSS path for the locality of the function
	//				to be applied. Defaults to document.body
	targetBlank: function(locality){
		$$(locality+' a[rel*="external"]').each(function(e){
			e.writeAttribute("target","_blank");
		});
	},

	// Automatic text clear for input fields
	// ========================================================
	// locality		[string] CSS path for the locality of the function
	//				to be applied. Defaults to document.body
	inputAutoClear: function(locality){
		$$(locality+' input.clearField').each(function(e){
			e.observe('focus',function(){
				if (this.value == this.defaultValue) {
					this.value = "";
				}
			}).observe('blur',function(){
				if(this.value == "") {
					this.value = this.defaultValue;
				}
			});
		});		
	},

	// Image roll-over setup
	// ========================================================
	// locality		[string] CSS path for the locality of the function
	//				to be applied. Defaults to document.body
	imgRollover: function(locality){
		$$(locality+' img.rollOver, '+locality+' input[type="image"].rollOver').each(function(e){
			e.observe('mouseover',function(){
				if (this.src.indexOf("_i.") != -1) {
					this.src = this.src.replace("_i.", "_o.");
				}
			}).observe('mouseout',function(){
				if (this.src.indexOf("_o.") != -1) {
					this.src = this.src.replace("_o.", "_i.");
				}
				if(this.src.indexOf("_a.")) {
					this.src = this.src.replace("_a.","_i.");
				}
			})
			if(e.match("input")) {
				e.observe('mousedown',function(){
					this.src = this.src.replace("_o.","_a.");
				}).observe('mouseup',function(){
					this.src = this.src.replace("_a.","_i.");
				});
			}
		});
	},

	// Initialize all DOM utilities on the body. Run onDOMReady
	init: function(locality){
		if(locality == null) {
			locality = "body";
		}
		this.targetBlank(locality);
		this.inputAutoClear(locality);
		this.imgRollover(locality);
	}
}

$(document).observe('dom:loaded',function(){
	DOMUtilities.init();
});
