// effect.js
// copyright by oursky.net, all rights reserved.

var fadeSpeed = .8;
var effectObjID = 0;
var alphaSpeed_bab = .7;

var alphaSpeed_aba = 100; // microseconds

function fadeTo(obj, to) {
	if (!is.i&&!is.ns6) return;

	if (typeof obj == "string") obj = document.getElementById(obj);

	if (is.ie && (!obj.filters || !obj.filters.alpha)) return;

	if (obj.tmr) clearTimeout(obj.tmr);
	obj.tmr = 0;
	var alpha = is.ie ? obj.filters.alpha.opacity : obj.style.MozOpacity * 100;
	alpha += (to - alpha) * fadeSpeed;
	if (Math.abs(alpha - to) < 2) {
		if (is.ie) {
			obj.filters.alpha.opacity = to;
		}
		else {
			obj.style.MozOpacity = to / 100;
		}
		return;
	}
	if (is.ie) {
		obj.filters.alpha.opacity = alpha;
	}
	else {
		obj.style.MozOpacity = alpha / 100;
	}
	if (!obj.id) obj.id = "fadeImg" + (++effectObjID);
	obj.tmr = setTimeout("fadeTo('"+obj.id+"', "+to+")");
}

function alpha_aba(obj, started) {
	if (!is.ie&&!is.ns6) return;

	if (typeof obj == "string") obj = document.getElementById(obj);

	if (is.ie && (!obj.filters || !obj.filters.alpha)) return;

	if (obj.tmr) clearTimeout(obj.tmr);
	obj.tmr = 0;


	var to = obj.to;
	if (!to) to = 50;
	/*
	var alpha = obj.filters.alpha.opacity;

	alpha += (to - alpha) * alphaSpeed_aba;
	if (Math.abs(alpha - to) < 2) {
	*/
		if (to == 100) {
			obj.to = 50; // first fade
			if (is.ie) obj.filters.alpha.opacity = to;
			else obj.style.MozOpacity = to / 100;
			if (started) return; // done
		} else if (to == 50) {
			obj.to = 100; // go back 100
			if (is.ie) obj.filters.alpha.opacity = to;
			else obj.style.MozOpacity = to / 100;
		}
	/*
	} else {
		obj.filters.alpha.opacity = alpha;
	}
	*/

	if (!obj.id) obj.id = "fadeImg" + (++effectObjID);
	obj.tmr = setTimeout("alpha_aba('"+obj.id+"', true)", alphaSpeed_aba);
}
function alpha_bab(obj, started) {
	if (!is.ie) return;

	if (typeof obj == "string") obj = document.getElementById(obj);

	if (!obj.filters) return;

	if (obj.tmr) clearTimeout(obj.tmr);
	obj.tmr = 0;


	var alpha = obj.filters.alpha.opacity;
	var to = obj.to;
	if (!to) to = 100; // start

	alpha += (to - alpha) * alphaSpeed_bab;
	if (Math.abs(alpha - to) < 2) {
		obj.filters.alpha.opacity = to;
		if (to == 50) {
			if (started) return; // done
			obj.to = 100; // start
		} else if (to == 100) {
			obj.to = 50; // go back 50
		}
	}
	obj.filters.alpha.opacity = alpha;
	if (!obj.id) obj.id = "fadeImg" + (++effectObjID);
	obj.tmr = setTimeout("alpha_bab('"+obj.id+"', true)");
}

function bhover(borderColor,e) {
	var o = e_getSrc(e);
	var p = is.ie ? 'parentElement' : 'parentNode';
	while (o && o.tagName != 'TD' && o.tagName != 'A' && o.tagName != 'DIV')
		o=o[p];
	if (!o) return;

	return borderHover(o,borderColor,e)
}

function borderHover(o,borderColor,e)
{
	var div, st;
	var add = false;
	if (!is.ie) return;
	if (o.style.cursor) return;
	o.style.cursor = is.hand;
	var fc = o.firstChild;
	while (fc) {
		if (fc.nodeName == 'IMG' || fc.nodeName == 'INPUT') {
			div = fc;
			break;
		}
		fc = fc.nextSibling;
	}
	if (!div) {
		add = true;
		div = document.createElement('div');
	}

	st = div.style;

	st.display = 'inline';
	st.cursor = is.hand;
	//st.position = 'absolute'; // have to..
	// st.left = st.top = 0 + 'px';
	//st.height = o.offsetHeight + 'px';
	//st.width = o.offsetWidth + 'px';
	// _setBorderColor(o, borderColor);
	st.borderStyle = 'solid';
	st.borderColor = borderColor;

	st.borderWidth = '1px'
	div.onmouseover = function () { this.style.borderWidth='1px'; }
	div.onmouseout = function() { this.style.borderWidth='0px'; }

	/*var fc = o.firstChild;
	while (fc) {
		div.appendChild(o.removeChild(fc));
		fc = fc.nextSibling;
	}*/
	if (!add) return;
	fc = o.firstChild;
	if (fc&&div!=fc) {
		o.insertBefore(div,fc);
		o.removeChild(fc);
	} else {
		o.appendChild(div);
	}
}

