// load frameset if not there...
//if (top.name!="CROPfm") top.location.replace("index.html");

var hover = 0;
var dir = "down";
var botimg = 1;
var comind = 1;
var mailind= 1;
var tgbuchind = 1;
var misind = 1;
var pastind = 1;
var emailind = 1;
var hoverit = 1;
var cropcom_ref;
var com_bright = false;

// needed for animation in ns7
var yPos;
var navElement, logoPos;
var logoAnim = 1;

var bottom = new Array();

bottom[1] = new Image();
bottom[1].src = "anim/cropfm_sledge_bottom_0.gif";
bottom[2] = new Image();
bottom[2].src = "anim/cropfm_sledge_bottom_1.gif";
bottom[3] = new Image();
bottom[3].src = "anim/cropfm_sledge_bottom_2.gif";
bottom[4] = new Image();
bottom[4].src = "anim/cropfm_sledge_bottom_3.gif";

var eggmission = new Array();

eggmission[1] = new Image();
eggmission[1].src = "anim/eggmission_1.gif";
eggmission[2] = new Image();
eggmission[2].src = "anim/eggmission_2.gif";
eggmission[3] = new Image();
eggmission[3].src = "anim/eggmission_3.gif";
eggmission[4] = new Image();
eggmission[4].src = "anim/eggmission_4.gif";
eggmission[5] = new Image();
eggmission[5].src = "anim/eggmission_5.gif";
eggmission[6] = new Image();
eggmission[6].src = "anim/dummy.gif";

var com_blink = new Array();
com_blink[1] = new Image();
com_blink[1].src = "anim/but_com_glow_soft.gif";
com_blink[2] = new Image();
com_blink[2].src = "anim/but_com_glow_bright.gif";
com_blink[3] = new Image();
com_blink[3].src = "images/but_com.gif";

var logoPos = new Array();

// ******************* LOGO ********************
function wobbleLogo()
{
  if (logoAnim > logoPos.length)
  {
    logoAnim = 1;
    return;
  }
    
  if ( document.all )
    document.all('egg').style.posLeft = logoPos[logoAnim];
  else
    logoElement.style.left = logoPos[logoAnim] + "px";
    
  logoAnim++;  
  setTimeout("wobbleLogo()",15 + logoAnim*3);
}

// ******************* NAV *********************

function openMail()
{
  var to = "cropfm" + "@" + "mur.at";
  location.href = "mailto:" + to;
}

function init()
{
  navElement = document.getElementById('nav');
  logoElement = document.getElementById('egg');
  logoPos[1] = parseInt(logoElement.style.left) + 1;
  logoPos[2] = parseInt(logoElement.style.left) + 2;
  logoPos[3] = parseInt(logoElement.style.left) + 1;
  logoPos[5] = parseInt(logoElement.style.left);
  logoPos[6] = parseInt(logoElement.style.left) - 1;
  logoPos[7] = parseInt(logoElement.style.left);
  logoPos[8] = parseInt(logoElement.style.left) + 1;
  logoPos[9] = parseInt(logoElement.style.left);
}

function moveNav(y)
{
  if ( document.all )
    document.all('nav').style.posTop += y;
  else
  {
    navElement = document.getElementById('nav');
    yPos = parseInt(navElement.style.top) + y;
    navElement.style.top = yPos + "px";
  }
}

function changeBottom( ind )
{
  if ( document.all )
    document.all('nav_bottom').src = bottom[ ind ].src;
  else
    document.images["nav_bottom"].src = bottom[ ind ].src;
}

function followNav() 
{
  if ( document.all )
    var y_dist = Math.floor(document.body.scrollTop - document.all('nav').style.posTop  + 200);
  else 
    var y_dist = Math.floor(window.pageYOffset - parseInt(navElement.style.top) + 200);

  if ( Math.abs(y_dist) > 30 )
  {
    if ( y_dist < 100 )
    {
      changeBottom( 4 );
    }
    else
    {
      changeBottom( 1 );
    }
    if ( Math.abs(y_dist) > 120 )
    {
      if ( y_dist < 0 )
        moveNav ( -50 );
      else 
        moveNav ( 60 );
    }
    else 
      moveNav( y_dist/10 );
  }
  else
  {
      hoverNav();
  }
}

