var vortarobobeloj = new Object();

AldoniStartoFunkcion('preparuBobelojn()');

function preparuBobelojn() {
        var Alk = troviKlase('alklakeblaj',centra);
        for (var x = 0; x < Alk.length; x++) {
            Alk[x].onclick = traduku;
            Alk[x].onmouseover = musoSuper;
            Alk[x].onmouseout = musoFor;
        }
}

var chiujdividostrekoj = new RegExp('-', 'g');
function traduku(e) {
    var obj;
    if (!e) var e = window.event;
    if (e.target) obj = e.target;
    else if (e.srcElement) obj = e.srcElement;
    if (obj.nodeType == 3) { // defeat Safari bug
        obj = targ.parentNode;
    }
    if (!obj || obj.nodeType == 3 || obj.tagName.toLowerCase() != 'var') {
        return;
    }
    alklakotraduko = true;
    ForigiVortaroBobelojn();
    if (!e && window.event) e = window.event;
    var pozx = 0;
    var pozy = 0;
    if (e.pageX || e.pageY) {
        pozx = e.pageX;
        pozy = e.pageY;
    } else if (e.clientX || e.clientY) {
        pozx = e.clientX + document.documentElement.scrollLeft;
        pozy = e.clientY + document.documentElement.scrollTop;
    }
    var fenestrolargho;
    var fenestroalto;
    if (window.innerWidth) {
        fenestrolargho = window.innerWidth;
        fenestroalto = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientWidth) {
        fenestrolargho = document.documentElement.clientWidth;
        fenestroalto = document.documentElement.clientHeight;
    }
    var distancox = e.clientX;
    var distancoy = e.clientY;
    var enhavodiv;
    if (!obj.superbibl) {
        obj.superbibl = document.createElement('div');
        obj.superbibl.pozx = pozx;
        obj.superbibl.pozy = pozy;
        obj.superbibl.distancox = distancox;
        obj.superbibl.distancoy = distancoy;
        obj.superbibl.className = 'vortarobobelo';
        var bobeloid = 'bobelo' + Math.random();
        vortarobobeloj[bobeloid] = bobeloid;
        obj.superbibl.id = bobeloid;
        obj.superbibl.style.zIndex = 10000000;
        obj.superbibl.title = 'Duoble alklaku por reteni la slipeton.';
        obj.superbibl.innerHTML = '<div class="superbiblenhavo">Palaukite...</div><div class="fermilo1" onclick="this.parentNode.gepatro.superbibl = 0; ForigiBobelon(this.parentNode);">X</div><div class="fermilo2" onclick="this.parentNode.gepatro.superbibl = 0; ForigiBobelon(this.parentNode);">X</div><div class="fermilo3" onclick="this.parentNode.gepatro.superbibl = 0; ForigiBobelon(this.parentNode);">X</div><div class="fermilo4" onclick="this.parentNode.gepatro.superbibl = 0; ForigiBobelon(this.parentNode);">X</div>';
        obj.superbibl.gepatro = obj;
        document.body.appendChild(obj.superbibl);
        obj.superbibl.ondblclick = function() { this.className='vortarobobelofiksa'; this.title=''; };
        new Draggable(bobeloid,{handle:bobeloid,revert:false,ghosting:false});
    }
    if (obj.superbibl) {
        obj.superbibl.style.display='block';
        if (obj.superbibl_largho) {
            if (document.all) {
                obj.superbibl.style.width = obj.superbibl_largho + 'em';
            } else obj.superbibl.style.maxWidth = obj.superbibl_largho + 'em';
        } else obj.superbibl.style.width='20em';
        if ((fenestroalto - distancoy) > distancoy) {
            /* Sube */
            obj.superbibl.style.top = (pozy+8) + 'px';
        } else {
            /* Supre */
            var superbiblalto;
            if (obj.superbibl.offsetHeight) superbiblalto = obj.superbibl.offsetHeight;
            else superbiblalto = parseInt(window.getComputedStyle(obj.superbibl,null).height);
            var loko = pozy-superbiblalto-10;
            if (loko < 0) loko = 0;
            obj.superbibl.style.top = loko + 'px';
        }
        if ((fenestrolargho - distancox) > distancox) {
            /* Dekstre */
            var shovo;
            if (window.pageXOffset) shovo = window.pageXOffset;
            else shovo = document.documentElement.scrollLeft;
            obj.superbibl.style.visibility = 'hidden';
            var superbibllargho;
            if (obj.superbibl.offsetWidth) superbibllargho = obj.superbibl.offsetWidth;
            else superbibllargho = parseInt(window.getComputedStyle(obj.superbibl,null).width);
            var loko = pozx;
            obj.superbibl.style.left = loko + 'px';
            if (obj.superbibl_centre) {
                obj.superbibl.style.width = superbibllargho + 'px';
                loko -= superbibllargho/2;
                if (loko - shovo < 0) {
                    obj.superbibl.style.left = shovo + 'px';
                } else {
                    obj.superbibl.style.left = loko + 'px';
                }
            }
            obj.superbibl.style.visibility = 'visible';
        } else {
            /* Maldekstre */
            var shovo;
            if (window.pageXOffset) shovo = window.pageXOffset;
            else shovo = document.documentElement.scrollLeft;
            obj.superbibl.style.visibility = 'hidden';
            var superbibllargho;
            if (obj.superbibl.offsetWidth) superbibllargho = obj.superbibl.offsetWidth;
            else superbibllargho = parseInt(window.getComputedStyle(obj.superbibl,null).width);
            var loko = pozx-superbibllargho;
            if (loko-shovo < 0) loko = shovo;
            obj.superbibl.style.left = loko + 'px';
            if (obj.superbibl_centre) {
                obj.superbibl.style.width = superbibllargho + 'px';
                loko += superbibllargho/2;
                if (loko + superbibllargho > fenestrolargho) {
                    obj.superbibl.style.left = '';
                    obj.superbibl.style.right = (5 - shovo) + 'px';
                } else {
                    obj.superbibl.style.left = loko + 'px';
                }
            }
            obj.superbibl.style.visibility = 'visible';
        }
    }

    //var vorto = "";
    //var enhavo = obj.childNodes;
    //for (var i = 0; i < enhavo.length; i++ ) {
    //    if (enhavo[i].firstChild) {
    //        vorto += enhavo[i].firstChild.nodeValue;
    //    } else if (enhavo[i].nodeValue) {
    //        vorto += enhavo[i].nodeValue;
    //    }
    //}
	var vorto = "";
	var serchovorto = obj.className.match(/^SERCHI:(.*)$/);
	if (serchovorto && serchovorto[1]) {
		vorto = serchovorto[1];
	} else {
		var enhavo = obj.childNodes;
		for (var i = 0; i < enhavo.length; i++ ) {
			if (enhavo[i].firstChild) {
				vorto += enhavo[i].firstChild.nodeValue;
			} else if (enhavo[i].nodeValue) {
				vorto += enhavo[i].nodeValue;
			}
		}
	}
    if (window.frames['vortarokadro'] && window.frames['vortarokadro'].Serchi) {
        vorto = vorto.replace(chiujdividostrekoj,'');
	// Shanghi lauh­bezone al la ghusta vortaro
	var kiulingvo = window.frames['vortarokadro'].ElektiLingvon.selectedIndex;
	if (kiulingvo > 0 && kiulingvo % 2 != 1) {
		window.frames['vortarokadro'].ElektiLingvon.selectedIndex--;
		window.frames['vortarokadro'].ShanghiUzantovortaron();
	}
        window.frames['vortarokadro'].Serchi(vorto,0,obj.superbibl.id);
    }
    if (e) Event.stop(e);
}

