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";
toolbox.style.filter = "alpha(opacity=80)";

var overlayer = document.createElement("div");
overlayer.id = "overlay";
overlayer.style.display = "none";
overlayer.style.filter = "alpha(opacity=80)";
overlayer.onclick = killAll;

var theFramer = document.createElement("div");
theFramer.id = "theframe";
theFramer.style.display = "none";

function goInitIt() {
  if(IE) {
    imgalts = document.getElementsByTagName("img");
    for(i = 0; i < imgalts.length; i++) {
      imgalts[i].setAttribute("alt", "");
    }
  }
  document.body.appendChild(toolbox);
  document.body.appendChild(overlayer);
  document.body.appendChild(theFramer);
}

function killAll() {
  overlayer.style.display = "none";
  theFramer.innerHTML = "";
  theFramer.style.display = "none";
  if(apsi = document.getElementById('allpaysites')) {
    apsi.style.display = "none";
  }
  if(apsi = document.getElementById('allstreams')) {
    apsi.style.display = "none";
  }
}

function enableOverlay() {
  tempY = getPos(document.getElementById("verybottom"));
//  overlayer.style.height = tempY.y + "px";
  overlayer.style.display = "block";
}

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(bam) {
  enableOverlay();
  dims = getDim();
  theFramer.style.top = (dims[2] + 75) + "px";
  theFramer.style.marginLeft = "-375px";
  theFramer.style.width = "750px";
  theFramer.innerHTML = "<div style='text-align: center;' onclick='killAll()'><img src='" + bam.href + "' onclick='killAll()'></div>";
  theFramer.style.display = "block";
  return false;
}

function showMovie(mov) {
  enableOverlay();
  dims = getDim();
  theFramer.style.top = (dims[2] + 75) + "px";
  theFramer.style.marginLeft = "-325px";
  theFramer.style.width = "650px";
  theFramer.style.height = "395px";
  theFramer.innerHTML = "<div class='title'>" + mov.title + "</div><br><iframe src='" +  mov.href + "' width='650px' height='395px' frameborder='0' scrolling='no'></iframe>";
  theFramer.style.display = "block";
  return false;
}

function showPsites() {
  enableOverlay();
  apsites = document.getElementById('allpaysites');
  dims = getDim();
  apsites.style.top = (dims[2] + 75) + "px";
  apsites.style.display = "block";
}

function showPfilms() {
  enableOverlay();
  apsites = document.getElementById('allstreams');
  imgs = apsites.getElementsByTagName('img');
  for(i = 0; i < imgs.length; i++) {
    if(!imgs[i].src) {
      imgs[i].src = imgs[i].getAttribute("nosrc");
    }
  }
  dims = getDim();
  apsites.style.top = (dims[2] + 75) + "px";
  apsites.style.display = "block";
}

function writeMenu() {
  document.write("Menu: &nbsp; <a href='javascript:void(showPsites())'>Sexbiografer</a> &nbsp; <a href='javascript:void(showPfilms())'>Dagens pornofilm</a> &nbsp; <a href='http://" + document.domain + "/' title='" + document.domain.charAt(0).toUpperCase() + document.domain.substr(1) + "' rel='sidebar' onclick='return bookmark(this)'>Føj til foretrukne</a>");
}

function bookmark(anchor) {
  if(window.external) {
    window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
    return false;
  }
  return true;
}

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 doSelect(total, selected, url) {
  if(total < 1) {
    total = 1;
  }
  document.write(" - Side ");
  document.write("<select style='font-size: 20px; width: 65px; font-weight: bold; margin: -1px 0px -1px 0px;' onchange='document.location.href = \"" + url + "\" + this.value;'>");
  for(i = 1; i <= total; i++) {
    document.write("<option value='" + i + "'" + (i == selected ? " selected" : "") + ">" + i + "</option>");
  }
  if(selected > total) {
    document.write("<option value='" + selected + "' selected>" + selected + "</option>");
  }
  document.write("</select>");
  document.write(" af " + total);
}

function doCommForm(ida) {
  document.write("<form action='" + document.URL + "' method='post' onsubmit='if(this.cauthor.value.length < 2 || this.ccontent.value.length < 50) { alert(\"Du skal skrive dit navn og din kommentar skal have en længde på mindst 50 tegn.\"); return false; }'>");
  document.write("<table><tr>");
  document.write("<td style='padding: 3px; vertical-align: middle;'>Dit navn:</td>");
  document.write("<td style='padding: 3px; vertical-align: middle;'><input type='text' name='cauthor' maxlength='25' style='width: 300px;'><input type='hidden' name='cblog_id' value='" + ida + "'></td>");
  document.write("</tr><tr>");
  document.write("<td style='padding: 3px;'>Kommentar:&nbsp;</td>");
  document.write("<td style='padding: 3px; vertical-align: middle;'><textarea name='ccontent' style='width: 300px; height: 75px;'></textarea></td>");
  document.write("</tr><tr>");
  document.write("<td style='padding: 3px;'>&nbsp;</td>");
  document.write("<td style='padding: 3px;'><input type='submit' value='Send' style='width: 50px;'></td>");
  document.write("</tr></table>");
  document.write("</form>");
}

function doFlash(ff, ww, hh) {
  document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='" + ww + "px' height='" + hh + "px'>"
               + "<param name='movie' value='" + ff + "'>"
               + "<param name='menu' value='false'>"
               + "<param name='quality value='best'>"
               + "<param name='wmode' value='transparent'>"
               + "<embed src='" + ff + "' menu='false' quality='best' wmode='transparent' width='" + ww + "px' height='" + hh + "px' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed>"
               + "</object>");
}

function doTube(obj) {
  enableOverlay();
  dims = getDim();
  theFramer.style.top = (dims[2] + 75) + "px";
  theFramer.style.marginLeft = "-375px";
  theFramer.style.width = "750px";
  theFramer.innerHTML = "<div style='text-align: center;'>"
                      + tubesource[obj.getAttribute("tubesource_id")].replace(/\[video_id\]/g, obj.getAttribute("video_id"))
                      + "<div id='showtubead' style='padding: 10px 50px 0px 50px;'>"
                      + document.getElementById("tubeads").innerHTML
                      + "</div>"
                      + "</div>";
  theFramer.style.display = "block";
}
