//** Tab Content script- c Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 8th, 06

/* enable tab persistence via session only cookies, so selected tab is remembered? */
var enabletabpersistence = 1;

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs = new Object();

function expandcontent(linkobj) {
	var ulid = linkobj.parentNode.parentNode.id;
	var ullist = document.getElementById(ulid).getElementsByTagName("li");
	for (var i = 0; i < ullist.length; i++) {
		ullist[i].className = "";
		if (typeof tabcontentIDs[ulid][i] != "undefined") {
			document.getElementById(tabcontentIDs[ulid][i]).style.display = "none";
		}
	}
	linkobj.parentNode.className = "selected";
	// document.getElementById(linkobj.getAttribute("rel")).style.display = "block";
	var tabcontent = document.getElementById(linkobj.getAttribute("rel"));
	tabcontent.style.display = "block";
	/*
	var f = new fade(tabcontent, 0, 100, 100);
	f.start();
	*/
	saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"));
}

function expandtab(tabcontentid, tabnumber) {
	var thetab = document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber];
	if (thetab.getAttribute("rel")) {
		expandcontent(thetab);
	}
}

function savetabcontentids(ulid, relattribute) {
	if (typeof tabcontentIDs[ulid] == "undefined") {
		tabcontentIDs[ulid]=new Array();
	}
	tabcontentIDs[ulid][tabcontentIDs[ulid].length] = relattribute;
}

function saveselectedtabcontentid(ulid, selectedtabid){
	if (enabletabpersistence == 1) {
		setCookie(ulid, selectedtabid);
	}
}

function getullistlinkbyId(ulid, tabcontentid){
	var ullist = document.getElementById(ulid).getElementsByTagName("li");
	for (var i = 0; i < ullist.length; i++){
		if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel") == tabcontentid){
			return ullist[i].getElementsByTagName("a")[0];
			break;
		}
	}
}

function initializetabcontent() {
	for (var i = 0; i < arguments.length; i++){
		if (enabletabpersistence == 0 && getCookie(arguments[i]) != "") {
			setCookie(arguments[i], "");
		}
		var clickedontab = getCookie(arguments[i]);
		var ulobj = document.getElementById(arguments[i]);
		var ulist = ulobj.getElementsByTagName("li");
		for (var x = 0; x < ulist.length; x++) {
			var ulistlink=ulist[x].getElementsByTagName("a")[0];
			if (ulistlink.getAttribute("rel")){
				savetabcontentids(arguments[i], ulistlink.getAttribute("rel"));
				ulistlink.onclick = function() {
					expandcontent(this);
					return false;
				}
				/* add by michioga */
				ulistlink.onmouseover = function() {
					expandcontent(this);
					return false;
				}
				if (ulist[x].className == "selected" && clickedontab == "") {
					expandcontent(ulistlink);
				}
			}
		}
		if (clickedontab != ""){
			var culistlink = getullistlinkbyId(arguments[i], clickedontab);
			if (typeof culistlink != "undefined") {
				expandcontent(culistlink);
			} else {
				expandcontent(ulist[0].getElementsByTagName("a")[0]);
			}
		}
	}
}


function getCookie(Name){ 
	var re = new RegExp(Name + "=[^;]+", "i");
	if (document.cookie.match(re)) {
		return document.cookie.match(re)[0].split("=")[1];
	}
	return "";
}

function setCookie(name, value){
	document.cookie = name + "=" + value;
}
/***********************************************************************************/
/* Fade Effect                                                                     */
/***********************************************************************************/
function fade(eElement, nStart, nEnd, nDuration, fCallback) {	

	this.nOffset = 8;
	this.nOpacity = nStart;
	this.nStart = nStart;	
	this.nEnd = nEnd;		
	this.nDuration = nDuration;
	this.fCallback = fCallback;
	this.e = eElement;
	this.nInterval = 0;
	this.bFading = false;
}

fade.prototype.fadeCycle = function() {

	if (this.nEnd < this.nStart) {	
		if (this.nOpacity > this.nEnd) {	
			this.nOpacity -= this.nOffset;	
		} else {
			this.finalize();
		}
	} else {
		if (this.nOpacity < this.nEnd) {	
			this.nOpacity += this.nOffset;	
		} else {
			this.finalize();
		}	
	}
	
	this.setOpacity(this.nOpacity/100);	
	
}

fade.prototype.setOpacity = function(nOp) {	
	this.e.style.opacity = nOp;
	this.e.style.filter = "alpha(opacity=" + (nOp*100) + ")";
}

fade.prototype.finalize = function() {
	this.nOpacity = this.nEnd;
	this.bFading = false;
	clearInterval(this.nInterval);	
	if (this.fCallback) { this.fCallback(); }
}

fade.prototype.isFading = function() {
	return (this.bFading == true) ? true : false;
}

fade.prototype.start = function() {
	var oSelf = this;
	this.bFading = true;
	this.nInterval = setInterval(function() { oSelf.fadeCycle(); }, (this.nDuration / this.nOffset));	
}

fade.prototype.stop = function() {
	this.bFading = false;
	clearInterval(this.nInterval);
}
