// On Mouse Over Invisible Box - V 1.0
// Programmer Adrian Diacon
// Developed for SC Graffco SRL 25.09.2006

function gEnableBoxes(id){
	var areas,links,i,c;
	if(!document.getElementById(id) || !document.getElementsByTagName) return;
	
//	spanul nou creat va avea id-ul gBox si position absolute	
	c=document.createElement("span");
	c.id="gBox";
	c.setAttribute("id","gBox");
	c.style.position="absolute";
	
//	adunarea colectiilor de area si linkuri	
	document.getElementsByTagName("body")[0].appendChild(c);
	if(id==null) {
		areas=document.getElementsByTagName("area");
		links=document.getElementsByTagName("a");
	} else {
		areas=document.getElementById(id).getElementsByTagName("area");
		links=document.getElementById(id).getElementsByTagName("a");
	}
	
//	pregatirea area	
	for(i=0;i<areas.length;i++){
		Prepare(areas[i]);
	}
//	pregatirea linkurilor	
	for(i=0;i<links.length;i++){
		Prepare(links[i]);
	}
}

function Prepare(el){
	var boxover,b,s,im,image,con,con_array;

// fix bug de sa nu mai afiseze alt si title pentru linkuri si area
	el.removeAttribute("title");
	el.removeAttribute("alt");

// prelucrat continutul boxurilor preluat din onmouseover
	con = new String(el.getAttribute("onmouseover"));
	if(con!='null' && navigator.appName == 'Microsoft Internet Explorer'){
		con = con.replace("function anonymous()", "");
		con = con.replace("{", "");
		con = con.replace("}", "");
		if(con!='null' && con.substr(2,8)=="gShowBox" ) {
			gShowBoxOver(con,el);
		}
	} else {
		if(con!='null' && con.substr(0,8)=="gShowBox" ) {
			gShowBoxOver(con,el);
		}	
	}
	
}

// prelucreaza showbox
function gShowBoxOver(con,el){
	var image_src;
	con = con.replace("gShowBox(", "");
	con = con.replace(");", "");
	
	con_array = con.split("','");
	var part_num=0;
	while (part_num < con_array.length) {
	  con_array[part_num] = con_array[part_num].replace("'","");// prima ghilimea
	  con_array[part_num] = con_array[part_num].replace("'","");// a doua ghilimea
	  part_num+=1;
	}
	
//		cream span cu class boxover
	boxover=CreateEl("span","boxover");
//	introducem poza daca exista in partea de sus cu class boximage
	if(con_array[2]!='null'){
		if( navigator.appName == 'Microsoft Internet Explorer' ){
			image_src = con_array[2].substr(2,con_array[2].length);
		} else {
			image_src = con_array[2];
		}
		if(image_src!=''){
			im=CreateEl("span","boxim");
			im.setAttribute("id","boxim");
			boxover.appendChild(im);
			image=CreateEl("img","boximage");
			image.setAttribute("src",image_src);
			
			image.setAttribute("width",100);
			
			if(image.height > 100 && navigator.appName == 'Microsoft Internet Explorer'){
				image.setAttribute("height",100);
			}
			image.setAttribute("id","boximage");
			im.appendChild(image);
		} else{
			im=CreateEl("span","boxnoim");
			im.setAttribute("id","boxnoim");
			boxover.appendChild(im);
		}
		
	}
//		introducem info de header daca exista in partea de sus cu class boxtop
	if(con_array[0]!='null'){
		s=CreateEl("span","top");
		s.setAttribute("id","boxtop");
		s.appendChild(document.createTextNode(con_array[0]));
		boxover.appendChild(s);
	}
//		introducem info de descriere daca exista in partea de jos cu class boxbottom
	if(con_array[1]!='null'){
		b=CreateEl("b","bottom");
		b.setAttribute("id","boxbottom");
		b.appendChild(document.createTextNode(con_array[1]));
		boxover.appendChild(b);
	}
	
	el.boxover=boxover;
	el.onmouseover=showBox;
	el.onmouseout=hideBox;
	el.onmousemove=FindMouse;	
}

// arata elementul curent
function showBox(e){
	document.getElementById("gBox").appendChild(this.boxover);
	FindMouse(e);
}

// ascunde elementul curent
function hideBox(e){
	var d=document.getElementById("gBox");
	if(d.childNodes.length>0){
		d.removeChild(d.firstChild);
	}
}

// creaza un nou element html
function CreateEl(t,c){
	var x=document.createElement(t);
	x.className=c;
	x.style.display="block";
	return(x);
}

// cauta tot timpul pozitia mouse-ului pe ecran
function FindMouse(e){
	var posx=0,posy=0;
	if(e==null) {
		e=window.event;
	}
	if(e.pageX || e.pageY){
		posx=e.pageX; posy=e.pageY;
	} else if(e.clientX || e.clientY){
		if(document.documentElement.scrollTop){
			posx=e.clientX+document.documentElement.scrollLeft;
			posy=e.clientY+document.documentElement.scrollTop;
		} else {
			posx=e.clientX+document.body.scrollLeft;
			posy=e.clientY+document.body.scrollTop;
		}
	}
	document.getElementById("gBox").style.top=(posy+10)+"px";
	document.getElementById("gBox").style.left=(posx-20)+"px";
}
// cauta tot timpul pozitia mouse-ului pe ecran special pentru partea dreapta a ecranului
function FindMouseRight(e){
	var posx=0,posy=0;
	if(e==null) {
		e=window.event;
	}
	if(e.pageX || e.pageY){
		posx=e.pageX; posy=e.pageY;
	} else if(e.clientX || e.clientY){
		if(document.documentElement.scrollTop){
			posx=e.clientX+document.documentElement.scrollLeft;
			posy=e.clientY+document.documentElement.scrollTop;
		} else {
			posx=e.clientX+document.body.scrollLeft;
			posy=e.clientY+document.body.scrollTop;
		}
	}
	document.getElementById("gBox").style.top=(posy+10)+"px";
	document.getElementById("gBox").style.left=(posx-220)+"px";
}

// functiile apelata la onmouseover nu face nimic
function gShowBox(title,description,image){
	return;
}
