// DHTML Basisfunktionen
// (c) 2007 schukai GmbH
// www.alvine.de

// Funktions- und Environmet-Variablen
var _ALVINE_DHTML = false;
var _ALVINE_DOM = false;
var _ALVINE_IE = false;
var _ALVINE_IE6 = false;
var _ALVINE_IE7 = false;
var _ALVINE_NS = false;
var _ALVINE_OP = false;
var _ALVINE_MAC = false;
var _ALVINE_NETSCAPE = false;

// Initialisieren der Environmet-Variablen
function initLib() {

  // Testen ob Javascript eingebunden
  setCookie("AlvineJavascript", true, 0, '/');

  if(navigator.appName=="Netscape") {
    _ALVINE_NETSCAPE = true;
  }

  if(document.getElementById) {
    _ALVINE_DHTML = true;
    _ALVINE_DOM = true;
  }
  
  if(window.opera) {
    _ALVINE_OP = true;
  }

  if(document.all && !_ALVINE_OP) {
     
     var $versionpattern = /MSIE\s(.*?)\;/i;
     var version = navigator.appVersion.match($versionpattern);
     version = version[1];
          
     if(version.substring(0, 1)=='6') _ALVINE_IE6 = true;
     if(version.substring(0, 1)=='7') _ALVINE_IE7 = true;
     
    _ALVINE_DHTML = true;
    _ALVINE_IE = true;
    
  };
 
  if(document.layers && !_ALVINE_OP) {
    _ALVINE_DHTML = true;
    _ALVINE_NS = true; 
  };
  
  if(navigator.userAgent.indexOf("Mac") != -1) {
    _ALVINE_MAC = true;
  };

};

function getElementID(id) {
  return getElement('id', id);
};

// System- und browserunabhägige Funktion um ein
// Element (Objekt) zu holen
// @param type Auswahl aus: id, name, tagname
// @param ptr ID oder Name des Elements
// @param index Nur bei Verwendung des Typ tagname
function getElement(type, ptr, index) {

  if(_ALVINE_DOM) { 
    if(type.toLowerCase()=="id") { 
      if(typeof document.getElementById(ptr) == "object") {
        return document.getElementById(ptr);
      };
      return void(0);

    } else if(type.toLowerCase()=="name") {
      if(typeof document.getElementsByName(ptr) == "object") {
        return document.getElementsByName(ptr)[index];
      };
      return void(0);

    } else if(type.toLowerCase()=="tagname") {
      if(typeof document.getElementsByTagName(ptr) == "object" || (_ALVINE_OP && typeof document.getElementsByTagName(ptr) == "function")) {
        return document.getElementsByTagName(ptr)[index];
      };
      return void(0);
    } else {
      return void(0);
    };

  } else if(_ALVINE_IE) {

    if(type.toLowerCase()=="id") {
      if (typeof document.all[ptr] == "object") {
        return document.all[ptr];
      };
      return void(0);

    } else if(type.toLowerCase()=="tagname") {
      if(typeof document.all.tags(ptr) == "object") {
        return document.all.tags(ptr)[index];
      };
      return void(0);

    } else if(type.toLowerCase()=="name") {
      if(typeof document[ptr] == "object") {
        return document[ptr];
      };
      return void(0);
    } else {
      return void(0);
    };

  } else if(_ALVINE_NS) {   

    if(type.toLowerCase()=="id" || type.toLowerCase()=="name") {
      if (typeof document[ptr] == "object") {
        return document[ptr];
      };
      return void(0);

    } else if(type.toLowerCase()=="index") {
      if (typeof document.layers[ptr] == "object") {
        return document.layers[ptr];
      };
      return void(0);
    } else {
      return void(0);
    };
  };
  return void(0);
}

// Browserunabhängig Inhalte in die Seite einfügen
// @param obj Zeiger auf Objekt
// @param content Zu schreibender inhalt 
function writeHTML(obj, content) {

   if(!obj) return void(0);  
   if(_ALVINE_OP) {
     // nicht implementiert
   } else if(_ALVINE_DOM) {   // IE7
     if(typeof(obj.innerHTML)!="undefined") { 
       obj.innerHTML = content;
     } else {
     // nicht implementiert
     };
   } else if(_ALVINE_IE) {
     //obj.innerHTML = content;
   } else if(_ALVINE_NS) { 
     obj.document.open();
     obj.document.write(content);
     obj.document.close();
   };
   
   return void(0);
};

// Browserunabhängig Inhalte in die Seite einfügen
// @param obj Zeiger auf Objekt
// @param content Zu schreibender inhalt (nur Text)
function writeContent(obj, content) {

   if(!obj) return void(0);  
   if(_ALVINE_OP) {

     // nicht implementiert
   
   } else if(_ALVINE_DOM) {  
     if(obj.firstChild) { 
       obj.firstChild.nodeValue = content;
     };

   } else if(_ALVINE_IE) {
     obj.innerText = content;

   } else if(_ALVINE_NS) { 
     obj.document.open();
     obj.document.write(content);
     obj.document.close();
   };
   return void(0);
};

// Diese Funktion verschiebt ein Objekt 
// an die angegebenen koordinaten
function moveElementTo(obj, x, y) {

  if(_ALVINE_DOM || _ALVINE_OP) { 
    obj.style.left = x+'px';
    obj.style.top = y+'px'; 
  } else if(_ALVINE_NS) { 
    obj.moveTo(x, y);
  };

 };
 
function setVisibilityMode(obj, flag) {

   if(!obj) return void(0);

   if(_ALVINE_DOM || _ALVINE_OP) { 
     if(flag) { 
       obj.style.visibility = "visible";
       obj.style.display = "block";
     } else {
       obj.style.visibility = "hidden";
       obj.style.display = "none";
     };

   } else if(_ALVINE_IE) {
     if(flag) { 
       obj.style.visibility = "visible";
       obj.style.display = "block";
     } else {
       obj.style.visibility = "hidden";
       obj.style.display = "none";
     };
   
   } else if(_ALVINE_NS) { 
     if(flag) { 
       obj.visibility="show";
       obj.display="block";
     } else {
       obj.visibility="hide";
       obj.display="none";
     };
   };
   return void(0);
};

// Sichtbarkeit von Elementen ändern.
// @param obj Zeiger auf Element
// @param flag true: sichtbar, false: unsichtbar
function setVisibility(obj, flag) {

   if(!obj) return void(0);

   if(_ALVINE_DOM || _ALVINE_OP) { 
     if(flag) { 
       obj.style.visibility = "visible";
       obj.style.display = "block";
     } else {
       obj.style.visibility = "hidden";
       obj.style.display = "none";
     };

   } else if(_ALVINE_IE) {
     if(flag) { 
       obj.style.visibility = "visible";
       obj.style.display = "block";
     } else {
       obj.style.visibility = "hidden";
       obj.style.display = "none";
     };
   
   } else if(_ALVINE_NS) { 
     if(flag) { 
       obj.visibility="show";
       obj.style.display = "block";
     } else {
       obj.visibility="hide";
       obj.style.display = "none";
     };
   };
   return void(0);
};

