var CommonClass = function(){
  var initFunctions       = [];
  var superInitFunctions  = [];

  this.initRolloverImgs = function(){
    var i, img, loader;
    var imgs = $A(document.images);
    regexps = $A([
      [/-geist.*\?ro/, 'geist', 'leben'],
      [/-geist.*\?ro/, 'geist', 'aktiv', true],
      [/-leben.*\?ro/, 'leben', 'aktiv', true]
    ]);
    
    imgs.each(function(img){
      regexps.each(function(re){
        if (re[0].exec(img.src)){
          loader      = new Image(); 
          loader.src  = img.src.replace(re[1], re[2]);
          
          if (re[3]){
            img.onmouseover = function(e){
              this.src = this.src.replace(re[1], re[2]);
            };

            img.onmouseout = function(e){
              this.src = this.src.replace(re[2], re[1]);
            };
          }
        }
      });
    });
  }

  this.reviveChilds = function(el){
    $A(el.getElementsByTagName('img')).each(function(img){
      if (/-geist.*\?ro/.exec(img.src)){
        img.src = img.src.replace('geist', 'leben');
      }
      Common.initRolloverImgs();
    });
  }


  this.popup = function(url, params){
    var props = $H({width:550,height:600,status:0,directories:0,hotkeys:1,location:0,menubar:0,resizable:1,scrollbars:0,toolbar:0}).
                merge($H(params)).
                map(function(pair){return pair.join('='); }).
                join(','); 

    var win = window.open(url,'pop',props);
    if (win) win.focus();
    return win;
  }

  this.changeImg = function(el, src){
    var onComplete;
            
    var clone = function(counter){
      
      if (typeof(counter) != 'Number'){ 
        onComplete = counter; counter=1; 
      }

      if (ref.complete){
        if( ref.width>0 && ref.height>0 ){
          el.src     = ref.src;
          el.width   = ref.width;
          el.height  = ref.height;
        } 
        if (typeof(onComplete) == 'function') { onComplete(); }
      } else {
        counter++;
        if (counter < 20) { setTimeout(function(){ clone(counter)},200); } 
      }
    }
    
    var v = $('video');
    if (src.match(/\.jpg/)){
      if (v) $('video').hide();
      var ref = new Image();
      ref.src = src;
      clone(function(){ el.show(); });
    } else {
      el.hide();
      if (v) $('video').show()
    } 
  }

  this.addInitFunction = function(func){
    initFunctions.push(func);
  }

  this.addSuperInitFunction = function(func){
    superInitFunctions.push(func);
  }

  this.initAll = function(){
    for (var i=0; i<superInitFunctions.length; i++){
      superInitFunctions[i]();   
    }  

    for (var i=0; i<initFunctions.length; i++){
      initFunctions[i]();   
    }  
  }

  var soundEmbed;
  this.embedSound = function(url){
    try {
      if (soundEmbed)
        document.body.removeChild(soundEmbed);
    } catch (e) {}

    soundEmbed = document.createElement("embed");
    soundEmbed.style.height = "0px";
    soundEmbed.setAttribute("src",        url);
    soundEmbed.setAttribute("hidden",     true);
    soundEmbed.setAttribute("autostart",  true);
    document.getElementById('gummy').appendChild(soundEmbed);
  }
}
var Common = new CommonClass();
