var mitems=['index','about','process','invest','media','contact']
var pageIndex;
function rsize(){
  if(di('nhs'))
  {        
    if(document.documentElement.clientHeight<550)
        di('footer').style.position='relative'
    else di('footer').style.position='absolute'
  }
}
function di(a){return document.getElementById(a)}
function mnuOver(item){
 var num=parseInt(item.id.substring(4));
 if(di('itemspan'+(num-1)))di('itemspan'+(num-1)).style.visibility='hidden'
 if(di('itemspan'+(num)))di('itemspan'+(num)).style.visibility='hidden'
 if(num==1)ddMenu('one',1);
 if(num==2)ddMenu('two',1);
 if(num==3)ddMenu('three',1);
}
function mnuOut(item){
 var num=parseInt(item.id.substring(4));
 if(num==1)ddMenu('one',-1);
 if(num==2)ddMenu('two',-1);
 if(num==3)ddMenu('three',-1);
 if(num!=pageIndex&&num+1!=pageIndex&&di('itemspan'+(num)))di('itemspan'+(num)).style.visibility='visible'
 if(num-1!=pageIndex-1&&num-1!=pageIndex&&di('itemspan'+(num-1)))di('itemspan'+(num-1)).style.visibility='visible'
 }
function nload()
{
    var i;pageIndex=0;
    for(i=0;i<mitems.length;i++)if(document.location.href.indexOf(mitems[i])>0){pageIndex=i;break;}
    di('item'+pageIndex).style.backgroundColor='#B61515';
    if(di('itemspan'+pageIndex))di('itemspan'+pageIndex).style.visibility='hidden';
    if(di('itemspan'+(pageIndex-1)))di('itemspan'+(pageIndex-1)).style.visibility='hidden';

    var navgat=navigator.userAgent.toLowerCase();
    if(navgat.indexOf("safari")>=0 && navgat.indexOf("chrome")<0)
    {
      di('drop1').style.right='363px'
      di('drop2').style.right='285px'
      di('drop3').style.right='137px'
      if(di('img-arrow-left'))di('img-arrow-left').style.left='780px'
      if(di('img-arrow-right'))di('img-arrow-right').style.left='805px'

      di('shl1').style.right='290px';
      di('shl1').style.height='122px';
      di('shr1').style.right='292px';
      di('shr1').style.width='218px';
      di('shr1').style.top='218px';

      di('shl2').style.right='212px';
      di('shl2').style.height='94px';
      di('shr2').style.right='215px';
      di('shr2').style.width='218px';
      di('shr2').style.top='188px';

      di('shl3').style.right='64px';
      di('shl3').style.height='184px';
      di('shr3').style.right='68px';
      di('shr3').style.width='216px';
      di('shr3').style.top='328px';
    }
    else
    {
      di('drop1').style.right='365px'
      di('drop2').style.right='290px'
      di('drop3').style.right='148px'

      di('shl1').style.right='292px';
      di('shl1').style.height='120px';
      di('shr1').style.right='296px';
      di('shr1').style.width='216px';
      di('shr1').style.top='214px';

      di('shl2').style.right='217px';
      di('shl2').style.height='91px';
      di('shr2').style.right='220px';
      di('shr2').style.width='218px';
      di('shr2').style.top='185px';

      di('shl3').style.right='75px';
      di('shl3').style.height='178px';
      di('shr3').style.right='78px';
      di('shr3').style.width='218px';
      di('shr3').style.top='330px';
    }

    if(di('mainbar') && di('leftsidebar')&&(di('subbase').offsetWidth-di('leftsidebar').offsetWidth-80)>0)di('mainbar').style.width=(di('subbase').offsetWidth-di('leftsidebar').offsetWidth-80)+'px';

    if(di('mainbar'))di('subbase').style.height=(di('mainbar').offsetHeight+3)+'px';
    if(navigator.userAgent.toLowerCase().indexOf('safari')>=0 && navigator.userAgent.toLowerCase().indexOf('macintosh')>=0)
    {
      di('sbp').style.paddingRight='7px'
//        di('subbase').style.width=di('img-home')?'877px':'820px';
  //      di('sbp').style.width=di('img-home')?'877px':'820px';
    }
    var url=document.location.href;
    if(url.indexOf('media.php')>=0 )
     {di('mainbar').style.paddingLeft='70px';di('mainbar').style.paddingRight='15px';}
    if(url.indexOf('invest-prices.php')>=0 )
    {
      di('subbase').style.width='991px'
      di('sbp').style.width='998px'
      di('sbp').style.paddingRight='0px'
      di('sbq').style.width='998px'
      di('sbr').style.width='991px'
      if(di('mainbar'))di('mainbar').style.width=(di('subbase').offsetWidth-di('leftsidebar').offsetWidth-60)+'px';

    }
    if(url.indexOf('invest-unit-price.php')>=0 || url.indexOf('invest-performance.php')>=0 )
    {
      di('subbase').style.width='891px'
      di('sbp').style.width='898px'
      di('sbp').style.paddingRight='0px'
      di('sbq').style.width='898px'
      di('sbr').style.width='891px'
      if(di('mainbar'))di('mainbar').style.width=(di('subbase').offsetWidth-di('leftsidebar').offsetWidth-60)+'px';

    }

    //di('subbase').style.width=(di('mainbar').offsetLeft+di('mainbar').offsetWidth+30)+'px'
    //var clientHeight=document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight
    //if(di('subbase').offsetHeight+di('menu').offsetHeight+di('footer').offsetHeight<(clientHeight)){di('footer').style.position='absolute';di('footer').style.bottom='0px'}
    if((di('mainbar')&&di('mainbar').offsetHeight<400)||di('nhs'))//|| (screen && screen.width>1400 && di('mainbar').offsetHeight<(screen.height-225))
    {
      di('footer').style.position='absolute'
      di('footer').style.left='0px'
      di('footer').style.bottom='0px'
      if(di('nhs'))di('footer').style.paddingTop='0px';
    }
    if(document.location.href.indexOf('contact.php')>=0&&document.body.scrollHeight<di('mainbar').offsetHeight+225)
    {
      di('footer').style.position='relative'
    }

    setTimeout(rsize,100)

    if(di('footer'))di('footer').style.display=''
    if(di('home-strip'))di('home-strip').style.width=(document.body.offsetWidth-820)+'px'
    if(di('img-home'))di('img-home').style.backgroundImage='url("images/home1.png")'

    //preload homepage images
    /*var oImage3 = new Image();
    oImage3.src='images/home3.png';
    var oImage2 = new Image();
    oImage2.src='images/home2.png';
    if(di('img-home'))setTimeout(startMove,1000);*/
}
var maxHomeIndex=3,currentHomeIndex=1;moveDirection=1;moveLeft=0;
function goNext(back){
moveDirection=back;
//setTimeout(moveImage,10);
//di('img-home').childNodes[0].src='images/home'+(++currentHomeIndex)+'.png';
}

