function resizeDiv(divId, limitW, limitH, step, afterCmd) {
	tmrName = divId + 'Tmr';
	tmrCmdIn = 'resizeDivTmr(\'' + divId + '\', ' + limitW + ', ' + limitH +', ' + step + ', \'' + afterCmd + '\')';
	tmrCmd = eval(tmrName + ' = setTimeout("' + tmrCmdIn + '", 1)');
}

function resizeDivTmr(divId, limitW, limitH, step, afterCmd) {
	var w;
	var h;
	var divElm = getElm(divId);
	var currW = parseInt(divElm.style.pixelWidth);
	var currH = parseInt(divElm.style.pixelHeight);
	if (step < 0) {
		if (currW > limitW) {
			divElm.style.width = String(currW + step);
		} else {
			w = true;
		}
		if (currH > limitH) {
			divElm.style.height = String(currH + step);
		} else {
			h = true;
		}
	} else {
		if (currW < limitW) {
			divElm.style.width = String(currW + step);
		} else {
			w = true;
		}
		if (currH < limitH) {
			divElm.style.height = String(currH + step);
		} else {
			h = true;
		}
	}

	tmrName = divId + 'Tmr';
	if (w && h) {
		clearTimeout(tmrName);
		eval(afterCmd);
	} else {
		tmrCmdIn = 'resizeDivTmr(\'' + divId + '\', ' + limitW + ', ' + limitH +', ' + step + ', \'' + afterCmd + '\')';
		tmrCmd = eval(tmrName + ' = setTimeout("' + tmrCmdIn + '", 1)');
	}
}

function randomLetterEffect(word, divId) {
	cnt = 0;
	tmrLE = setTimeout('tmrRandomLetterEffect(\'' + word + '\', \'' + divId + '\')', 10);
}

function tmrRandomLetterEffect(word, divId) {
	theInnerHtml = '';
	for (var j = 0; j < word.length; j++) {
		currLetters[j] = theLetters.charAt(Math.random() * theLetters.length + 1);
		theInnerHtml += currLetters[j] + '<br>';
	}
	getElm(divId).innerHTML = '<span style="color: black;">' + theInnerHtml + '</span>';
	if (cnt < 30) {
	tmrLE = setTimeout('tmrRandomLetterEffect(\'' + word + '\', \'' + divId + '\')', 10);
		cnt++;
	} else {
		clearTimeout(tmrLE);
		getElm(divId).innerHTML = '';
		for (var j = 0; j < word.length; j++) {
			getElm(divId).innerHTML += word.charAt(j) + '<br>';
		}
	}
}

function hex2dec(strHex) {
	rc = parseInt(strHex, 16);
	return rc;
}

function dec2hex(intDec, minLen) {
	rc = intDec.toString(16);
	for (var i = 0; i < minLen - rc.length; i++) {
		rc = '0' + rc;
	}
	return rc;
}

function getColorString(decR, decG, decB) {
	rc = '#' + dec2hex(decR, 2) + dec2hex(decG, 2) + dec2hex(decB, 2);
	return rc;
}

function getRGB(colorString) {
	if (colorString.substr(0, 1) != '#') colorString = '#' + colorString;
	tmpR = colorString.substr(1, 2);
	tmpG = colorString.substr(3, 2);
	tmpB = colorString.substr(5, 2);
	rc = new Array(tmpR, tmpG, tmpB);
	return rc;
}

function getDecRGB(colorString) {
	arrRGB = getRGB(colorString);
	tmpR = hex2dec(arrRGB[0]);
	tmpG = hex2dec(arrRGB[1]);
	tmpB = hex2dec(arrRGB[2]);
	rc = new Array(tmpR, tmpG, tmpB);
	return rc;	
}

function getMin(arrNums) {
	var tmpMin = arrNums[0];
	for (var i = 1; i < arrNums.length; i++) {
		if (arrNums[i] < tmpMin) tmpMin = arrNums[i];
	}
	return tmpMin;
}

function getMax(arrNums) {
	var tmpMax = arrNums[0];
	for (var i = 1; i < arrNums.length; i++) {
		if (arrNums[i] > tmpMax) tmpMax = arrNums[i];
	}
	return tmpMax;
}

