// @@ GLOBAL VARIABLES

var mainDomain="sivatech.co.uk";
var siteName="Sivatech Ltd.";
var postcode="HP19+8DJ";
var styleSheet="css/default.css";
var pagePicHeight=0;
// var aBG="blue", bBG="green", cBG="red";
var cBG0, cBG1;

switch (cBG) {
  case "blue"  : {
    cBG0='#139';
    cBG1='#35A';
    break;
  }
  case "green" : {
    cBG0='#6C1';
    cBG1='#8E3';
    break;
  }
  default : {
    cBG0='#D30';
    cBG1='#F52';
  }
}
document.write('<style type="text/css">');
document.write('#navi li a, #navi ul li a, .trig, .menuInactive { background-color: '+cBG0+' ! important; }');
document.write('#navi li a:hover, #navi ul li a:hover, .menuHover { background-color: '+cBG1+' ! important; }');
document.write('</style>');

window.onload = function() {
  new xMenu1('tr1','sm1',1,'mouseover');
  new xMenu1('tr2','sm2',1,'mouseover');
  new xMenu1('tr21','sm21',1,'mouseover');
  new xMenu1('tr211','sm211',1,'mouseover');
  new xMenu1('tr22','sm22',1,'mouseover');
  new xMenu1('tr221','sm221',1,'mouseover');
  new xMenu1('tr23','sm23',1,'mouseover');
  new xMenu1('tr231','sm231',1,'mouseover');
  new xMenu1('tr3','sm3',1,'mouseover');
  new xMenu1('tr4','sm4',1,'mouseover');
  bgOrder(aBG,bBG);
  pagePicHeight = xHeight('pagePic');
  winOnResize(); // set initial position
  fadeIn('left',1,20);
  setTimeout("fadeIn('pagePic',4,40);",700);
  xAddEventListener(window, 'resize', winOnResize, false);
}

function winOnResize() {
  xHeight('content',xClientHeight()-xHeight('header')-xHeight('footer'));
  xGetElementById('left').style.marginBottom=xHeight('footer')+'px';
//  xGetElementById('pagePic').style.marginBottom=(pagePicMargin+xHeight('footer')+xHeight('left'))+'px';
  xTop('pagePic',xClientHeight()-xHeight('footer')-xHeight('slogan')-pagePicHeight);
  xHeight('pagePic',pagePicHeight);
}

function bgOrder(a,b) {
  xGetElementById('left').className=a;
  xBackground('content','transparent','images/bg_'+b+'.png');
}

/* xMenu1 Object Prototype

  Parameters:
    triggerId   - id string of trigger element.
    menuId      - id string of menu.
    mouseMargin - integer margin around menu;
                  when mouse is outside this margin the menu is hid.
    openEvent   - string name of event on which to open menu ('click', 'mouseover', etc).
*/

function xMenu1(triggerId, menuId, mouseMargin, openEvent)
{
  var isOpen = false;
  var stayOpen = false;
  var trg = xGetElementById(triggerId);
  var mnu = xGetElementById(menuId);
  var chdArr = new Array;
  if (trg && mnu) {
    xAddEventListener(trg, openEvent, onOpen, false);
  }
  function onOpen()
  {
    if (!isOpen) {
      xMoveTo(mnu, xOffsetLeft(trg)+173, xOffsetTop(trg)-1);
      trg.className='trig menuHover';
      xShow(mnu);
//      xWidth('navi', xWidth('navi')+xWidth(mnu));
      xAddEventListener(document, 'mousemove', onMousemove, false);
      for (chdArr[0]=xFirstChild(xFirstChild(mnu)),i=0; nextItem=xFirstChild(xNextSib(xParent(chdArr[i],true))); i++) {
        chdArr[i+1]=nextItem;
      }
      isOpen = true;
    }
  }
  function onMousemove(ev)
  {
    var e = new xEvent(ev);
      for (i=0; chdArr[i]; i++) {
        if (xVisibility(chdArr[i])=='visible') {
          stayOpen=true;
          break;
        }
      }
    if (!stayOpen) {
      if (!xHasPoint(mnu, e.pageX, e.pageY, -mouseMargin) &&
          !xHasPoint(trg, e.pageX, e.pageY, -mouseMargin))
      {
        trg.className='trig menuInactive';
        xHide(mnu);
//        xWidth('navi', 'auto');
        xRemoveEventListener(document, 'mousemove', onMousemove, false);
        isOpen = false;
      }
    }
    stayOpen=false;
  }
} // end xMenu1

function fadeIn(obj,dur,steps) {
  xHide(obj);
  if (xIE4Up) {
    xGetElementById(obj).style.filter="blendTrans(duration="+dur+")";
    xGetElementById(obj).filters.blendTrans.Apply();
    xShow(obj);
  } else {
    xGetElementById(obj).style.opacity=0;
    xShow(obj);
    for (i=1,opa=0; (opa=(1/steps)*i)<=1; i++) setTimeout("xGetElementById('"+obj+"').style.opacity='"+opa+"';",Math.round(opa*(dur*1000)));
  }
  if (xIE4Up) xGetElementById(obj).filters.blendTrans.Play();
}

function fadeOut(obj,dur,steps) {
  xShow(obj);
  if (xIE4Up) {
    xGetElementById(obj).style.filter="blendTrans(duration="+dur+")";
    xGetElementById(obj).filters.blendTrans.Apply();
    xHide(obj);
  } else {
    for (i=1,opa=0; (opa=(1/steps)*i)<=1; i++) setTimeout("xGetElementById('"+obj+"').style.opacity='"+(1-opa)+"';",Math.round(opa*(dur*1000)));
    setTimeout("xHide('t"+thisTruck+"')",dur*1000);
  }
  if (xIE4Up) xGetElementById(obj).filters.blendTrans.Play();
}

// @@@@@ generating a spam-safe e-mail address @@@@@

function drawEmail(alias,text,dn,title) {
  var at = '&#064;'; // at symbol encoded
  var p1 = '&#109;&#097;&#105;&#108;'; // protocol name encoded part 1
  var p2 = '&#116;&#111;&#58;'; // protocol name encoded part 2
  if (!dn) dn=mainDomain;
  if (title) title=' title="'+title+'"'
    else title='';
  if (!text) text=alias+at+dn;
  document.write('<a href="'+p1+p2+alias+at+dn+'"'+title+'>'+text+'</a>');
}

// @@@@@ popup window to Image size and wrap in HTML @@@@@

function popupImg(img,addH,addW,caption) {
  var w = ((addW) ? addW : 0);
  var h = ((addH) ? addH : 0);
  var c = ((caption) ? ('<p align="center">' + caption + '</p>') : '');
  remoteWin = window.open("","photo","resizable=1,width=200,height=200,status=1,scrollbars="+(((h<0)||(w<0)) ? "1" : "0"));
  with (remoteWin.document) {
    open('text/html', 'replace');
    write('<html><head><meta http-equiv="imagetoolbar" content="no"><title>'+siteName+'</title><link rel="stylesheet" type="text/css" href="http://www.'+mainDomain+'/'+styleSheet+'"></head><body style="margin:20px;font-size:11px;" onload="resizeTo(document.popupImg.width+60+'+w+',document.popupImg.height+190+'+h+'); window.focus()"><p align="center"><img border="0" src="' + img + '" name="popupImg"></p>' + c + '<p align="center">[<a href="javascript:window.close()">close window</a>]</p></body></html>');
    close();
  }
}
