
//==================================================================================
//==================================================================================
//
// DRINKME
// AUTOR: DF
// ERSTELLT: 20.09.2007
//
//==================================================================================
//==================================================================================


var undefined;
var TIMEOUTAUTOMATICANIMATE;
var TIMEOUTPRELOAD;
var TIMEOUTPRELOADDELAY = 100;
var TIMEOUT;
var TIMEOUTDELAY = 100;
var NAVIGATIONINUSE = false;
var NAVIGATIONIMGCACHE;
var NAVIGATIONIMG = new Image();
NAVIGATIONIMG.id = 'head-navigation-image_active';
NAVIGATIONIMG.src = 'graphic/df_anim_menue.gif';
NAVIGATIONIMG.useMap = '#navigation_map';
NAVIGATIONIMG.alt = 'Grafik: Haupt-Navigation';
NAVIGATIONIMG.title = 'Haupt-Navigation';
var CONTENT = {};
var MAPAREA = {};

var ACTIVEBOTTLE;

function setActiveBottle(idx) {
  if (ACTIVEBOTTLE){
    ACTIVEBOTTLE.className = 'head-bottle-animated';
  }
  ACTIVEBOTTLE = undefined;
  if (arguments.length){
    var id = 'head-bottle-animated-' + idx;
    var className = 'head-bottle-actice-' + idx;
    var elem = document.getElementById(id);
    if (! elem){
      return;
    }
    elem.className = 'head-bottle-animated ' + className;
    ACTIVEBOTTLE = elem;
  }
}

function automaticAnimateNavigation1() {
  elem = MAPAREA[MAPAREA.length -1];
  var preloadPage = document.getElementById('preload-page');
  preloadPage.style.display = 'block';
  elem.onmouseover();
  var func = function () {automaticAnimateNavigation2(elem)};
  TIMEOUTAUTOMATICANIMATE = window.setTimeout(func, 1500);
}

function automaticAnimateNavigation2(lastElem) {
  if(TIMEOUTAUTOMATICANIMATE){
    window.clearTimeout(TIMEOUTAUTOMATICANIMATE);
  }
  lastElem.onmouseout();
  elem = document.getElementById('head-drinkme-anker');
  elem.className = 'drinkme-active';
  elem.onmouseover();
  var preloadPage = document.getElementById('preload-page');
  var func = function () {if(TIMEOUTAUTOMATICANIMATE){window.clearTimeout(TIMEOUTAUTOMATICANIMATE);} elem.onmouseout(); preloadPage.style.display = 'none'; document.getElementById('head-drinkme-anker').className='';}
  TIMEOUTAUTOMATICANIMATE = window.setTimeout(func, 1500);
}

function animateNavigation(elem) {
  NAVIGATIONINUSE = true;
  if (! NAVIGATIONIMGCACHE) {
    NAVIGATIONIMGCACHE = document.getElementById('head-navigation-image');
  }
  displayNavigationArrow(elem);
  var parentElem = document.getElementById('head-navigation');
  if (! parentElem){
    return;
  }
  try {
    parentElem.replaceChild(NAVIGATIONIMG, NAVIGATIONIMGCACHE);
  } catch(e) {
    return;
  }
}

function displayNavigationArrow(elem, type) {
  var arrow = document.getElementById('head-navigation-arrow');
  if (!elem || type == 'active'){
    arrow = document.getElementById('head-navigation-arrow-active');
  }
  if (! arrow){
    return;
  }
  if (! elem) {
    arrow.style.display = 'none';
    return;
  }
  var diff = elem.coords.split(/\,/);
  var top = Tools.getElementDocumentPositionTop(elem) + parseFloat(diff[1] - 10);
  var left = Tools.getElementDocumentPositionLeft(elem) + parseFloat(diff[0] - 18);
  arrow.style.top = top + 'px';
  arrow.style.left = left + 'px';
  arrow.style.display = 'block';
}

function resetNavigation() {
  NAVIGATIONINUSE = false;
  TIMEOUT = window.setTimeout('resetNavigationImage();', TIMEOUTDELAY);
}

function resetNavigationImage() {
  if (TIMEOUT){
    window.clearTimeout(TIMEOUT);
  }
  if (NAVIGATIONINUSE) {
    return;
  }
  var arrow = document.getElementById('head-navigation-arrow');
  if (! arrow){
    return;
  }
  arrow.style.display = 'none';
  var parentElem = document.getElementById('head-navigation');
  if (! parentElem){
    return;
  }
  try {
    parentElem.replaceChild(NAVIGATIONIMGCACHE, NAVIGATIONIMG);
  } catch(e) {
    return;
  }
}

function animateEyes(direction) {
  var elemLeft = document.getElementById('eyes_left');
  var elemRight = document.getElementById('eyes_right');
  var elemBottom = document.getElementById('eyes_bottom');
  if (! (elemLeft && elemLeft)){
    return;
  }
  elemLeft.style.display = 'none';
  elemRight.style.display = 'none';
  elemBottom.style.display = 'none';
  if (direction == 'left'){
    elemLeft.style.display = 'block';
  }
  if (direction == 'right'){
    elemRight.style.display = 'block';
  }
  if (direction == 'bottom'){
    elemBottom.style.display = 'block';
  }
}

