//
// (c) 2004 Stefan Ruettinger
// http://www.homepage-erfolg.de/
//
var agt      = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav  = ((agt.indexOf('mozilla') != -1) &&
               (agt.indexOf('spoofer') == -1) &&
               (agt.indexOf('compatible') == -1) &&
               (agt.indexOf('opera') == -1) &&
               (agt.indexOf('webtv') == -1) &&
               (agt.indexOf('hotjava') == -1));
var is_nav4 = (is_nav && (is_major <= 4));

var is_ie   = ((agt.indexOf("msie") != -1) &&
               (agt.indexOf("opera") == -1));
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) &&
              (agt.indexOf("msie 4")!=-1));
var is_ie5  = (is_ie && (is_major == 4) &&
              (agt.indexOf("msie 5")!=-1));

var box, inhalt;
var deltaX, deltaY;
var zielX, zielY, zielW, zielH;
var aX, aY;
var g, s, r, h;
var inAnimation = false;

var zeit = (new Date()).getTime();
var cookies = document.cookie.split( "; ");
var cookie;

var werbungen = new Array(2);
werbungen[0] = '<DIV ID="popup" STYLE="top: 100px; left: 400px; width: 304px; height: 426px;"><DIV ID="popup_kopf"><DIV ID="popup_titel" onMousedown="schiebe_box();">Serious Piercing - NEWS -</DIV><DIV ID="popup_icons"><A HREF="#" onClick="klappe_inhalt(); return false;"><IMG SRC="../popup_roll-in_out/aufundzu.png" WIDTH=16 HEIGHT=16 BORDER=0 HSPACE=2 ALT="Auf-/Zuklappen" TITLE="Auf-/Zuklappen"></A><A HREF="#" onClick="schliesse_box(); return false;"><IMG SRC="../popup_roll-in_out/schliessen.png" WIDTH=16 HEIGHT=16 BORDER=0 HSPACE=2 ALT="Schlie&szlig;en" TITLE="Schlie&szlig;en"></A><BR></DIV></DIV><DIV ID="popup_inhalt"><IMG SRC="../popup_roll-in_out/werbung.png" ALT="Popup-Fenster" BORDER=0 WIDTH=300 HEIGHT=400><BR></DIV></DIV>';
werbungen[1] = '<DIV ID="popup" STYLE="top: 100px; left: 400px; width: 304px; height: 426px;"><DIV ID="popup_kopf"><DIV ID="popup_titel" onMousedown="schiebe_box();">Serious Piercing - NEWS -</DIV><DIV ID="popup_icons"><A HREF="#" onClick="klappe_inhalt(); return false;"><IMG SRC="../popup_roll-in_out/aufundzu.png" WIDTH=16 HEIGHT=16 BORDER=0 HSPACE=2 ALT="Auf-/Zuklappen" TITLE="Auf-/Zuklappen"></A><A HREF="#" onClick="schliesse_box(); return false;"><IMG SRC="../popup_roll-in_out/schliessen.png" WIDTH=16 HEIGHT=16 BORDER=0 HSPACE=2 ALT="Schlie&szlig;en" TITLE="Schlie&szlig;en"></A><BR></DIV></DIV><DIV ID="popup_inhalt"><IMG SRC="../popup_roll-in_out/werbung.png" ALT="Popup-Fenster" BORDER=0 WIDTH=300 HEIGHT=400><BR></DIV></DIV>';


function init( verzoegerung, geschwindigkeit, schrittweite, hoehe) {
  if (is_ie5) { box    = document.all.popup;
                inhalt = document.all.popup_inhalt; }
  else        { box    = document.getElementById('popup');
                inhalt = document.getElementById('popup_inhalt'); }

  g = geschwindigkeit;
  s = schrittweite;
  h = hoehe;

  if ((box != null) && (inhalt != null)) {
    setTimeout( "zeige_box()", verzoegerung);
  }
}

function hole_width( div) {
  var w;

  if (is_ie5) { w = div.style.pixelWidth; }
  else        { w = parseInt( div.style.width); }

  return w;
}

function setze_width( div, w) {
  if (is_ie5) { div.style.pixelWidth = w; }
  else        { div.style.width = w + "px"; }
}