function hoverNav()
{
  if ( dir == "up" )
  {
    if ( hoverit == 1 )
    {
      moveNav( 1 );
      hover++;
      hoverit = 0;
    }
    else
      hoverit = 1;

    if ( botimg == 3 )
    {
      changeBottom( 2 );
      botimg = 2;
    }
    else
    {
      changeBottom( 3 );
      botimg = 3;
    }
    if ( hover == 2 )
    {
      dir = "down";
      hoverit = 0;
    }
    return;
  }

  if ( dir == "down" )
  {
    if ( hoverit == 1 )
    {
      moveNav( -1 );
      hover--;
      hoverit = 0;
    }
    else
      hoverit = 1

    if ( botimg == 3 )
    {
      changeBottom( 2 );
      botimg = 2;
    }
    else
    {
      changeBottom( 3 );
      botimg = 3;
    }
    if ( hover == -3 )
    {  
      dir = "up";
      hoverit = 0;
    }
  }
}

// ******************* BUTTONS *********************

function blink_cropcom()
{ 
  if ( cropcom_ref == null )
  	cropcom_ref = setInterval("do_blink_cropcom()", 1000);
}    


function eggmitpast()
{
  if ( pastind == 6 )
  {
    if ( document.all )
      document.all("ps_img").src = eggmission[ pastind ].src;
    else
      document.images["ps_img"].src = eggmission[ pastind ].src;

    pastind = 1;
    return;
  }

  if ( document.all )
    document.all("ps_img").src = eggmission[ pastind ].src;
  else
    document.images["ps_img"].src = eggmission[ pastind ].src;

  pastind++;
  setTimeout ( "eggmitpast()", 70 );
}

function eggmitcom()
{
  if ( comind == 6 )
  {
    if ( document.all )
      document.all("com_img").src = eggmission[ comind ].src;
    else
      document.images["com_img"].src = eggmission[ comind ].src;
    comind = 1;
    return;
  }

  if ( document.all )
    document.all("com_img").src = eggmission[ comind ].src;
  else
    document.images["com_img"].src = eggmission[ comind ].src;

  comind++;
  setTimeout ( "eggmitcom()", 70 );
}

function eggmittgbuch()
{
  if ( tgbuchind == 6 )
  {
    if ( document.all )
      document.all("tg_img").src = eggmission[ tgbuchind ].src;
    else
      document.images["tg_img"].src = eggmission[ tgbuchind ].src;

    tgbuchind = 1;
    return;
  }

  if ( document.all )
    document.all("tg_img").src = eggmission[ tgbuchind ].src;
  else
    document.images["tg_img"].src = eggmission[ tgbuchind ].src;

  tgbuchind++;
  setTimeout ( "eggmittgbuch()", 70 );
}

function eggmitemail()
{
  if ( emailind == 6 )
  {
    if ( document.all )
      document.all("e_img").src = eggmission[ emailind ].src;
    else
      document.images["e_img"].src = eggmission[ emailind ].src;

    emailind = 1;
    return;
  }

  if ( document.all )
    document.all("e_img").src = eggmission[ emailind ].src;
  else
    document.images["e_img"].src = eggmission[ emailind ].src;

  emailind++;
  setTimeout ( "eggmitemail()", 70 );
}

function eggmitmis()
{
  if ( misind == 6 )
  {
    if ( document.all )
      document.all("mis_img").src = eggmission[ misind ].src;
    else
      document.images["mis_img"].src = eggmission[ misind ].src;

    misind = 1;
    return;
  }

  if ( document.all )
    document.all("mis_img").src = eggmission[ misind ].src;
  else
    document.images["mis_img"].src = eggmission[ misind ].src;

  misind++;
  setTimeout ( "eggmitmis()", 70 );
}


function unblink_cropcom()
{ 
  if ( cropcom_ref != null )
  {
    clearInterval(cropcom_ref);
    cropcom_ref = null;
  }
  if ( document.images["com_but"] != null )
    document.images["com_but"].src = com_blink[3].src;
}

function do_blink_cropcom()
{
  if ( com_bright == true ) 
  {
    if ( document.images["com_but"] != null )
      document.images["com_but"].src = com_blink[1].src;
    com_bright = false;
  } else {
    if ( document.images["com_but"] != null )
      document.images["com_but"].src = com_blink[2].src;
    com_bright = true;
  }    
}