// Position eines Elements ermitteln
// Diese Funktion arbeitet mit dem Offset eines Elements
// und arbeitet sich rekursiv durch das DOM
// Ist eine AbbruchsID angegeben und trift
// die Funktion auf dieses Element so wird der
// Wert zurückgegeben
// @param obj Zeiger auf Element
// @param id AbbruchsID
function getLeftOfElement(obj, id) {

  if(_ALVINE_NS) return obj.pageX;

  if(!id) id = "noid"; 
  var left = obj.offsetLeft;
  if(obj.id==id) return left;

  if(obj.offsetParent!=null && obj.offsetParent.tagName!="HTML") {
    left += getLeftOfElement(obj.offsetParent);
  };
  return left;
}

// Identische Funktion für die Y-Koordinate
// @param obj Zeiger auf Element
// @param id AbbruchsID
function getTopOfElement(obj, id) {

  if(_ALVINE_NS) return obj.pageY;
  if(!id) id = "noid"; // dummywert!
  var top = obj.offsetTop; 

  if(obj.id==id) return top;
  if(obj.offsetParent!=null && obj.offsetParent.tagName!="HTML") {
    top += getTopOfElement(obj.offsetParent);
  };
  
  // to: add padding
  
  return top;
}

// Höhe eines Objektes zurückgeben
function getHeightOfElement(obj) {
  if(_ALVINE_NS) return obj.height;
  return obj.offsetHeight;
};

// Breite eines Objektes zurückgeben
function getWidthOfElement(obj) {
  if(_ALVINE_NS) return obj.width;
  return obj.offsetWidth;
};

// Cookie aufbauen
function setCookie(name, value, expires, path, domain, secure) {
  var today = new Date();
  today.setTime(today.getTime());
  if(expires) {
    expires = expires*86400000;
  };
  var expireDate = new Date(today.getTime()+(expires));
  document.cookie = name+"="+escape(value)+
  ((expires)?";expires="+expireDate.toGMTString():"")+ 
  ((path)?";path="+path:"")+ 
  ((domain)?";domain="+domain:"")+
  ((secure)?";secure":"");
} 

// Größen

function alvine_getClientWidth() {
  return alvine_getRectStruct (window.innerWidth ? window.innerWidth : 0,
    document.documentElement ? document.documentElement.clientWidth : 0,
    document.body ? document.body.clientWidth : 0
  );
}

function alvine_getClientHeight() {
  return alvine_getRectStruct (window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
  );
}

function alvine_getScrollLeft() {
  return alvine_getRectStruct (window.pageXOffset ? window.pageXOffset : 0,
    document.documentElement ? document.documentElement.scrollLeft : 0,
    document.body ? document.body.scrollLeft : 0
  );
}

function alvine_getScrollTop() {
  return alvine_getRectStruct (window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
  );
}

function alvine_getRectStruct(n_win, n_docel, n_body) {
  var n_result = 0;
  if(n_win) n_result = n_win;
  if(n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel;
  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
};


// Simple AJAX - Object 

function alvineSimpleAjaxRequest(url, id, errorID) {
  var url = url;
  var containerID = id;
  var errorContainerID = errorID;
  var requestObj = false;
  
  var urlData = new Array();
  var callBacks = new Array();

  var urlControlData = new Array();
  var urlControlID = new Array();
  
  
  function checkState() {
    // 0 (nicht initialisiert)
    // 1 (lade)
    // 2 (geladen)
    // 3 (interaktiv)
    // 4 (vollständig) 
    if(requestObj.readyState!=4) return false; 

    if(requestObj.status==200) {
      return requestObj.responseText;
    } else {
    
      errorMsg = 'Error: '+requestObj.status; // @TODO: sprachversionen

      if(errorContainerID!=null) {
        obj = getElement('id', errorContainerID);
        writeHTML(obj,errorMsg);
        return false;
      };

      return errorMsg;
    }
  }  
  
  this.sendRequest = function() {
    requestObj = null;
    if(window.XMLHttpRequest) { // Mozilla, Firefox, Safari, ...
      requestObj = new XMLHttpRequest();
      if (requestObj.overrideMimeType) {
        requestObj.overrideMimeType('text/html'); // BugFix für fehlerhaften Response
      };
    } else if(window.ActiveXObject) { // IE
      try {
        requestObj = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          requestObj = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
        };
      }
    };

    if(!requestObj) {
    
      errorMsg = 'no ajax'; // @TODO: sprachversionen

      if(errorContainerID!=null) {
        obj = getElement('id', errorContainerID);
        writeHTML(obj,errorMsg);
        return false;
      };

      return false;
    }
    
    var parameters = "";
    for(i=0; i<urlData.length;i++) {
      if(parameters.length>0) parameters += '&';
      value = eval(urlData[i]);
      parameters += 'sxx_ajax['+urlData[i]+']='+value;
    };

    for(i=0; i<urlControlID.length;i++) {
      if(parameters.length>0) parameters += '&';
      value = eval(urlControlData[i]);
      parameters += 'sxx_ajax['+urlControlID[i]+']='+value;
    };

    if(parameters.length>0) parameters += '&';
    parameters += 'r='+(1 + 10000*(Math.random()));;
    
    try {
      requestObj.onreadystatechange = eventHandler; 
      requestObj.open('POST', url, true);
      requestObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');   // wenn data
      requestObj.send(parameters); // WENN DATA hier übergeben  
    } catch (e) {
      alert(e);
    };
  }

  this.bindControl = function(key, id) {
    handler = 'getElementID(\''+id+'\').value;';
    urlControlData[urlControlData.length] = handler;   
    urlControlID[urlControlID.length] = key;
  }
  
  this.bindVariable = function(key) {
    urlData[urlData.length] = key;
  }
  
  function eventHandler() {
    var result = checkState();
    if(result==false) return;
    obj = getElement('id', containerID);
    resultContent = result;
    
    outScript = "";
    
    scriptStartIndex = resultContent.indexOf('<script'+'>');
    if(scriptStartIndex>=0) {
      scriptEndIndex = resultContent.indexOf('</script'+'>');
      outScript += resultContent.substr(scriptStartIndex+8, scriptEndIndex-scriptStartIndex-8);
      resultContent = resultContent.substr(0,scriptStartIndex)+resultContent.substr(scriptEndIndex+8+1,resultContent.length);
    };

    scriptStartIndex = resultContent.indexOf('<array>');
    if(scriptStartIndex>=0) {
      scriptEndIndex = resultContent.indexOf('</array>');
      skript = resultContent.substr(scriptStartIndex+7, scriptEndIndex-scriptStartIndex-7);
      data=eval(skript);
      for(j=0;j<callBacks.length;j++) {
        callBacks[j]('array',data);
      };
      resultContent = resultContent.substr(0,scriptStartIndex)+resultContent.substr(scriptEndIndex+7+1,resultContent.length);
    };    

    scriptStartIndex = resultContent.indexOf('<object>');
    if(scriptStartIndex>=0) {
      scriptEndIndex = resultContent.indexOf('</object>');
      skript = resultContent.substr(scriptStartIndex+8, scriptEndIndex-scriptStartIndex-8);
      data=eval(skript);
      for(j=0;j<callBacks.length;j++) {
        callBacks[j]('object',data);
      };
      resultContent = resultContent.substr(0,scriptStartIndex)+resultContent.substr(scriptEndIndex+8+1,resultContent.length);
    }; 

    writeHTML(obj,resultContent);
    if(outScript) eval(outScript);
  };
  
  this.bindCallback = function(callBack) {
    callBacks[callBacks.length] = callBack
  };
};

