function DHTML() {
	this.preloadedImages = new Array()

	this.preloadImage = DHTML_preloadImage
	this.changeImagePostfix = DHTML_changeImagePostfix
	this.changeImageSrc = DHTML_changeImageSrc
	this.getImagePostfix = DHTML_getImagePostfix
	this.insertImageSrcPostfix = DHTML_insertImageSrcPostfix
	this.removeImageSrcPostfix = DHTML_removeImageSrcPostfix
	this.mouseOver = DHTML_mouseOver
	this.mouseOut = DHTML_mouseOut
	this.mouseDown = DHTML_mouseDown
	this.getElement = DHTML_getElement
}

function DHTML_preloadImage(src) {
	var idx = this.preloadedImages.length
	this.preloadedImages[idx] = new Image()
	this.preloadedImages[idx].src = src
}

// change an image src filenmae, keeping same path
function DHTML_changeImageSrc(obj, newSrc) {

	var path = obj.src.substring(0, obj.src.lastIndexOf("/") +1)
	obj.src = path + newSrc
}

function DHTML_changeImagePostfix(obj, postfix) {

	var usPos = obj.src.lastIndexOf("_")
	var dotPos = obj.src.lastIndexOf(".")

	obj.src = obj.src.substring(0, usPos + 1) + postfix + obj.src.substring(dotPos)
}

function DHTML_getImagePostfix(src) {
	
	var usPos = src.lastIndexOf("_")
	var dotPos = src.lastIndexOf(".")
	
	return src.substring(usPos + 1, dotPos)
}

function DHTML_insertImageSrcPostfix(src, postfix) {

	if (src.lastIndexOf(postfix +".") == -1) {
		var pos = src.lastIndexOf(".")
		return src.substring(0, pos) + postfix + src.substring(pos)
	} else {
		return src
	}
}

function DHTML_removeImageSrcPostfix(src, postfix) {

	if (src.lastIndexOf(postfix +".") != -1) {
		var pos = src.lastIndexOf(postfix)
		return src.substring(0, pos) + src.substring(pos + postfix.length)
	} else {
		return src
	}
}

function DHTML_mouseOver(obj) {
	var postFix = this.getImagePostfix(obj.src)
	if (postFix == "disabled") return false
	if (postFix == "selected") return false
	this.changeImagePostfix(obj, "over")
}

function DHTML_mouseOut(obj) {
//	if (this.getImagePostfix(obj.src) != "disabled") obj.src =	obj.originalSrc
	var postFix = this.getImagePostfix(obj.src)
	if (postFix == "disabled") return false
	if (postFix == "selected") return false
	this.changeImagePostfix(obj, "default")
}

function DHTML_mouseDown(obj) {
	var postFix = this.getImagePostfix(obj.src)
	if (postFix == "disabled") return false
	if (postFix == "selected") return false
	this.changeImagePostfix(obj, "down")
//	if (this.getImagePostfix(obj.src) != "disabled") this.changeImagePostfix(obj, "down")
}


function DHTML_getElement(object, showError) {

	if (typeof(object) == "object") {
		var obj = object
	} else {
		var obj = document.getElementById(object);
	}
	
	if (!obj && showError) alert("DHTML.getElement, cannot find object ID '"+ object +"'.")

	return obj
}



var DHTML = new DHTML()



function CSS() {

	this.display = CSS_display
	this.className = CSS_className
	this.visibility = CSS_visibility
}

function CSS_display(objectID, display, showError) {
	
	if (display == null) display = "block";
	if (showError == null) showError = false;

	var obj = DHTML.getElement(objectID);
	if (obj) {
		obj.style.display = display;
	} else {
		if (showError) alert("CSS.display, cannot find object ID '"+ objectID +"'.")
	}
}

function CSS_className(objectID, className, showError) {
	
	if (showError == null) showError = false;

	var obj = DHTML.getElement(objectID);
	if (obj) {
		obj.className = className;
	} else {
		if (showError) alert("CSS.className, cannot find object ID '"+ objectID +"'.")
		return false
	}
}

function CSS_visibility(objectID, visibility, showError) {
	
	if (visibility == null) visibility = "visible";
	if (showError == null) showError = false;

	var obj = DHTML.getElement(objectID);
	if (obj) {
		obj.style.visibility = visibility;
		return true
	} else {
		if (showError) alert("CSS.visibility, cannot find object ID '"+ objectID +"'.")
		return false
	}
}

function CSS_changeToggleClass(objectID,submenu) {
//  alert("hello - "+objectID);
	var obj = DHTML.getElement(objectID);
//  alert("obj = "+obj);
	if (obj) {
		objClassName = obj.className;
		if(objClassName.indexOf('selected')== -1){
			objClassName = objectID+"selected";
		}else{
      if(submenu != false){
        objClassName = "submenucell"+submenu;
      }else{
        objClassName = "mainmenucell";
	    }		
		}
		CSS_className(objectID, objClassName, true) 		
	}
}


CSS = new CSS()