/* Eingeblendete Div oben am Fensterrand, unterer Rand immer sichtbar */

(function($)
{
 apx.topMoveDiv = {
  oTimer: null,
  oScrollTimer: null,
  bBleibtOffen: false,
  bWirdAngezeigt: false,
  nStartHoehe: 0,
  fnEndeAnzeigen: null,
  optionen: { hoehe: 100, datei: "", htmlstringid: "", id: "", bgclass: "", bgclass_ie: "", offsetdiv: "", offsetdivleftkorr: 0, visible: true },
  init: function(opt)
  {
   this.optionen = $.extend(this.optionen, opt);
   $("body").append('<div id="' + this.optionen.id + '" class="' + this.optionen.bgclass + '"><div></div></div>');
   this.optionen.id = "#" + this.optionen.id;
   if(this.optionen.bgclass_ie != "" && !jQuery.support.opacity)
   {
    $(this.optionen.id).removeClass(this.optionen.bgclass);
    $(this.optionen.id).addClass(this.optionen.bgclass_ie);
   }
   this.nStartHoehe = $(this.optionen.id).height();
   this.positionieren();
   if(this.optionen.visible)
   {
    if(this.optionen.datei == "")
     this.aktualisierenMitTagInhalt();
    else
     this.aktualisieren();
    this.anzeigenRandUnten();
   }
   var self = this;

   $(window).scroll(function()
   {
    self.positionieren();
    if(self.optionen.visible && $(self.optionen.id).height() == self.nStartHoehe && !self.bWirdAngezeigt)
    {
     $(self.optionen.id).hide(0);
     if(!self.oScrollTimer)
      self.oScrollTimer = window.setTimeout("apx.topMoveDiv.anzeigenRandUnten()", 1000);
    }
   });

   $(window).resize(function()
   {
    self.positionieren();
   });

   $(this.optionen.id).mouseleave(function()
   {
    if(self.bBleibtOffen)
    {
     self.bBleibtOffen = false;
     if(parseInt($(self.optionen.id).height()) == self.optionen.hoehe)
      self.ausblenden();
    }
   });

   $(this.optionen.id).mouseover(function()
   {
    if(self.oTimer)
     window.clearTimeout(self.oTimer);
    if($(self.optionen.id).height() == self.nStartHoehe)
     self.anzeigen();
    self.bBleibtOffen = true;
   });
  },

  aktualisieren: function()
  {
   $(this.optionen.id + " > div").load(this.optionen.datei);
  },

  aktualisierenMitTagInhalt: function()
  {
   $(this.optionen.id + " > div").html($("#" + this.optionen.htmlstringid).html());
  },

  positionieren: function()
  {
   var nLeft = 0;
   if(this.optionen.offsetdiv == "")
   {
    nLeft = parseInt(($(window).width() - $(this.optionen.id).width()) / 2);
   }
   else
   {
    var offs = $(this.optionen.offsetdiv).offset();
    nLeft = offs.left + this.optionen.offsetdivleftkorr;
   }
   $(this.optionen.id).css("left", nLeft + "px");
   $(this.optionen.id).css("top", $(window).scrollTop() + "px");
  },

  anzeigenRandUnten: function()
  {
   $(this.optionen.id).stop(true, true).animate({ "height": "show" }, { "duration": 400, "queue": false });
   this.oScrollTimer = null;
   this.optionen.visible = true;
  },

  anzeigen: function(fnEndeAnzeigen)
  {
   if(!this.optionen.visible)
   {
    $(this.optionen.id).show();
    this.optionen.visible = true;
   }
   this.fnEndeAnzeigen = fnEndeAnzeigen == undefined ? null : fnEndeAnzeigen;
   this.bBleibtOffen = false;
   this.positionieren();
   this.bWirdAngezeigt = true;
   var self = this;
   $(this.optionen.id).stop(true, false).animate({ "height": this.optionen.hoehe + "px" }, { "duration": "slow", "complete": function()
   {
    self.oTimer = window.setTimeout("apx.topMoveDiv.ausblenden()", 2000);
   }
   });
   $(this.optionen.id + " > div").stop(true, true).animate({ "height": "show", "opacity": "show" }, { "duration": 1000, "queue": false });
  },

  ausblenden: function()
  {
   this.oTimer = null;
   if(this.bBleibtOffen)
    return;
   this.bWirdAngezeigt = false;
   $(this.optionen.id + " > div").stop(true, true).animate({ "height": "hide", "opacity": "hide" }, { "duration": 500, "queue": false });
   $(this.optionen.id).stop(true, true).animate({ "height": this.nStartHoehe + "px" }, { "duration": 800, "complete": this.fnEndeAnzeigen });
  }
 }
})(jQuery);