function getViewportHeight() {

  vpHeight = null;
  if(document.documentElement.clientHeight) {  // FIREFOX
    vpHeight = document.documentElement.clientHeight
  } else if(window.innerHeight) { // Netscape & Co
    vpHeight = window.innerHeight;
  } else if(document.clientHeight) {
    vpHeight = document.clientHeight;
  } else if(document.body && document.body.clientHeight) { // IE
    vpHeight = document.body.clientHeight;
  } else if(document.documentElement.clientHeight) {  // IE6 im standardMode
    vpHeight = document.documentElement.clientHeigt; 
  } else { // Unbekannt
  }  
  return vpHeight;
}

function getViewportWidth() {

  vpWidth = null;
  if(document.documentElement.clientWidth) {  // FIREFOX
    vpWidth = document.documentElement.clientWidth
  } else if(window.innerWidth) { // Netscape & Co
    vpWidth = window.innerWidth;
  } else if(document.clientWidth) {
    vpWidth = document.clientWidth;
  } else if(document.body && document.body.clientWidth) { // IE
    vpWidth = document.body.clientWidth;
  } else if(document.documentElement.clientWidth) {  // IE6 im standardMode
    vpWidth = document.documentElement.clientWidth; 
  } else { // Unbekannt
  }  
  
  return vpWidth;
}



// Umgebungsvariablen initialisieren
initLib();

// Testwerte
//alert('FLAGS \nIE ' + _ALVINE_IE + " \nDOM " + _ALVINE_DOM + " \nNS "+ _ALVINE_NS + " \nOP " +_ALVINE_OP + " \nMAC " + _ALVINE_MAC);



// Menu-Events registrieren
if(document.layers) {
  window.captureEvents(Event.MOUSEUP);
  window.onmouseup=hidePulldownMenu;
} else {
  document.onmouseup=hidePulldownMenu;
}