function musoSuper(e) {
    var obj;
    if (!e) var e = window.event;
    if (e.target) obj = e.target;
    else if (e.srcElement) obj = e.srcElement;
    if (obj.nodeType == 3) { // defeat Safari bug
        obj = targ.parentNode;
    }
    if (!obj || obj.nodeType == 3 || obj.tagName.toLowerCase() != 'var') {
        return;
    }
    if (window.frames['vortarokadro']) {
        window.obj=obj;
        window.fonKoloro = obj.style.backgroundColor;
        window.deiraTekstOrnamo = obj.style.textDecoration;
        obj.style.backgroundColor = "rgb(255,255,143)";
        obj.style.textDecoration = "underline";
        obj.style.cursor = "help";
    }
}

function musoFor(e) {
    var obj;
    if (!e) var e = window.event;
    if (e.target) obj = e.target;
    else if (e.srcElement) obj = e.srcElement;
    if (obj.nodeType == 3) { // defeat Safari bug
        obj = targ.parentNode;
    }
    if (!obj || obj.nodeType == 3 || obj.tagName.toLowerCase() != 'var') {
        return;
    }
    if (window.frames['vortarokadro']) {
        window.obj=obj;
        obj.style.backgroundColor = window.fonKoloro;
        obj.style.textDecoration = window.deiraTekstOrnamo;
    }
}

