function getElementDimensions(id) {
  id = $(id);
  dx = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
  dy = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  co = Position.cumulativeOffset(id);
  co[0] = co[0] || parseInt(Element.getStyle(id,'left'));
  co[1] = co[1] || parseInt(Element.getStyle(id,'top'));
  ro = Position.realOffset(id);
  dim = Element.getDimensions(id);
  return {left: co[0], top: co[1], 
          screenleft: co[0]-dx, screentop: co[1]-dy, 
          width: dim.width, height: dim.height, 
          dx: dx, dy: dy};
}

function winHeight () {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}

function BCSpamSafe(nam,srv,cls,txt) {
  document.write('<a href="mailto:'+nam+'@'+srv+'" class="'+cls+'">Mail</a>')
}

try {
  document.execCommand("BackgroundImageCache",false,true);
} catch(err) {}


/*----------------------------------------------------------------------------*/
var bcLayers = {
  absTopOpened: 68,
  absTopClosed: 407,
  state: 0,
  blnShow1: false,
  blnShow2: false,
  blnShow3: false,
  
  init: function() {
  },

  saveState: function() {
    var sta = 0;
    if (bcLayers.blnShow1) { sta += 1; }
    if (bcLayers.blnShow2) { sta += 2; }
    if (bcLayers.blnShow3) { sta += 4; }
    Cookie.set('bcLayers',sta);
  },

  loadState: function() {
    var sta = Cookie.get('bcLayers'); 
    bcLayers.blnShow3 = (sta > 3);
    bcLayers.blnShow2 = (sta > 1);
    bcLayers.blnShow1 = (sta > 0);
    bcLayers.redraw();
  },

  redraw: function() {
    try { $("layer0").style.height = winHeight()-5; } catch(e) { }
    if (bcLayers.blnShow3) { bcLayers.open3(); return; }
    if (bcLayers.blnShow2) { bcLayers.open2(); return; }
    if (bcLayers.blnShow1) { bcLayers.open1(); return; }
    bcLayers.close1();
  },

  /*  */
  open1: function() {
    if (bcLayers.blnShow3) { bcLayers.close3(); }
    if (bcLayers.blnShow2) { bcLayers.close2(); }
    var dim1 = getElementDimensions($('layer1Nav'));
    var dim2 = getElementDimensions($('layer2Nav'));
    var top1 = dim1.height+bcLayers.absTopOpened;
    $('layer1Nav').style.top = bcLayers.absTopOpened; 
    $('layer1Content').style.top = top1;
    $('layer1Content').style.height = dim2.top-top1;
    $('layer1Content').style.display = 'block';   
    $('layer0').style.backgroundImage = 'url(app_icc/css/bc/pub_level0_act_bg.gif)'; 
    bcLayers.blnShow1 = true; 
    bcLayers.saveState();
  },
  close1: function() {
    if (bcLayers.blnShow3) { bcLayers.close3(); }
    if (bcLayers.blnShow2) { bcLayers.close2(); }
    $('layer1Content').style.display = 'none';
    var dim1 = getElementDimensions($('layer1Nav'));
    var dim2 = getElementDimensions($('layer2Nav'));
    $('layer1Nav').style.top = bcLayers.absTopClosed; 
    $('layer0').style.backgroundImage = 'url(app_icc/css/bc/pub_level0_bg.gif)'; 
    bcLayers.blnShow1 = false; 
    bcLayers.saveState();
  },
  
  /*  */
  open2: function() {
    bcLayers.open1();
    if (bcLayers.blnShow3) { bcLayers.close3(); }
    var dim1 = getElementDimensions($('layer1Nav'));
    var dim2 = getElementDimensions($('layer2Nav'));
    var dim3 = getElementDimensions($('layer3Nav'));
    var top2 = dim1.top+dim1.height;
    $('layer2Nav').style.top = top2; 
    $('layer2Content').style.top = top2; 
    $('layer2Content').style.height = dim3.top-top2;
    $('layer2Content').style.display = 'block';   
    $('PDFOpenText').style.display = 'none';
    $('PDFCloseText').style.display = 'block';
    bcLayers.blnShow2 = true; 
    bcLayers.saveState();
  },
  close2: function() {
    if (bcLayers.blnShow3) { bcLayers.close3(); }
    $('layer2Content').style.display = 'none';
    var dim2 = getElementDimensions($('layer2Nav'));
    var dim3 = getElementDimensions($('layer3Nav'));
    $('layer2Nav').style.top = dim3.top-dim2.height;
    $('PDFOpenText').style.display = 'block';
    $('PDFCloseText').style.display = 'none';
    bcLayers.blnShow2 = false; 
    bcLayers.saveState();
  },
  
  /*  */
  open3: function() {
    bcLayers.open1();
    bcLayers.open2();
    var dim2 = getElementDimensions($('layer2Nav'));
    var dim3 = getElementDimensions($('layer3Nav'));
    var top3 = dim2.top+dim2.height+dim3.height;
    $('layer3Nav').style.top = dim2.top+dim2.height; 
    $('layer3Content').style.top = top3; 
    $('layer3Content').style.height = winHeight()-top3;
    $('layer3Content').style.display = 'block';   
    $('layer2Content').style.display = 'none';
    $('PDFOpenText').style.display = 'block';
    $('PDFCloseText').style.display = 'none';
    bcLayers.blnShow3 = true;

    document.body.style.backgroundImage = 'url(/app_icc/css/bc/pub_level3_bg.gif)';
    document.body.style.backgroundRepeat = 'repeat-y';
    
    bcLayers.saveState();
  },
  close3: function() {
    $('layer3Content').style.display = 'none';
    var dim1 = getElementDimensions($('layer1Nav'));
    var dim2 = getElementDimensions($('layer2Nav'));
    var dim3 = getElementDimensions($('layer3Nav'));
//    $('layer3Nav').style.top = bcLayers.absTopClosed+dim1.height+dim2.height; 
    $('layer3Nav').style.top = winHeight()-dim2.height; 
    bcLayers.blnShow3 = false;
    bcLayers.saveState();
    bcLayers.close2();
  }  
}