var openObj = new Array(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
var lastLevel = null;

function hidePulldownMenu() {

  for(i=0;i<openObj.length;i++) {
    if(openObj[i]==null) continue;
    openObj[i].style.left="-9999px";
    openObj[i].style.position="absolute";
    openObj[i].style.visibility="hidden";
    openObj[i] = null;
  };
  

};


function showPulldownMenu(id, level) {

  dbg = getElementID('debug');

  info = "";
  for(i=0;i<openObj.length;i++) {
    if(openObj[i]==null) continue;
    info+= ' :: ' + openObj[i].id;
  };
  
  var abc = 4;

  if(id==null) {
    for(i=level;i<openObj.length;i++) {
      if(openObj[i]==null) continue;
      openObj[i].style.left="-9999px";
      openObj[i].style.position="absolute";
      openObj[i].style.visibility="hidden";
      openObj[i] = null;
    };
    return;
  };


  obj = getElementID(id);
  if(!obj) return;
  
  if(openObj[level]==obj) return;

  for(i=level;i<openObj.length;i++) {
    if(openObj[i]==null) continue;
    openObj[i].style.left="-9999px";
    openObj[i].style.position="absolute";
    openObj[i].style.visibility="hidden";
    openObj[i] = null;
  };

  openObj[level] = obj;

  if(level==0) {
    obj.style.left = 'auto';
    obj.style.visibility="visible";
  } else {
    var width = getWidthOfElement(obj.parentNode.parentNode);
    var top = 0;

    if(typeof obj.parentNode.offsetTop=='number') {
      top = obj.parentNode.offsetTop;
    };

    obj.style.left = (width)+'px';
    if(top>0) {
      obj.style.top = (top)+'px';
    } else {
      obj.style.top = '0px';
    };
    obj.style.visibility="visible";
  };
  
};

function str_replace(Search, Replace, Subject){

 if ((Subject == null) || (Search == null)) return null;
 if ((Subject.length == 0) || (Search.length == 0)) return Subject;
 if ((Replace == null) || (Replace.length == 0)) Replace = "";

 var LengthSearch = Search.length;
 var LengthReplace = Replace.length;
 var Pos = Subject.indexOf(Search, 0);

 while (Pos >= 0){
   Subject = Subject.substring(0, Pos) + Replace + Subject.substring(Pos + LengthSearch);
   Pos = Subject.indexOf(Search, Pos + LengthReplace);
 }
 
 return Subject;
}

function strstr(Haystack, Needle){

 if ((Haystack == null) || (Needle == null)) return null;
 if ((Haystack.length == 0) || (Needle.length == 0)) return null;

 var result = Haystack.indexOf(Needle);
 
 if(result<0) return false;

 return true;
}

/*
init-Params-Example

var timeParams = new Object();
timeParams['year'] = 2010;
timeParams['month'] = 10;
timeParams['day'] = 12;
timeParams['hours'] = 2;
timeParams['minutes'] = 15;
timeParams['seconds'] = 48;


*/

function time_initDateTime(time){

  var paramKeys = new Object();
  paramKeys['year'] = 1970;
  paramKeys['month'] = 0;
  paramKeys['day'] = 1;
  paramKeys['hours'] = 0;
  paramKeys['minutes'] = 0;
  paramKeys['seconds'] = 0;
  
  
  //Objektname = new Date(Jahr, Monat, Tag, Stunden, Minuten, Sekunden);
  if(typeof time == 'object'){
    var initTime = new Object();
    
    for(var i in paramKeys){
      if(typeof time[i] == 'undefined') {
        initTime[i] = paramKeys[i];
        continue;
      }
      
      var value = time[i];
      switch(i){
        default:          
          break
        case 'month':   //Month base is '0'
          value = parseInt(time[i])-1;
          break;
      
      }
      initTime[i] = parseInt(value);
      
    }

    var timeOject = new Date(initTime.year, initTime.month, initTime.day, initTime.hours, initTime.minutes, initTime.seconds);
  } else {
    var timeOject = new Date();
  }
  
  return timeOject;
}

function time_getTimestamp(time){
  
  var now = time_initDateTime(time);

  //now.getYear()  // year 2000 BUG!! Do not use this!!  
  var year    = now.getFullYear();  
  var month   = now.getMonth()+1;
  var day     = now.getDate();
  var minutes = now.getMinutes();
  var hours   = now.getHours();
  var seconds = now.getSeconds();
  //var milliseconds = now.getMilliseconds();
  
  
  var timestamp = new Array(); 
  timestamp.push(year); 
  timestamp.push(str_pad(month,2,'0','left')); 
  timestamp.push(str_pad(day,2,'0','left')); 
  timestamp.push(str_pad(hours,2,'0','left')); 
  timestamp.push(str_pad(minutes,2,'0','left')); 
  timestamp.push(str_pad(seconds,2,'0','left')); 
  //timestamp.push(milliseconds); 
  
  timestamp = timestamp.join('');
  
  return timestamp;
}

function time_getMilliTimestamp(time){
  
  var now = time_initDateTime(time);
  var milliTime = now.getTime();
  
  return milliTime;
}

function time_getUnixTimestamp(time){
  
  var now = time_getMilliTimestamp(time)/1000;
  now = parseInt(now);
  
  return now;
}







function element_addClassName(obj,className, offset){
  obj = element_isObject(obj);
  
  if(typeof offset == 'undefined') offset = '';
  obj.className+=offset+className;

  return true;
}

function element_removeClassName(obj,className,offset){
  obj = element_isObject(obj);

  if(typeof offset == 'undefined') offset = '';
    
  obj.className = str_replace(offset+className, '', obj.className);  
  
  return true;

}

function element_replaceClassName(obj,classNameSearch,classNameReplace){
  obj = element_isObject(obj);
  
  obj.className = str_replace(classNameSearch, classNameReplace, obj.className);
  
  
  return true;

}

function element_getZIndex(obj,value){
  obj = element_isObject(obj);
      
  if(obj.style.zIndex != null) {
    return obj.style.zIndex;
  }
  
  return true; 
}

function element_setZIndex(obj,value){
  obj = element_isObject(obj);
      
  if(obj.style.zIndex != null) {
    obj.style.zIndex  = value;
    return true;
  }
  
  return true; 
}

function element_get(type,res){
  var obj;
  
  if(document.getElementById) {
    
    if(type=='id') obj = document.getElementById(res);
    
  } else if(document.all) {

    if(type=='id') obj = document.all[res];
  }
  
  return obj;
}


function element_move(obj,vleft,vtop){
  obj = element_isObject(obj);
  
  var size = element_getSize(obj);

  vleft = element_recalcValue2px(vleft,size.width);
  vtop  = element_recalcValue2px(vtop,size.height);
  vleft = parseInt(vleft);
  vtop  = parseInt(vtop);
  
  obj.style.position = 'absolute';
  obj.style.left  = vleft.toString() + "px";
  obj.style.top = vtop.toString() + "px";

  return true;
}

function element_setVisibility(obj,status){
  obj = element_isObject(obj);

  obj.style.visibility = status;
  
  return true;
}

function element_setDisplay(obj,status){
  obj = element_isObject(obj);

  obj.style.display = status;
  
  return true;

}


function element_getAbsolutePositionX(obj, id){
  
  obj = element_isObject(obj);
  
  if(_ALVINE_NS) return obj.pageX;

  var left = parseInt(obj.offsetLeft);
  
  if(!id) id = "noid"; // dummywert!
  if(obj.id==id) return left;
  
  if(obj.offsetParent!=null && obj.offsetParent.tagName!="HTML") {
    left += element_getPositionX(obj.offsetParent);
  };
  return left;
  
}

function element_getAbsolutePositionY(obj, id){
  
  obj = element_isObject(obj);
  
  if(_ALVINE_NS) return obj.pageY;
   
  var top = parseInt(obj.offsetTop); 
  
  if(!id) id = "noid"; // dummywert!
  if(obj.id==id) return top;
  
  if(obj.offsetParent!=null && obj.offsetParent.tagName!="HTML") {
    top += element_getPositionY(obj.offsetParent);
  };
  
  // to: add padding
  
  return top;
  
}

function element_getPositionX(obj){  
  
  obj = element_isObject(obj);

  if(typeof obj.style.position != 'undefined'){
    if(obj.style.position == 'absolute' && typeof obj.style.left !='undefined'){
      return parseInt(obj.style.left);    
    }
  }
  
  if(typeof obj.offsetLeft =='number'){
    return parseInt(obj.offsetLeft);    
  }
  
  if(typeof obj.clientLeft =='number'){
    return parseInt(obj.clientLeft);
  }

  if(typeof obj.layerX =='number'){
    return parseInt(obj.layerX);
  }
  
  return false;
  
}

function element_getPositionY(obj){
  
  obj = element_isObject(obj);
  
  if(typeof obj.style.position != 'undefined'){
    if(obj.style.position == 'absolute' && typeof obj.style.top != 'undefined'){
      return parseInt(obj.style.top);
    }
  }
  
  if(typeof obj.offsetTop =='number'){
    return parseInt(obj.offsetTop);
  }
  
  if(typeof obj.clientTop =='number'){
    return parseInt(obj.clientTop);
  }

  if(typeof obj.layerY =='number'){
    return parseInt(obj.layerY);
  }
  
  return false;
  
}

function element_getPosition(obj, absolute, id){
  obj = element_isObject(obj); 
  
  if(!absolute){  
    var xpos = element_getPositionX(obj);
    var ypos = element_getPositionY(obj);
  } else {
    var xpos = element_getAbsolutePositionX(obj, id);
    var ypos = element_getAbsolutePositionY(obj, id);
  }
    
  return {x:xpos,y:ypos};
  
}


function element_getSize(obj){
  
  obj = element_isObject(obj);
  
  var ret = new Object();
  ret['width']  = element_getWidth(obj);    
  ret['height'] = element_getHeight(obj);

  return ret;
}



function element_getWidth(obj){  
  obj = element_isObject(obj);
  
  if(typeof obj.style.width != 'undefined' && obj.style.width != '' && obj.style.width!='auto') return parseInt(obj.style.width);  
  
  if(typeof obj.offsetWidth != 'undefined') return parseInt(obj.offsetWidth);
  
  if(typeof obj.clientWidth != 'undefined') return parseInt(obj.clientWidth);
  
  if(typeof obj.width != 'undefined') return parseInt(obj.width);
  
  if(typeof obj.naturalWidth != 'undefined') return parseInt(obj.naturalWidth);
  
  if(typeof document.all != 'undefined'){
    if(typeof document.all[obj.id].offsetWidth != 'undefined' && document.all[obj.id].offsetWidth != ''){
      return parseInt(document.all[obj.id].offsetWidth);
    }
  }
  
  return false;
}

function element_setWidth(obj,width){
  
  obj = element_isObject(obj);
  obj.style.overflow = 'hidden';
  obj.style.width = (width!='auto')?parseInt(width).toString()+'px':width;
  
  return true;
}


function element_getHeight(obj){
  obj = element_isObject(obj);

  if(typeof obj.style.height != 'undefined' && obj.style.height != '' && obj.style.height!='auto') return parseInt(obj.style.height);

  if(typeof obj.offsetHeight != 'undefined' && obj.offsetHeight != '') return parseInt(obj.offsetHeight);
  
  if(typeof obj.clientHeight != 'undefined' && obj.clientHeight != '') return parseInt(obj.clientHeight);
  
  if(typeof obj.height != 'undefined' && obj.height != '') return parseInt(obj.height);
 
  if(typeof obj.naturalHeight != 'undefined' && obj.naturalHeight != '') return parseInt(obj.naturalHeight);
  
  if(typeof document.all != 'undefined'){
    if(typeof document.all[obj.id].offsetHeight != 'undefined' && document.all[obj.id].offsetHeight != ''){
      return parseInt(document.all[obj.id].offsetHeight);
    }
  }
  
  return false;
}

function element_setHeight(obj,height){
 
  obj = element_isObject(obj);
  obj.style.overflow = 'hidden';
  obj.style.height = (height!='auto')?parseInt(height).toString()+'px':height;
  
  return true;
}
 
function element_setSize(obj,width,height){
  obj = element_isObject(obj);
  
  element_setWidth(obj, width);
  element_setHeight(obj, height);
  
  return true;
}

function element_setBackground(obj,background){

  obj = element_isObject(obj);

  obj.style.background = background;
  
  return true;
}


function element_setOpacity(obj,value){
  obj = element_isObject(obj);
  
  value = parseInt(value);
  value = value>100?100:parseInt(value);
  value = value<0?0:parseInt(value);

  if(typeof obj.style.opacity != 'undefined') {
    obj.style.opacity  = value/100;
    return true;
  }
    
  if(typeof obj.style.MozOpacity != 'undefined') {
    obj.style.MozOpacity = value/100;  
    return true;
  }

  if(typeof obj.filters != 'undefined') { 

    if(obj.style.filter == ''){     
      obj.style.filter = 'alpha(opacity='+value.toString()+')';
    }
    
    obj.filters['alpha']['opacity'] = parseInt(value);

    return true;
  }

  if(typeof obj.style.KhtmlOpacity != 'undefined') {
    obj.style.KhtmlOpacity  = value/100;
    return true;
  } 
  
  return true; 
}

function element_getOpacity(obj){
  obj = element_isObject(obj);

  if(obj.style.opacity != null) return parseInt(obj.style.opacity*100);
  
  if(obj.style.MozOpacity != null) return parseInt(obj.style.MozOpacity*100);  
  
  if(typeof obj.filters != 'undefined') {    
    if(obj.style.filter != ''){
      return parseInt(obj.filters['alpha']['opacity']);
    }
  }
    
  if(obj.style.KhtmlOpacity != 'undefined') return parseInt(obj.style.KhtmlOpacity*100);

  //wird nichts gefunden, wird angenommen, das Element sei komplett durchsichtig
  return 0;
}

var savedUniqueIDs = new Object();
function element_buildUniqueObjectID(object){
  var ret = 0;
  
  if(typeof object.sourceIndex != 'undefined') return object.sourceIndex;  

  //Fierfox doesn't know "sourceIndex"
  var id = null;
  if(typeof object.innerText != 'undefined') ret+= object.innerText;
  if(typeof object.outerText != 'undefined') ret+= object.outerText;
  if(typeof object.innerHTML != 'undefined') ret+= object.innerHTML;
  if(typeof object.childNodes != 'undefined') ret+= object.childNodes.length;
  if(typeof object.tagName != 'undefined') ret+= object.tagName;
  if(typeof object.id != 'undefined') id = object.id;
  var src = null;
  if(typeof object.src != 'undefined') {
    src = object.src;
    ret+= src;
    
    var parts = src.split('/');
    src = parts[parts.length-1];
    src = src.replace(/\./g, '');
  }
  
  ret = id + ret + src;

  var timestamp = time_getMilliTimestamp();
  
  var randomNr = Math.random();
  randomNr *= 1000;
  randomNr = Math.ceil(randomNr);
  
  var uid = 'a'+ret.toString() + randomNr.toString() + timestamp.toString();
  if(typeof savedUniqueIDs[uid] != 'undefined') uid = parseInt(uid)+1;
  
  savedUniqueIDs[uid] = uid.toString(); 
  return uid.toString();
}





function element_isObject(mixed){
  var ret = true;
  
  if (typeof(mixed)!="object"){
    mixed = element_get('id',mixed);
    if (typeof(mixed)=="object") return mixed;
    return false;
  } else {
    return mixed;  
  }
}

/*
 * recalculate px-values and percentage-values
 */
function element_recalcValue2px(value,val100percent){
  if(typeof value == 'undefined') return null;
  if(value == null) return null;

  if(value.toString().substring((value.toString().length-1))=='%'){  //Umrechnung bei %-Angabe
    return parseInt(((val100percent/100) * parseInt(value)));
  }
  
  if(value.toString().substring((value.toString().length-2),2)=='px'){  //Umwandlung bei px-Angabe
    return parseInt(value);
  }

  return parseInt(value);
}

function object_count(obj){
  
  if(typeof obj != 'object') return 0;
  
  var cnt = 0;
  for(var i in obj){
    cnt++;
  }
  
  return cnt;
}

var JAVASCRIPT_IMAGES_PRELOAD = new Object();

function image_preload_init(key){
  if(typeof JAVASCRIPT_IMAGES_PRELOAD[key] != 'undefined') return false;
  
  JAVASCRIPT_IMAGES_PRELOAD[key] = new Array();

}

function image_preload_add(key,image){
  var newIndex = JAVASCRIPT_IMAGES_PRELOAD[key].length;
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex] = new Object();
  
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex]['name'] = image['name'];
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex]['src'] = image['src'];
}