var ds;
var fadeTmr = new Array();
var tmrN = 0;
function fade(elmRef, startColor, endColor, afterCmd) {
	eval(elmRef  + ' = startColor');
	startRGB = getDecRGB(startColor);
	startR = startRGB[0];
	startG = startRGB[1];
	startB = startRGB[2];
	endRGB = getDecRGB(endColor);
	endR = endRGB[0];
	endG = endRGB[1];
	endB = endRGB[2];
	dR = endR - startR;
	dG = endG - startG;
	dB = endB - startB;
	d = getMax(new Array(Math.abs(dR), Math.abs(dG), Math.abs(dB)));
	if (d == 0) return;
	dR = dR / d;
	dG = dG / d;
	dB = dB / d;
	tmrN++;
	if (tmrN == 100) tmrN = 1;
	fadeTmr[tmrN] = setTimeout('tmrFade(' + tmrN + ', \'' + elmRef + '\', \'' + startColor + '\', \'' + endColor + '\', ' + dR + ', ' + dG + ', ' + dB + ', 0, \'' + afterCmd + '\')', 1);
}

function tmrFade(tmrN, elmRef, startColor, endColor, dR, dG, dB, dsIndex, afterCmd) {
	startRGB = getDecRGB(startColor);
	startR = startRGB[0];
	startG = startRGB[1];
	startB = startRGB[2];
	currR = parseInt(startR + dsIndex * dR);
	currG = parseInt(startG + dsIndex * dG);
	currB = parseInt(startB + dsIndex * dB);
	tmpColor = getColorString(currR, currG, currB);
	eval(elmRef  + ' = \'' + tmpColor + '\'');
	dsIndex++;
	if (tmpColor == endColor) {
		clearTimeout(fadeTmr[tmrN]);
		if (afterCmd != 'undefined' && afterCmd != '') {
			eval(afterCmd);
		}
	} else {
		fadeTmr[tmrN] = setTimeout('tmrFade(' + tmrN + ', \'' + elmRef + '\', \'' + startColor + '\', \'' + endColor + '\', ' + dR + ', ' + dG + ', ' + dB + ', ' + dsIndex + ', \'' + afterCmd + '\')', 1);
	}
}

var gBgStart;
var gBgEnd;
var elmObj;
var afterBfCmd;
function buildFrameByFade(divId, borderStartColor, borderEndColor, bgStartColor, bgEndColor, afterCmd) {
	afterBfCmd = afterCmd;
	gBgStart = bgStartColor;
	gBgEnd = bgEndColor;
	elmObj = getElm(divId);
	show(divId);
	elmObj.innerHTML = '';
	var params = getFadeBorderParams(divId, borderStartColor, borderEndColor);
	var condL = 'getElm("' + divId + '").style.borderLeftColor=="' + borderEndColor + '"';
	fade('getElm("' + divId + '").style.borderLeftColor', borderStartColor, borderEndColor);
	tmrDep = setTimeout('fTmrDep(\'' + condL + '\', \'bfbfTop(' + params + ')\')', 1);
}

function getFadeBorderParams(divId, borderStartColor, borderEndColor) {
	var rc = '"' + divId + '", "' + borderStartColor + '", "' + borderEndColor + '"';
	return rc;
}

function bfbfTop(divId, borderStartColor, borderEndColor) {
	var params = getFadeBorderParams(divId, borderStartColor, borderEndColor);
	var condT = 'getElm("' + divId + '").style.borderTopColor=="' + borderEndColor + '"';
	fade('getElm("' + divId + '").style.borderTopColor', borderStartColor, borderEndColor);
	tmrDep = setTimeout('fTmrDep(\'' + condT + '\', \'bfbfRight(' + params + ')\')', 1);
}

function bfbfRight(divId, borderStartColor, borderEndColor) {
	var params = getFadeBorderParams(divId, borderStartColor, borderEndColor);
	var condR = 'getElm("' + divId + '").style.borderRightColor=="' + borderEndColor + '"';
	fade('getElm("' + divId + '").style.borderRightColor', borderStartColor, borderEndColor);
	tmrDep = setTimeout('fTmrDep(\'' + condR + '\', \'bfbfBottom(' + params + ')\')', 1);
}

function bfbfBottom(divId, borderStartColor, borderEndColor) {
	var params = '"' + divId + '", "' + gBgStart + '", "' + gBgEnd + '"';
	var condB = 'getElm("' + divId + '").style.borderBottomColor=="' + borderEndColor + '"';
	fade('getElm("' + divId + '").style.borderBottomColor', borderStartColor, borderEndColor);
	tmrDep = setTimeout('fTmrDep(\'' + condB + '\', \'bfbfBackground(' + params + ')\')', 1);
}

