var speed=2;
var menu_id_norm="hauptmenu_norm";
var menu_id_start="hauptmenu_start";
var menu_id_zoom="nav_zoom";
var actual_icon="actual_icon";
var actual_icon_link="actual_icon_link";
var actual_pos="actual_pos";

var claim_id="con_claim";
var con_outer_id="con_outer";
var container_id="con_container";
var content_id="con_content";
var up_id="con_scroll_up";
var down_id="con_scroll_down";

var start_x, start_y, ziel_x, ziel_y, counter, opacit_timeout;
var opacit_off=100;
var float_step=5;
screen_saver_time = 20;

function movedown(){
  var crossobj=document.getElementById? document.getElementById(content_id) : document.all[content_id];
  var containerobj=document.getElementById? document.getElementById(container_id) : document.all[container_id];
  var contentheight=crossobj.offsetHeight;
  var containerheight=containerobj.offsetHeight;
  var topper=crossobj.style.top? crossobj.style.top : 0+"px";
  if (window.moveupvar) clearTimeout(moveupvar);
  if (parseInt(topper)>=(contentheight*(-1)+containerheight)) crossobj.style.top=parseInt(topper)-speed+"px";
  movedownvar=setTimeout("movedown()",20);
  var upobj=document.getElementById? document.getElementById(up_id) : document.all[up_id];
  upobj.style.visibility="visible";
}

function moveup(){
  var crossobj=document.getElementById? document.getElementById(content_id) : document.all[content_id];
  var topper=crossobj.style.top? crossobj.style.top : 0+"px";
  if (window.movedownvar) clearTimeout(movedownvar);
  if (parseInt(topper)<=0) crossobj.style.top=parseInt(topper)+speed+"px";
  moveupvar=setTimeout("moveup()",20);
}
function stopscroll(){
  if (window.moveupvar) clearTimeout(moveupvar);
  if (window.movedownvar) clearTimeout(movedownvar);
}
function movetop(){
  var crossobj=document.getElementById? document.getElementById(content_id) : document.all[content_id];
  var upobj=document.getElementById? document.getElementById(up_id) : document.all[up_id];
  stopscroll();
  crossobj.style.top=0+"px";
  upobj.style.visibility="hidden";
}
function floater_opacit(opacit_on){
  var content_outer_obj=document.getElementById? document.getElementById(con_outer_id) : document.all[con_outer_id];
  var crossobj=document.getElementById? document.getElementById(content_id) : document.all[content_id];
  var containerobj=document.getElementById? document.getElementById(container_id) : document.all[container_id];
  var downobj=document.getElementById? document.getElementById(down_id) : document.all[down_id];
  var contentheight=crossobj.offsetHeight;
  var containerheight=containerobj.offsetHeight;
  if (contentheight > containerheight){
    downobj.style.visibility="visible";
  }
  if(opacit_on<=100){
    containerobj.style.filter="alpha(opacity="+opacit_on+")";
    containerobj.style.MozOpacity=opacit_on/100;
    containerobj.style.visibility = "visible";
    content_outer_obj.style.filter="alpha(opacity="+opacit_on+")";
    content_outer_obj.style.MozOpacity=opacit_on/100;
    content_outer_obj.style.visibility = "visible";
    opacit_on+=5;
    opacit_timeout=setTimeout("floater_opacit("+opacit_on+")", 50);
  }
}

function floater_start(startY, zielY, fader_on, new_url){
  floatelement=document.getElementById? document.getElementById(menu_id_start):document.all[menu_id_start];
  claimelement=document.getElementById? document.getElementById(claim_id):document.all[claim_id];
  startX = window && window.innerWidth? window.innerWidth:document.body.offsetWidth? document.body.offsetWidth:600;
  startXscroll = 0;

  if (window && window.innerHeight){
    // Mozilla-Scrollbalken abziehen
    startXscroll = document.getElementsByTagName("body")[0].offsetHeight > window.innerHeight? 8:0;
  }
  startX = (startX-floatelement.offsetWidth)/2 - startXscroll;
  floatelement.style.left=startX+"px";
  floatelement.style.top=startY+"px";
  if (fader_on){
    var opacit_on=100/zielY*startY;
    floatelement.style.filter="alpha(opacity="+opacit_on+")";
    floatelement.style.MozOpacity=opacit_on/100;
    floatelement.style.visibility = "visible";
    startY+=float_step;
  }
  else {
    var opacit_on=100-(100/startY*zielY);
    startY-=float_step;
  }
  claimelement.style.filter="alpha(opacity="+opacit_on+")";
  claimelement.style.MozOpacity=opacit_on/100;
  claimelement.style.visibility = "visible";

  if ((startY<=zielY && fader_on) || (startY>=zielY && !fader_on)){
    floater_start_var=setTimeout("floater_start("+startY+", "+zielY+", "+fader_on+","+new_url+")", 20);
  }
  else if (new_url){
    page_reload(new_url);
  }
}

