var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isDyn = (isDOM || isIE4 || isNS4);


// compatibility for multiple browsers
function getRef( id ) {
	if (isDOM)
		return document.getElementById(id);
	if (isIE4)
		return document.all[id];
	if (isNS4)
		return document.layers[id];

}


function img_over(obj, act) {
	var img = obj.getElementsByTagName("img");
	if ( img.length > 0 ) {
		obj_over(img[0].id, act)
	}
}


function obj_over(objId, act) {
	var refObj = getRef(objId);
	if (refObj.cc==undefined)
		refObj.cc = 0; //create counter
	switch ( act ) {
		default:
			setTimeout('mod_className(\"'+refObj.id+'\",0,'+refObj.cc+')', 500 );
			break;
		case 1:
			refObj.cc++; //inc to disable pervious actions 
			setTimeout('mod_className(\"'+refObj.id+'\",'+act+','+refObj.cc+')', 50 );
			break;
	}
}


function mod_className(objId, act, cc) {
	var refObj = getRef(objId);
	if (refObj.cc!=cc)
		return; //skip action
	switch ( act ) {
		default:
			var re = new RegExp("g[9]");
			// replace className
			refObj.className = refObj.className.replace(re, "g0"); //off
			break;
		case 1:
			var re = new RegExp("g[0-8]");
			// replace className
			refObj.className = refObj.className.replace(re, "g9"); //over
			break;
	}
}


function glower(objId, set, glow) {
//	addStatus("#");
	// increase glow
	glow = glow + 2;
	if (glow >= cellGlow[set].length)
		glow = 1;
	var refObj = getRef(objId);
	var re = new RegExp(cellGlow[set][0]+"[0-8]");
	// replace className
	refObj.className = refObj.className.replace(re, cellGlow[set][0]+cellGlow[set][glow]);
//	addStatus(objId+".className.replace(RegExp("+cellGlow[set][0]+"[0-8]), "+cellGlow[set][0]+cellGlow[set][glow]+")");
	// new timeout
	setTimeout('glower(\"'+objId+'\", \"'+set+'\", '+glow+')', cellGlow[set][glow+1]);
}


var a_t = "@";


function processLink() {
	var arr = arguments[0].split("|");
	var tempadrformat = "";
	tempadrformat += (arr[0].substring(1,arr[0].length) + ":ot" + "l" + "iam").split("").reverse().join("");
	tempadrformat += a_t;
	for ( var i = 1; i < arr.length; i++ ) {
		if ( i > 1 ) tempadrformat += ".";
		tempadrformat += arr[i].substring(0,arr[i].length-1);
	}
	//window.location = tempadrformat;
	return "<a href=\""+tempadrformat+"\">"+tempadrformat.split(":")[1]+"</a>";
}

function preloadImages() {
	var d=document;
	if (d.images!=undefined) {
		if (d.p==undefined) d.p = new Array();
		var i, j = d.p.length, a = preloadImages.arguments;
		for (i=0; i<a.length; i++)
			if (a[i].indexOf("#") != 0) {
				d.p[j] = new Image;
				d.p[j++].src=a[i];
			}
	}
}


var cellGlow = new Array();


function navglow() {
	for ( var i = 0; i+1 < arguments.length; i = i + 2 ) {
	//	alert('glower("'+arguments[i]+'", 0, 1)"'+parseInt(arguments[i+1])+'"');
		setTimeout('glower(\"'+arguments[i]+'\", 0, 1)', parseInt(arguments[i+1]));
	}
}

function addStatus(str) {
	window.status = window.status + str;
}

function makeVisible() {
	var obj = getRef(arguments[0]);
	var bAction = arguments[1];
	var timer = arguments[2];
	if (obj.cc==undefined)
		obj.cc = 0; //create counter
	var cc = obj.cc;
	if (bAction == 0) {
		obj.cc++; //inc to disable pervious actions
		return;
	}
	if (arguments.length > 3)
		cc = arguments[3];
	if (obj.cc!=cc)
	return; //skip action
	switch ( bAction ) {
		default:
			break;
		case 1:
			obj.cc++; //inc to disable pervious actions
			setTimeout('makeVisible(\"'+obj.id+'\",2,0,'+obj.cc+')',timer);
			break;
		case 2:
			obj.style.visibility = "visible";
			break;
	}
}

function unscramble() {
	var aIn = arguments[0].split("");
	var aKe = new Array(1,0,4,2,3);
	var aUn = new Array();
	var sRe = "";
	for ( var i = 0; i <= aIn.length; i++ ) {
		aUn[Math.floor(i/5)*5 + aKe[i%5]] = aIn[i+1];
	}
	for ( var i = 0; i < aUn.length; i++ ) {
		if (aUn[i]!=undefined)
			sRe += aUn[i];
	}
	return sRe;
}
