
var bTranState = 1;
var bTranCount = 2;
var TimerId = null;
var VisibleId = "";
var pkSelectedId = "";
var phSelectedId = "";

function findPos(obj) {
  var curleft = 0;
  var curtop = 0;
  var currwidth = obj.offsetWidth;
    if (obj.offsetParent) {
          curleft = obj.offsetLeft
          //curtop = obj.offsetTop
          while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                //curtop += obj.offsetTop
          }
        }
  // return [curleft,curtop];
  // return curleft
  // alert()
  return curleft;
}

function OverMenu(LayerId,Obj) {
  if((VisibleId != "") && (TimerId != null)) {
    if(LayerId != VisibleId) {
      SetVisibility(VisibleId, "hidden")
    }
    clearTimeout(TimerId)
  }
  SetVisibility(LayerId, "visible");
  if(Obj) {
    xPos = findPos(Obj)
    if (document.documentElement) { document.getElementById(LayerId).style.left = xPos + "px" }
    else if (document.all)             { document.all[LayerId].style.left = xPos }
    else if (document.layers)               { document.layer[LayerId].left = xPos }
  }
}

function OutMenu(LayerId) {
  TimerId = window.setTimeout("HideMenu()", 500);
}

function HideMenu() {
  if(VisibleId != "") { SetVisibility(VisibleId, "hidden") }
  if(TimerId != null) { clearTimeout(TimerId) }
}

function SetVisibility(LayerId, Visibility) {
  if (document.layers)               { document.layer[LayerId].visibility = Visibility }
  else if (document.all)             { document.all[LayerId].style.visibility = Visibility }
  else if (document.documentElement) { document.getElementById(LayerId).style.visibility = Visibility }
  if(Visibility == "visible") { VisibleId = LayerId } else { VisibleId = "" }
}

function WriteMail(user,domain,style) {
  address = user + "@" + domain;
  document.write("<a href='mailto:" + address + "' class='" + style + "'>" + address +"</a>");
}

function SelectColour(pkLayerId,phLayerId) {
  if (document.layers)               { document.layer[pkSelectedId].border = '1px solid white' }
  else if (document.all)             { document.all[pkSelectedId].style.border = '1px solid white' }
  else if (document.documentElement) { document.getElementById(pkSelectedId).style.border = '1px solid white' }  
  if (document.layers)               { document.layer[pkLayerId].border = '1px dashed gray' }
  else if (document.all)             { document.all[pkLayerId].style.border = '1px dashed gray' }
  else if (document.documentElement) { document.getElementById(pkLayerId).style.border = '1px dashed gray' }  
  pkSelectedId = pkLayerId;
  if (document.layers)               { document.layer[phSelectedId].visibility = 'hidden' }
  else if (document.all)             { document.all[phSelectedId].style.visibility = 'hidden' }
  else if (document.documentElement) { document.getElementById(phSelectedId).style.visibility = 'hidden' }  
  if (document.layers)               { document.layer[phLayerId].visibility = 'visible' }
  else if (document.all)             { document.all[phLayerId].style.visibility = 'visible' }
  else if (document.documentElement) { document.getElementById(phLayerId).style.visibility = 'visible' }    
  phSelectedId = phLayerId;
}

function fnToggle() {
    clearTimeout(TimerId)
    oTransContainer.filters[0].duration=2;
    oTransContainer.filters[0].overlap=1.0;
    oTransContainer.filters[0].Apply();
    if(bTranState==bTranCount) { bTranState=1 } else { bTranState++ }
    if(bTranState==1) { oTransContainer.style.backgroundImage = "url(/img/main-whales.jpg)" }
    if(bTranState==2) { oTransContainer.style.backgroundImage = "url(/img/main-man.jpg)" }
   	oTransContainer.filters[0].Play();
    TimerId = window.setTimeout("fnToggle()", 15000);
}