function image_preload_get(key,index){
  return JAVASCRIPT_IMAGES_PRELOAD[key][index];  
}

function image_shrinkToFit(obj, new_w, new_h){
  
  obj = element_isObject(obj);
  var old = element_getSize(obj);
  
  ret = new Object();
  
  var ratio  = (old.width / old.height);
  if (old.width > old.height) {    
    ret['width']  = new_w;
    ret['height'] = new_w * ratio;
  } else {    
    ret['width']   = new_h * ratio;
    ret['height']  = new_h;    
  }
  if (old.width == old.height) {
    ret['width']  = new_w;
    ret['height'] = new_h;
  }

  return ret;
}

//SFX
var sfxObjects = new Object();
function JAVASCRIPT_SFX(){

  this.oid                     = element_buildUniqueObjectID(this);
  this.objectPool              = new Object();
  this.objectName              = null;
  
  this.calc                    = new JAVASCRIPT_SFX_OBJECT_POSITION_CALC();

  //FollowUp
  this.followingObjects        = new Array(); 
  this.followOptions           = new Object();
    
  this.current_intervalID      = null;
  
  this.addObject               = JAVASCRIPT_SFX_addObject;
  this.registerFollowingObject = JAVASCRIPT_SFX_registerFollowingObject;
  this.setFollowingOptions     = JAVASCRIPT_SFX_setFollowingOptions;
  this.callFollowingObjects    = JAVASCRIPT_SFX_callFollowingObjects;
  this.start                   = JAVASCRIPT_SFX_start;
  this.stop                    = JAVASCRIPT_SFX_stop;  
  
}