function floater_ende(new_url){
  floater_start(180, 30, false, new_url);
}
function getAbsoluteX (elm) {
  var x = 0;
  if (elm && typeof elm.offsetParent != "undefined") {
    while (elm && typeof elm.offsetLeft == "number") {
      x += elm.offsetLeft;
      elm = elm.offsetParent;
    }
  }
  return x;
}

function getAbsoluteY(elm) {
  var y = 0;
  if (elm && typeof elm.offsetParent != "undefined") {
    while (elm && typeof elm.offsetTop == "number") {
      y += elm.offsetTop;
      elm = elm.offsetParent;
    }
  }
  return y;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(function() {
  var check_menu_id_start=document.getElementById? document.getElementById(menu_id_start) : document.all[menu_id_start];
  var id_actual_icon=document.getElementById? document.getElementById(actual_icon) : document.all[actual_icon];
  var id_actual_pos=document.getElementById? document.getElementById(actual_pos) : document.all[actual_pos];
  document.zanmantou1 = new Zanmantou("zanmantou");
  if (check_menu_id_start){
    floater_start(10, 180, true);
  }
  if (id_actual_pos && id_actual_icon){
    id_actual_icon.style.left=getAbsoluteX(id_actual_pos)+'px';
    id_actual_icon.style.top=getAbsoluteY(id_actual_pos)+'px';
    box_float_initial();
  }
});

function box_float(start_x, start_y, ziel_x, ziel_y, actual_move_count, actual_move_direct, actual_move_initial, new_url){
  var id_actual_icon=document.getElementById? document.getElementById(actual_icon) : document.all[actual_icon];
  if (actual_move_direct==1){
    if (actual_move_initial==true){
      if (actual_move_count==actual_move_x.length){
        return floater_opacit(0);
      }
      else{
        start_x = getAbsoluteX(id_actual_icon);
        start_y = getAbsoluteY(id_actual_icon);
      }
      if (actual_move_x[actual_move_count]!=0){
        var buffer = window && window.innerWidth? window.innerWidth:document.body.offsetWidth? document.body.offsetWidth:600;
        buffer = (buffer-1023) / 2;
        ziel_x = actual_move_x[actual_move_count]+buffer;
      }
      else {
        ziel_x = start_x;
      }
      if (actual_move_y[actual_move_count]!=0) {
        ziel_y = actual_move_y[actual_move_count];
      }
      else {
        ziel_y = start_y;
      }
    }
    if (start_x < ziel_x) {
      start_x+=float_step;
    }
    if (start_y < ziel_y) {
      start_y+=float_step;
    }
  }
  if (actual_move_direct==2){
    if (actual_move_initial==true){
      if (actual_move_count==actual_move_x.length){
        if (new_url) {
          page_reload(new_url);
        }
      }
      else{
        start_x = getAbsoluteX(id_actual_icon);
        start_y = getAbsoluteY(id_actual_icon);
      }
      if (actual_move_x[actual_move_count]!=0) {
        ziel_x = actual_move_x[actual_move_count];
      }
      else {
        ziel_x = start_x;
      }
      if (actual_move_y[actual_move_count]!=0) {
        ziel_y = actual_move_y[actual_move_count];
      }
      else{
        ziel_y = start_y;
      }
    }
    if (start_x > ziel_x) {
      start_x-=float_step;
    }
    if (start_y > ziel_y) {
      start_y-=float_step;
    }
  }
  id_actual_icon.style.left=start_x+'px';
  id_actual_icon.style.top=start_y+'px';
  id_actual_icon.style.visibility = "visible";
  if (((start_x<ziel_x || start_y<ziel_y) && actual_move_direct==1) || ((start_x>ziel_x || start_y>ziel_y) && actual_move_direct==2)){
    actual_move_initial=false;
  }
  else{
    actual_move_initial=true;
    actual_move_count++;
  }
  box_float_var=setTimeout("box_float("+start_x+", "+start_y+", "+ziel_x+", "+ziel_y+", "+actual_move_count+", "+actual_move_direct+", "+actual_move_initial+", "+new_url+")", 20);
}

function box_float_back(new_url){
  if (window.box_float_var) clearTimeout(box_float_var);

  var actual_icon_link_obj=document.getElementById? document.getElementById(actual_icon_link) : document.all[actual_icon_link];
  var content_outer_obj=document.getElementById? document.getElementById(con_outer_id) : document.all[con_outer_id];
  var containerobj=document.getElementById? document.getElementById(container_id) : document.all[container_id];
  var downobj=document.getElementById? document.getElementById(down_id) : document.all[down_id];
  var upobj=document.getElementById? document.getElementById(up_id) : document.all[up_id];
  actual_icon_link_obj.onclick= function() {box_float_initial(); return true;};
  if (downobj.style.visibility=="visible") opacit_off=100;
  downobj.style.visibility="hidden";
  upobj.style.visibility="hidden";
  if(opacit_off>=0){
    content_outer_obj.style.filter="alpha(opacity="+opacit_off+")";
    content_outer_obj.style.MozOpacity=opacit_off/100;
    containerobj.style.filter="alpha(opacity="+opacit_off+")";
    containerobj.style.MozOpacity=opacit_off/100;
    opacit_off-=5;
    opacit_timeout=setTimeout("box_float_back("+new_url+")", 50);
  }
  else {
    var id_actual_pos=document.getElementById? document.getElementById(actual_pos) : document.all[actual_pos];
    content_outer_obj.style.visibility="hidden";
    containerobj.style.visibility="hidden";
    opacit_off=100;
    if (!new_url){
      timeout = setInterval("screen_saver(100)", screen_saver_time * 1000);
      document.onmousemove = function(){
        screen_saver_stop();
      }
      document.onkeydown = function(){
        screen_saver_stop();
      }
    }
    actual_move_x = new Array(getAbsoluteX(id_actual_pos),0);
    actual_move_y = new Array(0,getAbsoluteY(id_actual_pos));
    box_float(start_x, start_y, ziel_x, ziel_y, 0 , 2, true, new_url);
  }
}

function page_reload(new_url){
  location.replace("http://www.mypressagent.de/index.php?page_id="+new_url);
}
function box_float_initial(){
  if (window.box_float_var) clearTimeout(box_float_var);
  opacit_off=-5;
  if (window.opacit_timeout) clearTimeout(opacit_timeout);
  actual_move_x = new Array(0, 815);
  actual_move_y = new Array(200, 0);
  var actual_icon_link_obj=document.getElementById? document.getElementById(actual_icon_link) : document.all[actual_icon_link];
  actual_icon_link_obj.onclick= function() {box_float_back(); return true;};
  box_float(start_x, start_y, ziel_x, ziel_y, 0 , 1, true);
}
function DisplayElement (displayid, displayvalue){
  elementid=document.getElementById? document.getElementById(displayid):document.all[displayid];
  elementid.style.display = displayvalue;
}
function new_on (){
  DisplayElement ('down_gfx_box', 'none');
  DisplayElement ('down_ref_box', 'none');
  DisplayElement ('down_new_box', 'block');
  DisplayElement ('down_fly_box', 'none');
  movetop();
}
function ref_on (){
  DisplayElement ('down_gfx_box', 'none');
  DisplayElement ('down_ref_box', 'block');
  DisplayElement ('down_new_box', 'none');
  DisplayElement ('down_fly_box', 'none');
  movetop();
}
function gfx_on (){
  DisplayElement ('down_ref_box', 'none');
  DisplayElement ('down_new_box', 'none');
  DisplayElement ('down_gfx_box', 'block');
  DisplayElement ('down_fly_box', 'none');
  movetop();
}
function fly_on (){
  DisplayElement ('down_gfx_box', 'none');
  DisplayElement ('down_ref_box', 'none');
  DisplayElement ('down_new_box', 'none');
  DisplayElement ('down_fly_box', 'block');
  movetop();
}
function screen_saver_stop(){
  clearTimeout(timeout);
  timeout = setInterval("screen_saver(100)", screen_saver_time * 1000);
}
function screen_saver(opac){
  var content_outer_obj=document.getElementById? document.getElementById(con_outer_id) : document.all[con_outer_id];
  var containerobj=document.getElementById? document.getElementById(container_id) : document.all[container_id];
  var id_actual_icon=document.getElementById? document.getElementById(actual_icon) : document.all[actual_icon];
  var id_menu_norm=document.getElementById? document.getElementById(menu_id_norm) : document.all[menu_id_norm];
  var upobj=document.getElementById? document.getElementById(up_id) : document.all[up_id];
  var downobj=document.getElementById? document.getElementById(down_id) : document.all[down_id];
  upobj.style.visibility="hidden";
  downobj.style.visibility="hidden";
  if(opac>=0){
    content_outer_obj.style.filter="alpha(opacity="+opac+")";
    content_outer_obj.style.MozOpacity=opac/100;
    containerobj.style.filter="alpha(opacity="+opac+")";
    containerobj.style.MozOpacity=opac/100;
    id_actual_icon.style.filter="alpha(opacity="+opac+")";
    id_actual_icon.style.MozOpacity=opac/100;
    id_menu_norm.style.filter="alpha(opacity="+opac+")";
    id_menu_norm.style.MozOpacity=opac/100;
    opac-=5;
    opac_timeout=setTimeout("screen_saver("+opac+")", 50);
  }
  else{
    location.replace("http://www.mypressagent.de/");
  }
}

/**************************************************************************************************
* Zamantou JavascriptMicroAPI 1.2
* Releases <http://zanmantou.voodoon.com>
* Copyright 2007 by Andi Dittrich <andi.dittrich@voodoon.com>
* Terms of Use avaible under : "http://zanmantou.voodoon.com"
* ALL RIGHTS RESERVED

* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**************************************************************************************************/

/* Universal Callback */
function ZanmantouCallback(id, args){
  for (var i = 0;i<ZanmantouInstance.length;i++){
    if (ZanmantouInstance[i][0] == id){
      ZanmantouInstance[i][1].callback(args);
    }
  }
}
/* Event Callback */
function ZanmantouEventCallback(id, args){
  for (var i = 0;i<ZanmantouInstance.length;i++){
    if (ZanmantouInstance[i][0] == id){
      ZanmantouInstance[i][1].eventCallback(args);
    }
  }
}

/* Alle erzeugten Zanamntou Instanzen */
var ZanmantouInstance = new Array();

/* konstruktor */
function Zanmantou(id){
  this.zanmantou = document.getElementById(id);
  this.id = id;
  this.isRegistered = false;
  this.callbackArgs = "";
  this.onChangeEvent = null;
  ZanmantouInstance.push(new Array(id, this));
}

/* callback */
Zanmantou.prototype.callback = function(args){
  this.callbackArgs = args + "";
}

/* event callback */
Zanmantou.prototype.eventCallback = function(args){
  // event verarbeiten
  // wenn es einen trackchange gibt
  if (args == 'change'){
    if (this.onChangeEvent != null){
      this.onChangeEvent.actionPerformed();
    }
  }
}

/* event registrieren */
Zanmantou.prototype.registerEvent = function(type, obj){
  if (type == 'onChange'){
    this.onChangeEvent = obj;
  }
}

Zanmantou.prototype.register = function(){
  if (!this.isRegistered){
    this.isRegistered = true;
    this.zanmantou.JMAPI_init(this.id);
  }
}
/* jumpAndPlay */
Zanmantou.prototype.jumpAndPlay = function(index){
  this.zanmantou.JMAPI_jump(index);
}
