var langThisBox = null; var langThisBoxCss = "display: none; left: 80px; top: 200px; position: absolute; z-index: 1042; border: 2px solid silver; background-color: #fff;"; function CreateLangThisBox() { var iframeUrl = "http://www.langthis.com/translate.php?url=" + location.href + "&from=gb&site=&user="; var divBox = document.createElement("div"); divBox.style.cssText = langThisBoxCss; var topBarDiv = document.createElement("div"); topBarDiv.style.textAlign = "left"; divBox.appendChild(topBarDiv); var closeLink = document.createElement("a"); closeLink.setAttribute("href", "javascript:void(0);") closeLink.onclick = function() { langThisBox.style.display = "none"; } topBarDiv.appendChild(closeLink); var closeImg = document.createElement("img"); closeImg.setAttribute("alt", "X"); closeImg.setAttribute("src", "http://www.langthis.com/img/close.png"); closeImg.setAttribute("border", "0"); closeImg.setAttribute("style", "outline:none;float:right;"); closeLink.appendChild(closeImg); var iframe = document.createElement("iframe"); iframe.setAttribute("src", iframeUrl); iframe.setAttribute("scrolling", "no"); iframe.setAttribute("frameBorder", "0"); iframe.setAttribute("width", "260"); iframe.setAttribute("height", "160"); divBox.appendChild(iframe); document.body.insertBefore(divBox, document.body.firstChild); return divBox; } function GetElementsByClassName(className, parent) { var result = new Array(); var regex = new RegExp(className + "(?:$| )"); for(var i = 0; i < parent.childNodes.length; i++) { if(regex.test(parent.childNodes[i].className)) result.push(parent.childNodes[i]); var temp = GetElementsByClassName(className, parent.childNodes[i]); for(var j = 0; j < temp.length; j++) result.push(temp[j]); } return result; } function LangThisMouseOver(e) { if(langThisBox.style.display == "none") { langThisBox.style.display = "block"; var left = this.offsetLeft; var top = this.offsetTop + this.offsetHeight; var boxWidth = langThisBox.offsetWidth; var boxHeight = langThisBox.offsetHeight; var windowHeight = 0; var windowWidth = 0; if(typeof(window.innerWidth ) == 'number' ) { windowWidth = window.innerWidth; windowHeight = window.innerHeight; } else { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } if(left + boxWidth - getScrollWidth() >= windowWidth) left = this.offsetLeft + this.offsetWidth - boxWidth; if(top + boxHeight - getScrollTop() >= windowHeight) top = this.offsetTop - boxHeight; langThisBox.style.left = left + "px"; langThisBox.style.top = top + "px"; } else langThisBox.style.display = "none"; return false; } function getScrollTop() { var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop; return h ? h : 0; } function getScrollWidth() { var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft; return w ? w : 0; } window.onload = function() { langThisBox = CreateLangThisBox(); var elements = GetElementsByClassName("langthis", document.body); for(var i = 0; i < elements.length; i++) { var element = elements[i]; element.onmouseover = LangThisMouseOver; element.onclick = LangThisMouseOver; } }