JAVASCRIPT_SFX_addObject = function(object, destinationX, destinationY){
  object = element_isObject(object);

  this.objectPool[object.id]                     = new Object();
  this.objectPool[object.id]                     = object;
  this.objectPool[object.id]['destination']      = new Object();
  this.objectPool[object.id]['destination']['x'] = (typeof destinationX == 'number')?destinationX:null;  
  this.objectPool[object.id]['destination']['y'] = (typeof destinationY == 'number')?destinationY:null;
  this.objectPool[object.id]['initPosition']     = element_getPosition(object.id);
  
  return true;
}


JAVASCRIPT_SFX_registerFollowingObject = function(object){
  object = element_isObject(object);
  
  //registers following Objects (with method 'start')
  if(typeof object.start == 'undefined') return true;

  this.followingObjects.push(object);

  return true;
}

JAVASCRIPT_SFX_setFollowingOptions = function(key, value){
  
  this.sfx.followingOptions[key] = value;
  
  return true;
}


JAVASCRIPT_SFX_callFollowingObjects = function(){
  //calls following Objects (with method 'start')

  for(var i in this.followingObjects){
    if(typeof this.followingObjects[i].start == 'undefined') continue;

    this.followingObjects[i].start();
  }
  return true;
}

JAVASCRIPT_SFX_start = function(){
  //starts the Effect

  this.sfx.callString = this.sfx.objectName + ".doEffect()";

  //set timer  
  this.sfx.current_intervalID = setInterval(this.sfx.callString, this.sfx.calc.intervalSpeed);

  return true;
}

JAVASCRIPT_SFX_stop = function(){

  clearInterval(this.sfx.current_intervalID);  //timeout zurücksetzen
  
  if(this.sfx.followingObjects.length==0) return true;

  this.sfx.callFollowingObjects();
  
  return true;
}






var app_registeredItems = new Object();

function JAVASCRIPT_SFX_OBJECT_POSITION_CALC(){
  
  //initial Values can be changed by Method "setParameters"
  this.intervalSpeed = 50;  
  this.a             = 0.000000001;
  this.b             = 0.0001;
  this.c             = 1;  
  
  this.startTime     = null;  
  
  this.getValue      = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_getValue;
  this.setParameters = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_setParameters;  
  this.reset         = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_reset;

}

JAVASCRIPT_SFX_OBJECT_POSITION_CALC_getValue = function(direction, calcLinear){
  direction = (typeof direction == 'undefined')?1:direction;
  
  if(this.startTime == null) this.startTime = time_getMilliTimestamp();  
  
  //time  
  var currentTime = time_getMilliTimestamp();      
  var xt = currentTime - this.startTime;  
  
  var a = this.a;
  var b = this.b;
  var c = this.c;  
  
  if(calcLinear==true){
    y = a;
    y = Math.ceil(y);
  } else{
    //a*= direction;
    b*= direction;
    c*= direction;

    y = a * Math.pow(xt, 2) + (b * xt) + c; //y = ax² + bx + c  
    y = Math.floor(y);
  }
  

  return y;
  
}


JAVASCRIPT_SFX_OBJECT_POSITION_CALC_setParameters = function(intervalSpeed, a, b, c){

  this.intervalSpeed = (typeof intervalSpeed != 'undefined' && intervalSpeed != null)?intervalSpeed:this.intervalSpeed;  
  this.a = (typeof a != 'undefined' && a != null)?a:this.a;
  this.b = (typeof b != 'undefined' && b != null)?b:this.b;
  this.c = (typeof c != 'undefined' && c != null)?c:this.c;

}

JAVASCRIPT_SFX_OBJECT_POSITION_CALC_reset = function(){
  
  this.startTime = null;
  
}

function sfx_openPopUp(fileurl,width, height) {
  
  ScreenWidth = screen.width; 
  ScreenHeight = screen.height; 
  xpos = (ScreenWidth/2)-(width/2); 
  ypos = (ScreenHeight/2)-(height/2); 
  option = "left="+xpos+",top="+ypos+",width="+width+",height="+height+",status=false,toolbar=false";
  neupop = open(fileurl,"Detail",option);

}


/***************************************************************
*  ROLLOUT
****************************************************************/
 
function JAVASCRIPT_SFX_ROLLOUT(objectName, followOptions) {
   
  this.sfx                     = new JAVASCRIPT_SFX(); //uses JAVASCRIPT_SFX
  this.sfx.objectName          = objectName;
  this.oid                     = element_buildUniqueObjectID(this);
  
  this.effect_type             = 'slide';
  this.status_open             = false;  

  if(typeof followOptions != 'undefined'){
    unlock_sizing = followOptions['unlock_sizing']==true?true:false; 
    this.sfx.setFollowingOptions('unlock_sizing', unlock_sizing);      
  }
  /// register Functions 
  this.doEffect                = JAVASCRIPT_SFX_ROLLOUT_doEffect;   
  this.addItem                 = JAVASCRIPT_SFX_ROLLOUT_addItem;   
  this.setSpeedParameters      = JAVASCRIPT_SFX_ROLLOUT_setSpeedParameters;   
  this.start                   = this.sfx.start;
  this.stop                    = this.sfx.stop;

  return true;
}

//Wrapper Function
JAVASCRIPT_SFX_ROLLOUT_addItem = function(object, destinationX, destinationY, effectType){
  object = element_isObject(object);
  
  var size = element_getSize(object);
  
  switch(effectType){
    default:
    case 'slide':
      var visibleByPercentX = destinationX.toString().substring((destinationX.toString().length-1))=='%'?true:false;
      var visibleByPercentY = destinationY.toString().substring((destinationY.toString().length-1))=='%'?true:false;
      
      var visibleThresholdX = size.width * (-1);
      var visibleThresholdY = size.height * (-1);
    
      var initPosition = element_getPosition(object); //aktuelle Position als Fallback

      var destinationX = (destinationX!='')?element_recalcValue2px(destinationX, size.width):initPosition.x; //Prozentualwerte umrechnen
      var destinationY = (destinationY!='')?element_recalcValue2px(destinationY, size.height):initPosition.y;      

      var x = (visibleByPercentX)?visibleThresholdX + destinationX:parseInt(destinationX); //Werte umrechnen
      var y = (visibleByPercentY)?visibleThresholdY + destinationY:parseInt(destinationY);
      
    break;
    
    case 'size':
      var x = element_recalcValue2px(destinationX, size.width);
      var y = element_recalcValue2px(destinationY, size.height);
    break;
  }

  this.sfx.addObject(object, x, y);  

  this.sfx.objectPool[object.id]['effectType'] = (typeof effectType != 'undefined')?effectType:'slide';

}

JAVASCRIPT_SFX_ROLLOUT_setSpeedParameters = function(intervalSpeed, a, b, c){

  this.sfx.calc.setParameters(intervalSpeed, a, b, c);  
  
}