function ButtOver(LayerId) {
  if (document.layers)               { document.layer[LayerId].backgroundImage = "url(/img/sbutt-on.jpg)" }
  else if (document.all)             { document.all[LayerId].style.backgroundImage = "url(/img/sbutt-on.jpg)" }
  else if (document.documentElement) { document.getElementById(LayerId).style.backgroundImage = "url(/img/sbutt-on.jpg)" }
}

function ButtOut(LayerId) {
  if (document.layers)               { document.layer[LayerId].backgroundImage = "url(/img/sbutt-off.jpg)" }
  else if (document.all)             { document.all[LayerId].style.backgroundImage = "url(/img/sbutt-off.jpg)" }
  else if (document.documentElement) { document.getElementById(LayerId).style.backgroundImage = "url(/img/sbutt-off.jpg)" }
}

var iTop = 0;
var LayerId = null;

function DivStop() {
  clearTimeout(TimerId);
}

function DivUp(LayerId,Height) {
  if(iTop<=Height) { return }  
  iTop--;
  if (document.layers)               { document.layer[LayerId].top = iTop + 'px' }
  else if (document.all)             { document.all[LayerId].style.top = iTop + 'px' }
  else if (document.documentElement) { document.getElementById(LayerId).style.top = iTop + 'px' }
  TimerId = window.setTimeout("DivUp('" + LayerId + "'," + Height + ")", 5);
}

function DivDown(LayerId) {
  if(iTop == 0) { return }
  iTop++;
  if (document.layers)               { document.layer[LayerId].top = iTop + 'px' }
  else if (document.all)             { document.all[LayerId].style.top = iTop + 'px' }
  else if (document.documentElement) { document.getElementById(LayerId).style.top = iTop + 'px' }
  TimerId = window.setTimeout("DivDown('" + LayerId + "')", 5);
}

function ShowEnlarged(gkod,model) {
  msgWindowWidth = 600 + 30;
  msgWindowHeight = 400 + 30;
  msgWindowLeft = Math.round(screen.width / 2) - Math.round(msgWindowWidth / 2);
  msgWindowTop = Math.round(screen.height / 2) - Math.round(msgWindowHeight / 2) - 40;
  options = "resizable=no,toolbar=no,menubar=no,location=no,personalbar=no,top=" + msgWindowTop + ",left=" + msgWindowLeft + ",height=" + msgWindowHeight + ",width=" + msgWindowWidth + ",status=no,scrollbars=no";
  msgWindow = window.open('/photos/' + gkod + '/big/' + model + '.JPG','model',options);
  msgWindow.focus();
}

function Glossary(code) {
  glsWindowWidth = 700 + 30;
  glsWindowHeight = 500 + 30;
  glsWindowLeft = Math.round(screen.width / 2) - Math.round(glsWindowWidth / 2);
  glsWindowTop = Math.round(screen.height / 2) - Math.round(glsWindowHeight / 2) - 40;
  options = "resizable=no,toolbar=no,menubar=no,location=no,personalbar=no,top=" + glsWindowTop + ",left=" + glsWindowLeft + ",height=" + glsWindowHeight + ",width=" + glsWindowWidth + ",status=no,scrollbars=1";
  glsWindow = window.open('/cgi/glossary.cgi?co=' + code,'glossary',options);
  glsWindow.focus();
}

function FullDescription(id) {
  glsWindowWidth = 700 + 30;
  glsWindowHeight = 500 + 30;
  glsWindowLeft = Math.round(screen.width / 2) - Math.round(glsWindowWidth / 2);
  glsWindowTop = Math.round(screen.height / 2) - Math.round(glsWindowHeight / 2) - 40;
  options = "resizable=no,toolbar=no,menubar=no,location=no,personalbar=no,top=" + glsWindowTop + ",left=" + glsWindowLeft + ",height=" + glsWindowHeight + ",width=" + glsWindowWidth + ",status=no,scrollbars=1";
  glsWindow = window.open('/cgi/fulldescription.cgi?id=' + id,'fulldescription',options);
  glsWindow.focus();
}