function openLayer0() {
  bcLayers.blnShow1 = true; 
  bcLayers.blnShow2 = false; 
  bcLayers.blnShow3 = false; 
  bcLayers.saveState();
}

/*----------------------------------------------------------------------------*/
var bcRules = {
  'body': function(el) {
      el.onresize = function() {
        bcLayers.redraw(); 
      };    
      el = null;
    },
  '#layer0': function(el) {
      el.style.top = 0; 
      el.style.height = winHeight()-5;    
      el = null;
    },
  '#PubMainTitle': function(el) {
      el.onclick = function() {
        bcLayers.close1(); 
        return false;
      };    
      el = null;
    },
  '#PDFOpenText': function(el) {
      el.onclick = function() {
        bcLayers.open2(); 
        return false;
      };    
      el = null;
    },
  '#PDFCloseText': function(el) {
      el.onclick = function() {
        bcLayers.close2(); 
        return false;
      };    
      el = null;
    },
  '#layer3Nav': function(el) {
      el.onclick = function() {
        if (!bcLayers.blnShow3) {
          bcLayers.open3(); 
        } else {
          bcLayers.close3(); 
        }  
        return false;
      };    
      el = null;
    },
  '#MainNav td.main': function(el) {
      el.onmouseover = function() {
        Element.setStyle(el,{backgroundImage: 'url(app_icc/css/bc/pub_mainnav_bg.gif)'}); 
        if (!Element.hasClassName(el,'active')) { 
          $('sub'+el.id).style.display = 'block';
        }  
      };
      el.onmouseout = function() {
        Element.setStyle(el,{backgroundImage: ''}); 
        if (!Element.hasClassName(el,'active')) { 
          $('sub'+el.id).style.display = 'none';
        }  
      };
    },
  '#MainNav div.sub': function(el) {
      el.onmouseover = function() {
        if (!Element.hasClassName(el,'active')) { 
          try { el.style.display = 'block'; } catch(e) { }
        }  
      };
      el.onmouseout = function() {
        if (!Element.hasClassName(el,'active')) { 
          try { el.style.display = 'none'; } catch(e) { }
        }  
      };
    },
  '#MainNav td.item': function(el) {
      el.onmouseover = function() {
        Element.setStyle(el,{backgroundColor: '#7592A3'}); 
      };
      el.onmouseout = function() {
        Element.setStyle(el,{backgroundColor: ''}); 
      };
    },
  '#MainNav a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '#cusTop a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '#cusTopNavigation a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '#cusNews a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '.cusQuickLink a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '#AccCmd a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '.scCartSum a': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  '#Pub #SeaFrm .button': 
    function(el) {
      el.onclick = function() { openLayer0(); };
      el = null;
    },
  'div.floatright': function(el) {
      new Insertion.Bottom(el,'<div align="right">Klicken Sie auf das Bild um es zu vergrössern</div>');
      el = null;
    },
  '.cusSeminarRegisterButton a': function(el) {
      el.onclick = function() {
        Cookie.set('bcRegister',el.title);
      };
    },
  '#cusRegisterSeminarName': function(el) {
      el.innerHTML = Cookie.get('bcRegister');
    },
  '#cusRegisterSeminarNameFld': function(el) {
      el.value = Cookie.get('bcRegister');
    }
    
}
Behaviour.register(bcRules);