JAVASCRIPT_SFX_ROLLOUT_doEffect = function(){

  var objects = this.sfx.objectPool;

  var currentValues = new Object();
  currentValues['x'] = null;
  currentValues['y'] = null;
  for(var id in objects){
    
    var object = objects[id];

    //get currentValues
    switch(object.effectType){
    default:
    case 'slide':
      //positions
      var currentPos = element_getPosition(object);  
      currentValues['x'] = currentPos.x;
      currentValues['y'] = currentPos.y;
    break;
    
    case 'size':
      var currentSize = element_getSize(object);  
      currentValues['x'] = currentSize.width;
      currentValues['y'] = currentSize.height;
    break;
    }
    
    
    //direction
    var direction = new Object();
    direction['x'] = (currentValues.x<object.destination.x)?1:-1;
    direction['y'] = (currentValues.y<object.destination.y)?1:-1;  

    //parameters
    var y = 0;
    
    //calculation
    for(axis in direction){
      
      if(currentValues[axis] == object.destination[axis]) continue;
      
      y = this.sfx.calc.getValue(direction[axis]);

      if(direction[axis] > 0){
        currentValues[axis]+= y;    
        currentValues[axis] = (currentValues[axis]<object.destination[axis])?currentValues[axis]:object.destination[axis];    
      } else if(direction[axis] < 0){
        currentValues[axis]-= y;
        currentValues[axis] = (currentValues[axis]>object.destination[axis])?currentValues[axis]:object.destination[axis];
      }    
    }
    
    //make movement/sizing
    switch(object.effectType){
    default:
    case 'slide':
      element_move(object, currentValues.x, currentValues.y);
    break;
    
    case 'size':
      element_setSize(object, currentValues.x, currentValues.y);
    break;
    }
    
    
    if(currentValues.x == object.destination.x && currentValues.y == object.destination.y) {
      delete this.sfx.objectPool[id];
      continue;      
    }
  } 

  if(object_count(this.sfx.objectPool) == 0) {
    this.stop();
  }
      
  return true;
}



var previewImages = new Object();
var initData = new Object();

function registerImage(boxID, width, height, fileurl){
  
  if(typeof previewImages[boxID] == 'undefined') previewImages[boxID] = new Object();
  previewImages[boxID][width]           = new Object();
  previewImages[boxID][width]['url']    = fileurl;
  previewImages[boxID][width]['width']  = width;
  previewImages[boxID][width]['height'] = height;
   
  if(typeof initData[boxID] == 'undefined'){
    initData[boxID]             = new Object();
    initData[boxID]['maxwidth'] = 0;
  }
  if(parseInt(width)>=initData[boxID]['maxwidth']){
    initData[boxID]['maxwidth'] = parseInt(width);
    initData[boxID]['maxitem']  = previewImages[boxID][width];
  }
  
  if(typeof initData[boxID]['init'] == 'undefined') initData[boxID]['init'] = new Object();
}

function initImagePreview(boxID){
  var objImage      = element_isObject('preview_image_image_'+boxID);

  var tmp = new Object();
  for(var i in previewImages[boxID]){
    tmp = previewImages[boxID][i];
    break;
  }
  objImage.src = tmp['url'];
  element_setSize(objImage, tmp['width'], tmp['height']);
  
  image_preview_reset(boxID);

}

function image_preview_size(boxID, direction){
  var objPositioner = element_isObject('preview_image_positioner_'+boxID);
  var objImage      = element_isObject('preview_image_image_'+boxID);
  
  var min  = 50;
  var max  = initData[boxID]['maxwidth'];

  var step = 8; //in percent
  var currentSize = element_getSize(objImage);

  if(direction=='+'){
    currentSize.width  += parseInt(((currentSize.width/100)*step));
    currentSize.height += parseInt(((currentSize.height/100)*step));
  }
  if(direction=='-'){
    currentSize.width  -= parseInt(((currentSize.width/100)*step));
    currentSize.height -= parseInt(((currentSize.height/100)*step));
  }
  
  if(currentSize.width<=min) return true;  
  if(currentSize.width>max) {
    var currentImage = initData[boxID]['maxitem'];
    currentSize.width  = initData[boxID]['maxitem'].width;
    currentSize.height = initData[boxID]['maxitem'].height;
  } else {
    var currentImage = image_preview_getNextMatch(boxID, currentSize, true);
  }
  
  image_preview_zoom(boxID, objImage, currentSize.width, currentSize.height);    
  objImage.src = currentImage.url;  
}

//find the next smaller/higher Image to fit in Panel
function image_preview_getNextMatch(boxID, size, higher){
  
  higher = (typeof higher == 'undefined')?false:true;
  
  var ret = new Object();

  //find the next smaller Image to fit in Panel
  var currentDiff = higher?width:size.width;
  for(var width in previewImages[boxID]){
    if(!higher){
      var diff = size.width - width;      
    } else {
      var diff = width - size.width;
    }
    
    if(diff<0) continue;
    if(currentDiff<diff) continue;
    
    ret = previewImages[boxID][width];
    
    currentDiff = diff;
  }

  return ret;
}

function image_preview_reset(boxID){
  var objPanel      = element_isObject('preview_image_holder_'+boxID);
  var objPositioner = element_isObject('preview_image_positioner_'+boxID);
  var objImage      = element_isObject('preview_image_image_'+boxID);

  image_preview_move(objPositioner, 0, 0);
  
  if(typeof initData[boxID]['init']['url'] != 'undefined'){
    
    image_preview_zoom(boxID, objImage, initData[boxID]['init']['width'], initData[boxID]['init']['height']);

    objImage.src = initData[boxID]['init']['url'];
  
    return true;
  }
  
  var size = element_getSize(objPanel);
  var newSize = image_shrinkToFit(objImage, size.width, size.height);
  
  image_preview_zoom(boxID, objImage, newSize.width, newSize.height);

  //find the next bigger Image to fit in Panel
  var currentImage = image_preview_getNextMatch(boxID, newSize, true);
  objImage.src = currentImage.url;

  initData[boxID]['init']   = currentImage;
  initData[boxID]['init']['width']  = newSize.width; 
  initData[boxID]['init']['height'] = newSize.height;
}