function unfadePreloadPage(elem, diff, endfunc) {
  if (TIMEOUTPRELOAD){
    window.clearTimeout(TIMEOUTPRELOAD);
  }
  var preloadPage = elem;
  if (!preloadPage){
    return;
  }
  var opGrenzwert = 1;
  if (preloadPage.filters != undefined){
    // IE
    opGrenzwert = 100;
    var opValue = parseFloat(0 + parseFloat(diff));
    preloadPage.filters['Alpha']['opacity'] = opValue;
    preloadPage.filters['Alpha']['finishopacity'] = opValue;
    diff += 8;
  } else {
    // Other
    var opValue = parseFloat(0 + parseFloat(diff));
    preloadPage.style.opacity = opValue;
    diff += 0.08;
  }
  if (opValue < opGrenzwert) {
    var func = function () {unfadePreloadPage(preloadPage, diff, endfunc)};
    TIMEOUTPRELOAD = window.setTimeout(func, TIMEOUTPRELOADDELAY);
    return;
  }
  preloadPage.style.display = 'none';
  if (endfunc) {
    endfunc();
  }
}

function fadePreloadPage(elem, diff, endfunc) {
  if (TIMEOUTPRELOAD){
    window.clearTimeout(TIMEOUTPRELOAD);
  }
  var preloadPage = elem;
  if (!preloadPage){
    return;
  }
  if (preloadPage.filters != undefined){
    // IE
    var opValue = parseFloat(100 - parseFloat(diff));
    preloadPage.filters['Alpha']['opacity'] = opValue;
    preloadPage.filters['Alpha']['finishopacity'] = opValue;
    diff += 5;
  } else {
    // Other
    var opValue = parseFloat(1 - parseFloat(diff));
    preloadPage.style.opacity = opValue;
    diff += 0.05;
  }
  if (opValue > 0) {
    var func = function () {fadePreloadPage(preloadPage, diff, endfunc)};
    TIMEOUTPRELOAD = window.setTimeout(func, TIMEOUTPRELOADDELAY);
    return;
  }
  preloadPage.style.display = 'none';
  if (endfunc) {
    endfunc();
  }
}

function setContentPages() {
  var arr = document.getElementsByTagName('div');
  for (var i=0; i<arr.length; i++) {
    if (! arr[i].id || ! arr[i].id.toString().match(/^\_content\_/)){
      continue;
    }
    CONTENT[arr[i].id] = arr[i];
  }
}

function setMapArea() {
  MAPAREA = document.getElementsByTagName('area');
}

function displayPage(idx, mode) {
  if (! idx){
    return;
  }
  var preloadContentPage = document.getElementById('body-content-preload');
  preloadContentPage.style.display = 'block';
  //var activePage = getActiveContentPage();
  var body = document.getElementsByTagName('body')[0];
  var func = function() {setPage(idx, mode);};
  unfadePreloadPage(preloadContentPage, 0, func);
}

function getActiveContentPage() {
  for (var i in CONTENT){
    if (CONTENT[i].style.display == 'block'){
      return CONTENT[i];
    }
  }
  return undefined;
}


function setPage(idx, mode) {
  if (! idx){
    return;
  }
  idx = idx.toString().split(/\#/)[1];
  for (var i in CONTENT){
    CONTENT[i].style.display = 'none';
  }
  var ground = document.getElementById('body-content');
  ground.style.display = 'block';
  var groundSpecial = document.getElementById('body-content-special');
  groundSpecial.style.display = 'none';
  if (! mode){
    setActiveBottle();
  }
  if (mode){
    //alert(mode);
    ground.style.display = 'none';
    groundSpecial.style.display = 'block';
    if (mode == 'boost'){
      groundSpecial.className = "special-boost";
    } else if (mode == 'booz'){
      groundSpecial.className = "special-booz";
    } else {
      groundSpecial.className = "special-ladies";
    }
  }
  if (CONTENT[idx]){
    CONTENT[idx].style.display = 'block';
    var preloadContentPage = document.getElementById('body-content-preload');
    preloadContentPage.style.display = 'block';
    var body = document.getElementsByTagName('body')[0];
    if (body){
      //preloadContentPage.style.top = Tools.getElementDocumentPositionTop(activePage) + 'px';
      //preloadContentPage.style.left = Tools.getElementDocumentPositionLeft(activePage) + 'px';
      //preloadContentPage.style.width = activePage.offsetWidth + 'px';
      if (IE6){
        //preloadContentPage.style.height = parseFloat(body.offsetHeight - Tools.getElementDocumentPositionTop(preloadContentPage)) + 'px';
      } else {
        //preloadContentPage.style.height = parseFloat(body.offsetHeight - preloadContentPage.style.top) + 'px';
      }
    }
    fadePreloadPage(preloadContentPage, 0);
  }
}

function unsetFocusBorder() {
  var arr = document.getElementsByTagName('a');
  if (arr){
    for (var i=0; i<arr.length; i++) {
      arr[i].onfocus = arr[i].blur;
    }
  }
}

function init() {
  unsetFocusBorder();
  displayNavigationArrow(document.getElementById('_MAP_HOME'),'active');
  setContentPages();
  setMapArea();
  var func = function () {automaticAnimateNavigation1();};
  fadePreloadPage(document.getElementById('preload-page'), 0, func);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////