//
// (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;
var inAnimation = false;
var aktuell, addieren;

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

var werbungen = new Array(2);
werbungen[0] = '<DIV ID="popup" STYLE="top: 28px; left: 10px; width: 204px; height: 358px;"><DIV ID="popup_kopf"><DIV ID="popup_titel" onMousedown="schiebe_box();">Hundeerziehung</DIV><DIV ID="popup_icons"><A HREF="#" onClick="klappe_inhalt(); return false;"><IMG SRC="http://www.polar-chat.de/empfehlung/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="http://www.polar-chat.de/empfehlung/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"><A HREF="http://www.amazon.de/gp/product/3837008576?ie=UTF8&tag=hundeschule0d-21&linkCode=as2&camp=1638&creative=6742&creativeASIN=3837008576" TARGET="_blank"><IMG SRC="http://www.polar-chat.de/empfehlung/buch.jpg" ALT="Hundeerziehung leicht gemacht" BORDER=0 WIDTH=198 HEIGHT=332></A><BR></DIV></DIV>';
werbungen[1] = '<DIV ID="popup" STYLE="top: 28px; left: 10px; width: 204px; height: 358px;"><DIV ID="popup_kopf"><DIV ID="popup_titel" onMousedown="schiebe_box();">Hundeerziehung</DIV><DIV ID="popup_icons"><A HREF="#" onClick="klappe_inhalt(); return false;"><IMG SRC="http://www.polar-chat.de/empfehlung/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="http://www.polar-chat.de/empfehlung/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"><A HREF="http://www.amazon.de/gp/product/3837008576?ie=UTF8&tag=hundeschule0d-21&linkCode=as2&camp=1638&creative=6742&creativeASIN=3837008576" TARGET="_blank"><IMG SRC="http://www.polar-chat.de/empfehlung/buch.jpg" ALT="Hundeerziehung leicht gemacht" BORDER=0 WIDTH=198 HEIGHT=332></A><BR></DIV></DIV>';


function init( verzoegerung, geschwindigkeit, schrittweite) {
  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;

  setTimeout( "zeige_box()", verzoegerung);
}

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 setze_opacity( div, v) {
  div.style.opacity = (v / 100);
  div.style.MozOpacity = (v / 100);
  div.style.filter = "alpha(opacity=" + 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 zeigen() {
  if (inAnimation) {
    aktuell  += addieren;
    addieren += s;

    if (aktuell >= 100) {
      inAnimation = false;
      setze_opacity( box, 100);
    }
    else {
      setze_opacity( box, aktuell);
      setTimeout( "zeigen()", g);
    }
  }
}

function zeige_box() {
  if ((!is_nav4) && (!is_ie3) && (!is_ie4)) {
    aktuell  = s;
    addieren = s;
    setze_opacity( box, aktuell);

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

    inAnimation = true;
    setTimeout( "zeigen()", g);
  }
}

function schliesse_box() {
  setze_visibility( box, "hidden");
  setze_visibility( inhalt, "hidden");
}

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]);
  }
}