// Global

function $(id) {
	return document.getElementById(id);
}

oImg = {
	aImgPre: new Array(),
	nImgPre: 0,
	aIdImg: new Array(),
	aImgSrc: new Array(),
	preload: function(src) {
		this.aImgPre[this.nImgPre] = new Image();
		this.aImgPre[this.nImgPre].src = src;
		this.nImgPre++;
	},
	swap: function(id, src) {
		var img = $(id);
		oImg.aIdImg.push(id);
		oImg.aImgSrc.push(img.src);
		img.src = src;
	},
	restore: function() {
		while(id = oImg.aIdImg.pop()) {
			src = oImg.aImgSrc.pop();
			$(id).src = src;
		}
	}
}

oMenuPral = {
	aId: new Array(),
	add: function(id) {
		this.aId.push(id);
		$("li"+id).className = "contracted";
		$("a"+id).href = "javascript:oMenuPral.toggle('"+id+"')";
		$("ul"+id).style.display = "none";
	},
	toggle: function(idSel) {
		for(i in this.aId) {
			try {
				id = this.aId[i]
				objLi = $("li"+id);
				objUl = $("ul"+id);
				if(id == idSel && objLi.className == "contracted") { 
					objLi.className = "expanded";
					objUl.style.display = "block";
				} else {
					objLi.className = "contracted";
					objUl.style.display = "none";
				}
			} catch(e) {}
		}
	},
	select: function(id) {
		try {
			objLi = $("li"+id);
			objLi.classNmae += " selected";
		} catch(e) {}
	}
}

// class ExandingSections
function ExandingSections(sInstanceName, sTitleTag, sClass) {
	this.sClass = sClass;
	this.sInstanceName = sInstanceName;
	this.aDiv = new Array();
	if(arguments[3] == true) this.bOnlyOne = true; else this.bOntlyOne = false;
	var aAllDiv = document.getElementsByTagName("div");
	for(var i=0; i<aAllDiv.length; i++) {
		if(aAllDiv[i].className == sClass) this.aDiv.push(aAllDiv[i]);
	}
	for(i=0; i<this.aDiv.length; i++) {
		this.aDiv[i].className = sClass + " collapsed";
		h2 = this.aDiv[i].getElementsByTagName(sTitleTag)[0];
		sH2 = h2.innerHTML;
		id = this.aDiv[i].id;
		h2.innerHTML = "<a href=\"javascript:" + this.sInstanceName + ".toggle('" + id + "')\">"
						 +  sH2 + "</a>";
	}
}
ExandingSections.prototype.toggle = function(id) {
	var obj = $(id);
	if(obj) {
		if(obj.className.indexOf("collapsed") != -1) obj.className = this.sClass + " expanded";
		else obj.className = this.sClass + " collapsed";
		obj.getElementsByTagName("a")[0].blur();
	}
	if(this.bOnlyOne) {
		for(i=0; i < this.aDiv.length; i++) {
			if(this.aDiv[i].id != id) this.aDiv[i].className = this.sClass + " collapsed";
		}
	}
}