function hole_height( div) {
  var h;

  if (is_ie5) { h = div.style.pixelHeight; }
  else        { h = parseInt( div.style.height); }

  return h;
}

function setze_height( div, h) {
  if (is_ie5) { div.style.pixelHeight = h; }
  else        { div.style.height = h + "px"; }
}

function hole_left( div) {
  var x;

  if (is_ie5) { x = div.style.pixelLeft; }
  else        { x = parseInt( div.style.left); }

  return x;
}

function hole_top( div) {
  var y;

  if (is_ie5) { y = div.style.pixelTop; }
  else        { y = parseInt( div.style.top); }

  return y;
}

function hole_visibility( div) {
  return div.style.visibility;
}

function setze_visibility( div, v) {
  div.style.visibility = v;
}

function hole_cookie( name) {
  if (cookies != null) {
    for (var i = 0; i < cookies.length; i++) {
      cookie = cookies[i].split( "=");
      if (cookie[0] == name)
        return unescape( cookie[1]);
    }
  }

  return null;
}

function setze_cookie( name, wert) {
  var ablauf  = new Date( zeit + (14 * 24 * 60 * 60 * 1000));

  document.cookie = name + "=" + escape( wert) + "; expires=" + ablauf.toGMTString();
}

function bewegen() {
  var stop = 0;

  if (inAnimation) {
    if (r == 2) { aY += s; }
    if (r == 8) { aY -= s; }

    if ((r == 2) && (aY >= zielY)) { stop = 1; }
    if ((r == 8) && (aY <= zielY)) { stop = 1; }

    if (stop == 1) {
      inAnimation = false;
      setze_position( inhalt, zielX, zielY);

      if (r == 8) {
        setze_visibility( box, "hidden");
        setze_visibility( inhalt, "hidden");
      }
    }
    else {
      setze_position( inhalt, aX, aY);
      setTimeout( "bewegen()", g);
    }
  }
}


function zeige_box() {
  if ((!is_nav4) && (!is_ie3) && (!is_ie4)) {
    zielX = 0;
    zielY = 22;
    zielH = h;

    aX = zielX;
    aY = zielY - zielH;

    setze_position( inhalt, aX, aY);

    setze_visibility( box, "visible");
    setze_visibility( inhalt, "visible");

    r = 2;
    inAnimation = true;
    setTimeout( "bewegen()", g);
  }
}

function schliesse_box() {
  zielY = -zielH;

  r = 8;
  inAnimation = true;
  setTimeout( "bewegen()", g);
}

 function klappe_inhalt() {
  if (hole_visibility( inhalt) == "visible")
    setze_visibility( inhalt, "hidden");
  else
    setze_visibility( inhalt, "visible");
}

function setze_position( div, x, y) {
  if (is_ie5) { div.style.pixelLeft = x;
                div.style.pixelTop  = y; }
  else        { div.style.left = x + "px";
                div.style.top  = y + "px"; }
}

function position( e) {
  if (is_ie) { deltaX = event.clientX - hole_left( box);
               deltaY = event.clientY - hole_top( box); }
  else       { document.captureEvents( Event.MOUSEMOVE | Event.MOUSEUP); 
               deltaX = e.clientX - hole_left( box);
               deltaY = e.clientY - hole_top( box); }

  document.onmousemove = drag;
  document.onmouseup   = drop;

  return false;
}

function drag( e) {
  if (is_ie) {
    setze_position( box, event.clientX - deltaX,
                         event.clientY - deltaY);
  }
  else {
    setze_position( box, e.clientX - deltaX,
                         e.clientY - deltaY);
  }

  return false;
}

function drop() {
  if (!is_ie) {
    document.releaseEvents( Event.MOUSEMOVE | Event.MOUSEUP);
  }

  document.onmousemove = null;
  document.onmouseup   = null;
  box.onmousedown = null;
}

function schiebe_box() {
  box.onmousedown = position;
}

function waehle_werbung( sperrzeit) {
  var zuletzt = hole_cookie( "popup");

  if ((zuletzt == null) || ((zeit - zuletzt) > sperrzeit)) {
    setze_cookie( "popup", zeit);

    var zufall  = Math.floor( Math.random() * werbungen.length);
    document.writeln( werbungen[zufall]);
  }
}