function GhustigiPozicion(id) {
    var obj = document.getElementById(id);
    if (obj) {
        var pozx = obj.pozx;
        var pozy = obj.pozy;
        var fenestrolargho;
        var fenestroalto;
        if (window.innerWidth) {
            fenestrolargho = window.innerWidth;
            fenestroalto = window.innerHeight;
        } else if (document.documentElement && document.documentElement.clientWidth) {
            fenestrolargho = document.documentElement.clientWidth;
            fenestroalto = document.documentElement.clientHeight;
        }
        var distancox = obj.distancox;
        var distancoy = obj.distancoy;
        obj.style.display='block';
        if (obj.superbibl_largho) {
            if (document.all) {
                obj.style.width = obj.superbibl_largho + 'em';
            } else obj.style.maxWidth = obj.superbibl_largho + 'em';
        } else obj.style.width='20em';
        if ((fenestroalto - distancoy) > distancoy) {
            /* Sube */
            obj.style.top = (pozy+8) + 'px';
        } else {
            /* Supre */
            var superbiblalto;
            if (obj.offsetHeight) superbiblalto = obj.offsetHeight;
            else superbiblalto = parseInt(window.getComputedStyle(obj,null).height);
            var loko = pozy-superbiblalto-10;
            if (loko < 0) loko = 0;
            obj.style.top = loko + 'px';
        }
        if ((fenestrolargho - distancox) > distancox) {
            /* Dekstre */
            var shovo;
            if (window.pageXOffset) shovo = window.pageXOffset;
            else shovo = document.documentElement.scrollLeft;
            obj.style.visibility = 'hidden';
            var superbibllargho;
            if (obj.offsetWidth) superbibllargho = obj.offsetWidth;
            else superbibllargho = parseInt(window.getComputedStyle(obj,null).width);
            var loko = pozx;
            obj.style.left = loko + 'px';
            if (obj.superbibl_centre) {
                obj.style.width = superbibllargho + 'px';
                loko -= superbibllargho/2;
                if (loko - shovo < 0) {
                    obj.style.left = shovo + 'px';
                } else {
                    obj.style.left = loko + 'px';
                }
            }
            obj.style.visibility = 'visible';
        } else {
            /* Maldekstre */
            var shovo;
            if (window.pageXOffset) shovo = window.pageXOffset;
            else shovo = document.documentElement.scrollLeft;
            obj.style.visibility = 'hidden';
            var superbibllargho;
            if (obj.offsetWidth) superbibllargho = obj.offsetWidth;
            else superbibllargho = parseInt(window.getComputedStyle(obj,null).width);
            var loko = pozx-superbibllargho;
            if (loko-shovo < 0) loko = shovo;
            obj.style.left = loko + 'px';
            if (obj.superbibl_centre) {
                obj.style.width = superbibllargho + 'px';
                loko += superbibllargho/2;
                if (loko + superbibllargho > fenestrolargho) {
                    obj.style.left = '';
                    obj.style.right = (5 - shovo) + 'px';
                } else {
                    obj.style.left = loko + 'px';
                }
            }
            obj.style.visibility = 'visible';
        }
    }
}

function ForigiBobelon(bob) {
    vortarobobeloj[bob.id] = 0;
    Element.remove(bob);
}

function ForigiVortaroBobelojn() {
    for (var b in vortarobobeloj) {
        if (b) {
            var bobelo = $(b);
            if (bobelo && bobelo.className == 'vortarobobelo') {
                bobelo.gepatro.superbibl = 0;
                Element.remove(bobelo);
            }
        }
    }
}