var effectZoom = new Object();
var effectMove = new Object();
function image_preview_zoom(boxID, obj, width, height){
  element_setSize(obj, width, height);
  return null;
  
  if(typeof effectZoom[boxID] == 'undefined') effectZoom[boxID] = new Object();
  effectZoom[boxID] = new JAVASCRIPT_SFX_ROLLOUT("effectZoom['"+boxID+"']");
  effectZoom[boxID].addItem(obj , width+'px', height+'px', 'size');
  
  var interval = 40;
  var a        = 0.00001;
  var b        = 0.001;
  var c        = 1;
  
  effectZoom[boxID].setSpeedParameters(interval, a, b ,c);

  effectZoom[boxID].start();
}
function image_preview_move(obj, left, top){
  //element_move(obj, left, top);
  
  effectMove = new JAVASCRIPT_SFX_ROLLOUT('effectMove');
  effectMove.addItem(obj , left, top);
  
  var interval = 65;
  var a        = 0.000001;
  var b        = 0.001;
  var c        = 1;
  
  effectMove.setSpeedParameters(interval, a, b ,c);

  effectMove.start();
}

  /**
  * Function : __debug()
  * Arguments: The data - array,hash(associative array),object
  *    The level - OPTIONAL
  * Returns  : The textual representation of the array.
  * This function was inspired by the print_r function of PHP.
  * This will accept some data as the argument and return a
  * text that will be a more readable version of the
  * array/hash/object that is given.
  */
  function __debug(arr,showalert) {
    var ret = '';
    var level = 0;
    showalert = (showalert!='undefined')?showalert:true;
    if(!name) name = '';

    //The padding given at the beginning of the line.
    var level_padding = "";
    
    if(!showalert){
      ret+= '<div style="margin:0px 0px 5px 0px;background:#ffcccc;overflow:hidden;border:1px solid #000000;color:#444444;">'+"\n";
      ret+= '<div style="font-style:italic">DEBUG-Output(JS)</div>'+"\n";
      ret+= '<div style="font-weight:bold">'+name+'</div>'+"\n";
      ret+= '<pre>'+"\n";
    }
    for(var j=0;j<=level;j++) level_padding += "  ";
    if(typeof(arr) == 'object') { //Array/Hashes/Objects
     for(var item in arr) {
      var value = arr[item];
      if(typeof(value) == 'object') { //If it is an array,
       ret += level_padding + "" + item + " ... ";
       ret += dump(value,level+1);
       ret += "\n";
      } else {
       ret += level_padding + "" + item + " => " + value + "\n";
      }
     }
    } else { //Strings/Chars/Numbers etc.
     ret+= "===>"+arr+"<===("+typeof(arr)+")"+"\n";
    }
    if(!showalert){
      ret+= '</pre>'+"\n";
      ret+= '</div>'+"\n";
    }
    
    if(!showalert){
      document.write(ret);
    }else{
      alert(ret);
    }
    
    return true;
  }

function _dbg(dbgObj){
  if(typeof dbgObj == 'undefined'){
    alert('_dbg: no object given');
    return false;
  }
  
  var x = new Array();
//alert(tickeritemmap[0].all['clientHeight']); 
  var ipp = 18;
  var tmp = new Array();
  var cnt = 0;
  for(var i in dbgObj){    
    
    if(typeof dbgObj[i] == 'undefined') continue;
    tmp.push(i.toString()+': '+dbgObj[i]);
    cnt++;
    if(cnt==ipp){
      x.push(tmp.join("\n"));
      var tmp = new Array();
      cnt = 0;
    }
  
  }
  for(var id in x){
    alert(x[id]);
  }
}

function errorMessage(meldung, url, zeile){
   var txt = "Es ist ein Fehler aufgetreten!\n\n"
   txt += "Meldung: " + meldung + "\n"
   txt += "URL: " + url + "\n"
   txt += "Zeile: " + zeile
   alert(txt)
   return true
}
//window.onerror = errorMessage;

/***************************************************************
*  FADER
***************************************************************/
 
function JAVASCRIPT_SFX_FADE(objectName) {
  
  this.sfx                     = new JAVASCRIPT_SFX(); //uses JAVASCRIPT_SFX
  this.sfx.objectName          = objectName;
  this.oid                     = element_buildUniqueObjectID(this);
  
  // register Functions 
  this.doEffect                = JAVASCRIPT_SFX_FADE_doEffect;   
  this.addItem                 = JAVASCRIPT_SFX_FADE_addItem;   
  this.setSpeedParameters      = JAVASCRIPT_SFX_FADE_setSpeedParameters;
  this.start                   = this.sfx.start;
  this.stop                    = this.sfx.stop;
  
  return true;
}

//Wrapper Function
JAVASCRIPT_SFX_FADE_addItem = function(object, destinationX, destinationY){
  object = element_isObject(object);
  
  var x = null;
  var y = null;
  
  x = element_recalcValue2px(destinationX, 100);
  
  this.sfx.addObject(object, x, y);  

}

JAVASCRIPT_SFX_FADE_setSpeedParameters = function(intervalSpeed, a, b, c){
  
  this.sfx.calc.setParameters(intervalSpeed, a, b, c);  

}



JAVASCRIPT_SFX_FADE_doEffect = function(oid){
 
  var objects = this.sfx.objectPool;  
  for(var id in objects){  
    var object = objects[id];  //Momentan wird nur 1 Objekt/Effekt unterstützt
    
    //positions
    var currentOpacity = element_getOpacity(object); 

    //direction
    var direction = (currentOpacity<object.destination.x)?1:-1;  
    
    //parameters
    var y = 0;
    
    //calculation      
    y = this.sfx.calc.getValue(direction);
      
    currentOpacity+= y;

    if(direction > 0){    
      currentOpacity = (currentOpacity<object.destination.x)?currentOpacity:object.destination.x;    
    } else if(direction < 0){
      currentOpacity = (currentOpacity>object.destination.x)?currentOpacity:object.destination.x;
    }    
    
    //movement
    element_setOpacity(object, currentOpacity);
    
    if(currentOpacity == object.destination.x) {
      delete this.sfx.objectPool[id];
      continue;
    }
  } 
  
  if(object_count(this.sfx.objectPool) == 0) {
    this.stop();
  }
      
  return true;

}




/**
 * content.layout.popup.animation.js - insert headline here
 *
 * COPYRIGHT: All  title   and  proprietary  rights,  including  trade
 * secrets,   in   the   Software   and   any   copies thereof and the
 * accompanying  written   materials,   are  owned  by   schukai  GmbH
 * and  are  protected  by  German  copyright  laws,  other applicable
 * copyright   laws  and  international  treaty  provisions.
 *
 * @package    alvine
 * @author     schukai GmbH <info@schukai.de>
 * @copyright  Copyright (C) 2002, 2003, 2004, 2005, 2006 schukai GmbH
 * @license    http://www.alvine.de/license/
 * @version    20061114
 * @link       http://www.alvine.de/
 */
 
function content_frontend_plugin_content_layout_popup_animation_init(){

}

/*usage:
 * addEvent(object,'mousemove',function);
 * removeEvent(object,'mousemove',function);
 * 
 * important: Function must be given as reference(without quotes!)
*/

function event_add(obj, type, fn){
	var ietype = type;
	if(type.indexOf('on')>-1) {
		type = type.substring(2);
	} else{
	 	ietype = 'on'+type;
	}

  obj = element_isObject(obj);
  if(!obj) return false;

  if (obj.addEventListener) {
    obj.addEventListener(type, fn, false);
  } else if (obj.attachEvent) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function() { return obj['e'+type+fn](window.event); }
    obj.attachEvent(ietype, obj[type+fn] );
  }
  
  return true;
}

function event_remove(obj, type, fn){
  var ietype = type;
	if(type.indexOf('on')>-1) {
	 	type = type.substring(2);
	} else{
	 	ietype = 'on'+type;
	}
	
	obj = element_isObject(obj);
  if(!obj) return false;
  
  if (obj.removeEventListener) {
    obj.removeEventListener(type, fn, false);
  } else if (obj.detachEvent) {
    obj.detachEvent(ietype, obj[type+fn]);
    obj[type+fn] = null;
    obj['e'+type+fn] = null;
  }
  
  return true;
}

//returns the source-element of an event
function event_getTarget(e){
  if(!e) return null;

  if(e.target) return e.target;
  if(e.srcElement) return e.srcElement;
    
  return null;
}