function bfbfBackground(divId, bgStartColor, bgEndColor) {
	var cond = 'getElm("' + divId + '").style.background=="' + gBgEnd + '"';
	fade('getElm("' + divId + '").style.background', bgStartColor, bgEndColor);
	tmrDep = setTimeout('fTmrDep(\'' + cond + '\', \'bfbfAfter()\')', 1);
}

function bfbfAfter() {
	eval(afterBfCmd);
}

function fTmrDep(cond, nextCmd) {
	if (eval(cond)) {
		clearTimeout(tmrDep);
		eval(nextCmd);
	} else {
		tmrDep = setTimeout('fTmrDep(\'' + cond + '\', \'' + nextCmd + '\')');
	}
}

var TW_INTERVAL = 1;
var arrTypes = new Array();
function typeWriterEffect(divId, iHtml, cursorChar, cursorColor) {
	arrTypes = createTypedTextArray(iHtml);
	cursorHtml = '<span style="color: ' + cursorColor + ';">' + cursorChar + '</span>';
	var tmrTW = setTimeout('fTmrTW(\'' + divId + '\', \'' + cursorHtml + '\', 1, ' + arrTypes.length + ')', TW_INTERVAL);
}

function fTmrTW(divId, cursorHtml, currIndex, elmNum) {
	var arrTypesElm = arrTypes[currIndex];
	var allChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYS';
	if (cursorHtml.indexOf('RANDOM') != -1) {
		var randomChar = allChars.charAt(parseInt(Math.random() * allChars.length));
		var tmpArr = cursorHtml.split('RANDOM');
		currCursorHtml = tmpArr[0] + randomChar + tmpArr[1];
	} else {
		currCursorHtml = cursorHtml;
	}
	if (currIndex == elmNum - 1) {
		getElm(divId).innerHTML = arrTypesElm;
		clearTimeout(tmrTW);
	} else {
		getElm(divId).innerHTML = arrTypesElm + currCursorHtml;
		currIndex++
		tmrTW = setTimeout('fTmrTW(\'' + divId + '\', \'' + cursorHtml + '\', ' + currIndex + ', ' + arrTypes.length + ')', TW_INTERVAL);
	}
}

function createTypedTextArray(iHtml) {
	var rc = new Array();
	var tagFlag = false;
	var tagBuffer = '';
	rc[0] = '';
	n = 1;
	for (var i = 0; i < iHtml.length; i++) {
		currChr = iHtml.charAt(i);
		if (currChr == '<') {
			tagFlag = true;
		}
		if (currChr == '>') {
			tagBuffer+= currChr;
			tagFlag = false;
		}
		if (tagFlag) {
			tagBuffer+= currChr;
		} else {
			if (tagBuffer != '') {
				rc[n] = rc[n - 1] + tagBuffer;
				tagBuffer = '';
				n++;
			} else {
				rc[n] = rc[n - 1] + currChr;
				n++;
			}
		}
	}
	rc[n] = rc[n - 1];
	return rc;
}

function high(obj) {
	theObj = obj;
	tmrHighlight = setInterval('highlightTmr(theObj)', 50);
}

function low(obj) {
	clearInterval(tmrHighlight);
	if (obj.style.MozOpacity) obj.style.MozOpacity = 0.3;
	else if (obj.filters) obj.filters.alpha.opacity = 75;
}

function highlightTmr(obj) {
	if (obj.style.MozOpacity < 1) obj.style.MozOpacity = parseFloat(obj.style.MozOpacity) + 0.1;
	else if (obj.filters && obj.filters.alpha.opacity < 100) obj.filters.alpha.opacity += 10;
	else if (window.tmrHighlight) clearInterval(tmrHighlight);
}

function lowToZero(obj, afterCmd) {
	theAfterCmd = afterCmd;
	theObj = obj;
	tmrHighlight = setInterval('lowToZeroTmr(theObj)', 50);
}

function lowToZeroTmr(obj) {
	if (obj.style.MozOpacity > 0) obj.style.MozOpacity = parseFloat(obj.style.MozOpacity) - 0.1;
	else if (obj.filters && obj.filters.alpha.opacity > 0) obj.filters.alpha.opacity -= 10;
	else if (window.tmrHighlight) {
		clearInterval(tmrHighlight);
		eval(theAfterCmd);
	}
}

