if(top && top != this) {
  top.location.href = this.location.href;
}

var IE = document.all && window.external;
var tools = new Array();
var toolbox = document.createElement("div");
toolbox.id = "tooltip";
toolbox.style.display = "none";
var box = null;

function goInitIt() {
  if(document.referrer.length > 12 && !document.referrer.match("suck.dk/")) {
    reghit = new Image();
    reghit.src = "/env/reghit.php?r=" + escape(document.referrer);
  }
  if(IE) {
    imgalts = document.getElementsByTagName("img");
    for(i = 0; i < imgalts.length; i++) {
      imgalts[i].setAttribute("alt", "");
    }
  }
  document.body.appendChild(toolbox);
  moveTop(0);
}

function getDim() {
	var windowWidth, windowHeight;
	if(self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if(document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
  if(self.pageYOffset) {
    scrollY = self.pageYOffset;
  } else if(document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
    scrollY = document.documentElement.scrollTop;
  } else if(document.body) {// all other Explorers
    scrollY = document.body.scrollTop;
  }
  return new Array(windowWidth, windowHeight, scrollY);
}

function showPicture(url) {
  document.getElementById("overlay").style.display = "block";
  pcw = document.getElementById("pictureviewer");
  pcw.innerHTML = "<img src='" + url + "' style='padding: 10px; border: 1px solid #000000; background-color: #FFFFFF;'>";
  pcw.style.top = (dims[2] + 25) + "px";
  pcw.style.display = "block";
  return false;
}

function killPicture() {
  document.getElementById("pictureviewer").style.display = "none";
  document.getElementById("overlay").style.display = "none";
}

function moveTop(cul) {
  thetop = document.getElementById("headerbox");
  if(thetop.style.backgroundPosition == '0px 0px') {
    thetop.style.backgroundPosition = '-5px 0px';
  } else {
    thetop.style.backgroundPosition = '0px 0px';
  }
  if(cul < 10) {
    setTimeout("moveTop(" + (cul + 1) + ")", 100);
  }
}

function tooltip(obj) {
  if(!obj.onmouseout) {
    obj.onmouseout = tooltipDie;
    obj.setAttribute("tooltext", obj.getAttribute("title"));
    obj.setAttribute("title", "");
  }
  if(!(toolid = obj.getAttribute("toolid"))) {
    toolid = tools.length;
    obj.setAttribute("toolid", toolid);
    tools[toolid] = obj;
  }
  tooltipPos;
  document.onmousemove = tooltipPos;
  obj.setAttribute("toolcheck", "1");
  setTimeout("tooltipLive(" + toolid + ")", 100);
}

function tooltipLive(toolid) {
  obj = tools[toolid];
  if(obj.getAttribute("toolcheck") == 1) {
    toolbox.innerHTML = obj.getAttribute("tooltext");
    toolbox.style.display = "block";
  }
}

function tooltipPos(e) {
  if(IE) {
    tempX = event.clientX + (document.documentElement ? document.documentElement.scrollLeft : document.body.scrollLeft);
    tempY = event.clientY + (document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop);
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }
  limiX = document.body.offsetWidth;
  if(tempX + 10 + toolbox.offsetWidth > limiX) {
    tempX = tempX - ((tempX + 10 + toolbox.offsetWidth) - limiX);
  }
  toolbox.style.left = (10 + tempX) + "px";
  toolbox.style.top = (10 + tempY) + "px";
}

function tooltipDie() {
  this.setAttribute("toolcheck", "0");
  toolbox.style.display = "none";
  document.onmousemove = null;
}

function getPos(elm) {
  for(var zx = zy = 0; elm != null; zx += elm.offsetLeft, zy += elm.offsetTop, elm = elm.offsetParent);
  return {x:zx,y:zy};
}

function starover(obj) {
  stars = parseInt(obj.id);
  for(i = 1; i <= 5; i++) {
    document.getElementById(i + "star").src = "/env/" + (i > stars ? "dark" : "") + "star.png";
  }
}

function starvote(obj) {
  stars = parseInt(obj.id);
  quickload("/env/rate.php?checksum=" + obj.getAttribute("checksum") + "&r=" + stars + "&o=" + obj.getAttribute("rating"));
  for(i = 1; i <= 5; i++) {
    document.getElementById(i + "star").style.cursor = "default";
    document.getElementById(i + "star").onmouseover = null;
  }
}

function quickload(url) {
  quickobj = new Image();
  quickobj.src = url;
}

function getCoords(e) {
  if(IE) {
    tempX = event.clientX + (document.documentElement ? document.documentElement.scrollLeft : document.body.scrollLeft);
    tempY = event.clientY + (document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop);
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }
  return {x:tempX, y:tempY};
}
