var popupobj = new Array();

function findPos(obj) {
	var coords = { x: 0, y: 0 };
	if (obj.offsetParent) {
		while (obj) {
			coords.x += obj.offsetLeft;
			coords.y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	return coords.x;
}

function searchinarray(objpop){
	var found = false;
	for (i = 0; i < popupobj.length; i++){
		if (popupobj[i][0] == objpop){
			found = true;
			break;
		}
	}
	if (found)
		return i;
	else
		return "none";
}

function searchhighlight(objimgsrc){
	var found = false;
	for (i = 0; i < imgsrc.length; i++){
		if (objimgsrc.indexOf(imgsrc[i]) != -1){
			found = true;
			break;
		}
	}
	if (found)
		return i;
	else
		return "none";
}

function showpopup(objpop,objparent,objimg){
	//check if objpop already in array
	var founds = searchinarray(objpop);
	if (founds == "none"){
		if (popupobj.length == 0){
			popupobj[0] = new Array(2);
			popupobj[0][0] = objpop;
			popupobj[0][1] = "1";
		}
		else{
			popupobj[popupobj.length] = new Array(2);
			popupobj[popupobj.length][0] = objpop;
			popupobj[popupobj.length][1] = "1";
		}
	}
	else{
		if (popupobj[i][1] == "1"){
			closepopup(objpop,objparent,objimg);
			return;
		}
		else{
			popupobj[i][1] = "1";
		}
	}
	var c = document.getElementById(objpop);
	var d = document.getElementById(objparent);
	var e = document.getElementById(objimg);
	var elpos = findPos(d);
	c.style.left = elpos+'px';
	c.style.bottom = d.offsetHeight+'px';
	c.style.display = 'block';
	d.style.backgroundColor="#FFFFFF";
	e.src=img[searchhighlight(e.src.replace("_off","_on"))].src;
}

function closepopup(objpop,objparent,objimg){
	var founds = searchinarray(objpop);
	if (founds != 'none'){
		if (popupobj[founds][1] == "1"){
			popupobj[founds][1] = "0";
		}
	}
	var c = document.getElementById(objpop);
	var d = document.getElementById(objparent);
	var e = document.getElementById(objimg);
	c.style.display = 'none';
	d.style.backgroundColor="";		
	e.src=img[searchhighlight(e.src.replace("_on","_off"))].src;
}

function objmouseover(objpop,objparent,objimg){
	var founds = searchinarray(objpop);
	if (founds != 'none'){
		if (popupobj[founds][1] == '0'){
			var d = document.getElementById(objparent);
			var e = document.getElementById(objimg);
			d.style.backgroundColor="#FFFFFF";
			e.src=img[searchhighlight(e.src.replace("_off","_on"))].src;
		}
	}
	else{
		var d = document.getElementById(objparent);
		var e = document.getElementById(objimg);
		d.style.backgroundColor="#FFFFFF";
		e.src=img[searchhighlight(e.src.replace("_off","_on"))].src;
	}
}

function objmouseout(objpop,objparent,objimg){
	var founds = searchinarray(objpop);
	if (founds != 'none'){
		if (popupobj[founds][1] == '0'){
			var d = document.getElementById(objparent);
			var e = document.getElementById(objimg);
			d.style.backgroundColor="";
			e.src=img[searchhighlight(e.src.replace("_on","_off"))].src;
		}
	}
	else{
		var d = document.getElementById(objparent);
		var e = document.getElementById(objimg);
		d.style.backgroundColor="";
		e.src=img[searchhighlight(e.src.replace("_on","_off"))].src;
	}
}

function switch_style(C,E){
	var F=C;
	if(F==""){
		return 
	}
	var B=new String(window.location);
	var A=new String("");
	B=B.split("#");
	if(B[1]){
		A="#"+B[1]
	}
	B=B[0];
	if(B.indexOf(E+"id=")!=-1&&is_regexp){
		var D=new RegExp(E+"id=\\d+&?");
		B=B.replace(D,"")
	}
	if(B.indexOf("?")==-1){
		B+="?"
	}
	else{
		lastchar=B.substr(B.length-1);
		if(lastchar!="&"&&lastchar!="?"){
			B+="&"
		}
	}
	window.location=B+E+"id="+F+A
}

function getKeyEvent(e){
	var keynum;
	if(window.event) 
		keynum = e.keyCode;
	else if(e.which) 
		keynum = e.which;
	return keynum;
}

function gotoblog(){
	var uname = document.getElementById("usernamebloggo").value;
	window.open("http://blog.ngobrolaja.com/"+uname,"_blank");
}

function checkenterblog(evt){
	if (getKeyEvent(evt) == 13){
		gotoblog();
	}
}