function startMove(){
  setTimeout(moveImage,10);
}
function sendcontact()
{

}
function moveImage()
{
  if(moveDirection==-1)moveLeft=moveLeft-8;else moveLeft=moveLeft+8;
  di('img-home').style.backgroundPosition=moveLeft+"px 0px";
  if(moveLeft>di('img-home').offsetWidth)
  {
    if(currentHomeIndex>=maxHomeIndex)currentHomeIndex=1;else currentHomeIndex++;
    di('img-home').style.backgroundImage='url("images/home'+currentHomeIndex+'.png")'
    moveLeft=-moveLeft
  }
  else if(moveLeft<-di('img-home').offsetWidth)
  {
    if(currentHomeIndex<=1)currentHomeIndex=maxHomeIndex;else currentHomeIndex--;
    di('img-home').style.backgroundImage='url("images/home'+currentHomeIndex+'.png")'
    moveLeft=-moveLeft
  }
  if(moveLeft)
  setTimeout(moveImage,10);
  else setTimeout(startMove,4000);
}

function moveImageNew()
{
  if(moveDirection==-1)moveLeft=moveLeft-5;else moveLeft=moveLeft+5;

  di('img-home').style.opacity = moveLeft / 100;
  di('img-home').style.filter = 'alpha(opacity=' + (moveLeft) + ')';

  if(moveLeft>=100)
  {
    moveLeft=100;
    //if(currentHomeIndex>=maxHomeIndex)currentHomeIndex=1;else currentHomeIndex++;
    //di('img-home').style.backgroundImage='url("images/home'+currentHomeIndex+'.png")'
    moveDirection=-1;
  }
  else if(moveLeft<=0)
  {
    moveLeft=0;
    if(currentHomeIndex<=1)currentHomeIndex=maxHomeIndex;else currentHomeIndex--;
    di('img-home').style.backgroundImage='url("images/home'+currentHomeIndex+'.png")'
    moveDirection=1;
  }
  if(moveLeft!=100)
  setTimeout(moveImage,10);
  else
  {
    di('img-home').style.removeAttribute("filter");
    setTimeout(startMove,4000);
  }
}

/************DROP DOWN *********/
var DDSPEED = navigator.userAgent.indexOf("MSIE")>0?2:10;
var DDTIMER = DDSPEED==2?3:15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}
function omvr(id,indx)
{
  var divs=di(id).getElementsByTagName('div');
  if(divs[indx])divs[indx].style.display='none'
  if(divs[indx-1])divs[indx-1].style.display='none'
}
function omut(id,indx)
{
  var divs=di(id).getElementsByTagName('div');
  if(divs[indx])divs[indx].style.display=''
  if(divs[indx-1])divs[indx-1].style.display=''
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  var old=c.style.height;
  c.style.height = currh + (dist * d) + 'px';
  if(old==c.style.height)currh=d==1?c.maxh-1:1;
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  
  var s=1;
  if(c.id.indexOf('two')==0)s=2;else if(c.id.indexOf('three')==0)s=3;
  if(d==-1)di('shl'+s).style.display=di('shr'+s).style.display='none';
  if(!document.all)
  {di('shl'+s).style.display=di('shr'+s).style.display=d==1?'':'none';}

  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
    if(d==1)di('shl'+s).style.display=di('shr'+s).style.display='';    
    if(DDSPEED==2)
    {
    c.style.removeAttribute('opacity')
    c.style.removeAttribute('filter')
    c.removeAttribute('maxh')
    if(currh<2)c.style.removeAttribute('display')
    }
  }
}