var perma;
if (document.images)
    {
      img1 = new Image(87,45);
      img1.src="/images/mnu-clean-on.jpg";
      img2 = new Image(146,45);
      img2.src="/images/mnu-corporate-on.jpg";
      img3 = new Image(77,45);
      img3.src="/images/mnu-home-on.jpg";
      img4 = new Image(108,45);
      img4.src="/images/mnu-invest-on.jpg";
      img5 = new Image(70,45);
      img5.src="/images/mnu-projects-on.jpg";
      img6 = new Image(94,45);
      img6.src="/images/mnu-contact-on.jpg";
    }

function di(a){return document.getElementById(a)}
function dv(a){di(a).value=''}
function searchBlur(){if(di('search').value=='')di('search').value="search...";}
function searchFocus(){if(di('search').value=="search...")di('search').value='';}

function dropout(){}

var prevmenu=0;
function showmenu(id)
{
  if(di(id)!=prevmenu&&di(id))
  {
  hidemenu()
  prevmenu=di(id);
  di(id).style.display=''
  }
}
function hidemenu(){
  if(prevmenu)
  {
  prevmenu.style.display='none';
    mnuout(di(prevmenu.id.replace('drop-','')));
  prevmenu=0
  }
  }
function mnuover(img)
{
  if(img.id!=perma && img.src.indexOf('-on.jpg')<0)img.src=img.src.replace('.jpg','-on.jpg');
  if(prevmenu&&prevmenu.id!='drop-'+img.id)hidemenu();
  showmenu('drop-'+img.id);
}
function mnuout(img)
{
if(img.id!=perma && !(di('drop-'+img.id) && di('drop-'+img.id).style.display==''))img.src=img.src.replace('-on.jpg','.jpg');
}

function setPermanent(id)
{
di(id).src=di(id).src.replace('.jpg','-on.jpg');
perma=id;
}

function load(){
var url=document.location.href;

  var refURL=document.referrer;
  if(url.indexOf('/contact')>0)
    setPermanent('mnu-contact');
  else if(url.indexOf('/corporate')>0)
    setPermanent('mnu-corporate');
  else if(url.indexOf('/projects')>0)
    setPermanent('mnu-projects');
  else if(url.indexOf('/clean-coal')>0)
    setPermanent('mnu-clean');
  else if(url.indexOf('/investor')>0 || url.indexOf('/speculator')>0)
    setPermanent('mnu-invest');
  else
    setPermanent('mnu-home');
document.body.onmouseup=function(){hidemenu()}

var navpath=di('navpath'),here="You are here: <a href='/'>Home</a> &gt; ";
if(navpath)
{
  if(url.indexOf('corporate-company-overview.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; Company Profile';
       di('subnav').getElementsByTagName('a')[0].style.background='#DEDEDE'
     }
  else if(url.indexOf('corporate-board.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; Board & Management';
       di('subnav').getElementsByTagName('a')[1].style.background='#DEDEDE'
     }
  else if(url.indexOf('corporate-governance.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; Governance';
       di('subnav').getElementsByTagName('a')[2].style.background='#DEDEDE'
       di('subnav').getElementsByTagName('a')[3].style.display=''
       di('subnav').getElementsByTagName('a')[4].style.display=''
       di('subnav').getElementsByTagName('a')[5].style.display=''
     }
  else if(url.indexOf('corporate-audit-committee.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; <a href="corporate-governance.cfm">Governance</a> &gt; Audit Committee';
       di('subnav').getElementsByTagName('a')[2].style.background='#DEDEDE'
       di('subnav').getElementsByTagName('a')[3].style.display=''
       di('subnav').getElementsByTagName('a')[4].style.display=''
       di('subnav').getElementsByTagName('a')[5].style.display=''
     }
  else if(url.indexOf('corporate-shareholder-communications.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; <a href="corporate-governance.cfm">Governance</a> &gt; Shareholder Communications';
       di('subnav').getElementsByTagName('a')[2].style.background='#DEDEDE'
       di('subnav').getElementsByTagName('a')[3].style.display=''
       di('subnav').getElementsByTagName('a')[4].style.display=''
       di('subnav').getElementsByTagName('a')[5].style.display=''
     }
  else if(url.indexOf('corporate-community-relations.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; <a href="corporate-governance.cfm">Governance</a> &gt; Community Relations';
       di('subnav').getElementsByTagName('a')[2].style.background='#DEDEDE'
       di('subnav').getElementsByTagName('a')[3].style.display=''
       di('subnav').getElementsByTagName('a')[4].style.display=''
       di('subnav').getElementsByTagName('a')[5].style.display=''
     }
  else if(url.indexOf('corporate-environment.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; Environment';
       di('subnav').getElementsByTagName('a')[6].style.background='#DEDEDE'
     }
 else if(url.indexOf('corporate-vision.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; Vision';
       di('subnav').getElementsByTagName('a')[7].style.background='#DEDEDE'
     }
 else if(url.indexOf('contact.cfm')>0)
     {
       navpath.innerHTML=here+'<a href="corporate-company-overview.cfm">Corporate Information</a> &gt; Contact Us';
       di('subnav').getElementsByTagName('a')[8].style.background='#DEDEDE'
     }
 else if(url.indexOf('projects-oaklands')>0)
     {
       navpath.innerHTML=here+'<a href="projects-oaklands.cfm">Projects</a> &gt; Oaklands';
       di('subnav').getElementsByTagName('a')[3].style.display=''
       di('subnav').getElementsByTagName('a')[4].style.display=''
       di('subnav').getElementsByTagName('a')[5].style.display=''

       if(url.indexOf('projects-oaklands-resource')>0)
              di('subnav').getElementsByTagName('a')[3].style.background='#DEDEDE'
       else if(url.indexOf('projects-oaklands-ctl')>0)
              di('subnav').getElementsByTagName('a')[4].style.background='#DEDEDE'
       else  if(url.indexOf('projects-oaklands-bfs')>0)
              di('subnav').getElementsByTagName('a')[5].style.background='#DEDEDE'
       else di('subnav').getElementsByTagName('a')[2].style.background='#DEDEDE'
     }
 else if(url.indexOf('projects-vickery')>0)
 {
      navpath.innerHTML=here+'<a href="projects-oaklands.cfm">Projects</a> &gt; Vickery South';
      di('subnav').getElementsByTagName('a')[0].style.background='#DEDEDE'

 }
 else if(url.indexOf('projects-hodgson')>0)
 {
      navpath.innerHTML=here+'<a href="projects-oaklands.cfm">Projects</a> &gt; Hodgson Vale';
      di('subnav').getElementsByTagName('a')[6].style.background='#DEDEDE'
 }
 else if(url.indexOf('projects-ashford')>0)
 {
      navpath.innerHTML=here+'<a href="projects-oaklands.cfm">Projects</a> &gt; Ashford Lime';
      di('subnav').getElementsByTagName('a')[7].style.background='#DEDEDE'
 }
  else if(url.indexOf('projects-ferndale')>0)
 {
      navpath.innerHTML=here+'<a href="projects-ferndale.cfm">Projects</a> &gt; Ferndale';
      di('subnav').getElementsByTagName('a')[1].style.background='#DEDEDE'
 }
  else if(url.indexOf('investor-asx.cfm')>0 || url.indexOf('speculator')>0)
 {
       navpath.innerHTML=here+'<a href="investor-asx.cfm">Investor Centre</a> &gt; ASX Announcements';
       di('subnav').getElementsByTagName('a')[0].style.background='#DEDEDE'
 }
  else if(url.indexOf('investor-presentation.cfm')>0)
 {
       navpath.innerHTML=here+'<a href="investor-asx.cfm">Investor Centre</a> &gt; Investor Presentations';
       di('subnav').getElementsByTagName('a')[1].style.background='#DEDEDE'
 }
  else if(url.indexOf('investor-media.cfm')>0)
 {
       navpath.innerHTML=here+'<a href="investor-asx.cfm">Investor Centre</a> &gt; Media Coverage';
       di('subnav').getElementsByTagName('a')[2].style.background='#DEDEDE'
 }
  else if(url.indexOf('investor-annual-reports.cfm')>0)
 {
       navpath.innerHTML=here+'<a href="investor-asx.cfm">Investor Centre</a> &gt; Annual Reports';
       di('subnav').getElementsByTagName('a')[3].style.background='#DEDEDE'
 }
  else if(url.indexOf('investor-quarterly-reports.cfm')>0)
 {
       navpath.innerHTML=here+'<a href="investor-asx.cfm">Investor Centre</a> &gt; Quarterly Reports';
       di('subnav').getElementsByTagName('a')[4].style.background='#DEDEDE'
 }
  else if(url.indexOf('privacy.cfm')>0)
 {
       navpath.innerHTML=here+'Privacy and Disclaimer';
       di('subnav').getElementsByTagName('a')[0].style.background='#DEDEDE'
 }

}
  var lbar=0,i,divs=document.getElementsByTagName('div');
  for(i=0;i<divs.length;i++)
  {
    if(divs[i].className=='leftbar')
    { lbar=divs[i] }
    else if(lbar && divs[i].className=='midbar')
    {
    //  lbar.style.height=(divs[i].offsetHeight)+'px'
    //  divs[i].style.height=(divs[i].offsetHeight+16)+'px'
      lbar.id='mylbar'
      divs[i].id='mymbar'
      break;
    }
  }
}

var ROT_COUNT=3,ROT_CUR=1,LOAD_COUNT=0,DONE=0;
function imgload()
{if(DONE)return;
LOAD_COUNT++;
if(LOAD_COUNT>2){DONE=1;setTimeout(rotate,3000)}
}
function rotate()
{
if(ROT_CUR<ROT_COUNT)ROT_CUR++;else ROT_CUR=1;
blendimage('animbg','animimg','/img/bg'+ROT_CUR+'.jpg',500);
}

var divWin=0;divLayer=0;

function hideSubscribe()
{
  divWin.style.display='none';
  divLayer.style.display='none';
}

function showSubscribe()
{
  hidemenu();
  if(!divLayer)
  {
    divLayer=document.createElement('div');
    var st=divLayer.style;
    st.position='absolute';
    st.left='0px'
    st.top='0px';
    st.width='100%';
    st.height='100%';
    st.zIndex=1000;
    st.backgroundColor='black';
    var opacity=50;
    st.opacity = (opacity / 100);
    st.MozOpacity = (opacity / 100);
    st.KhtmlOpacity = (opacity / 100);
    st.filter = "alpha(opacity=" + opacity + ")";
    divWin=document.createElement('div');
    st=divWin.style;
    st.position='absolute';
    st.left=(Math.floor(document.body.offsetWidth/2)-188)+'px'
    st.top='100px';
    st.width='375px';
    st.height='427px';
    st.color='black'
    st.zIndex=10000;
    st.backgroundImage='url("/img/subscribe-bg.jpg")';
    st.backgroundRepeat='no-repeat';
    divWin.innerHTML='<div style="text-align:right;padding-right:13px;padding-top:12px"><span style="font-size:12px;cursor:pointer" onclick="hideSubscribe()">Close</span></div><div style="line-height:17px;text-align:left;padding-left:35px;font-size:13px;font-family:Arial"><strong>CWK Subscription</strong><div style="padding-top:30px;padding-bottom:17px;">If you would like to receive information about<br/>Coalworks\' latest activities, please provide your<br/>email address.</div><div><div><span style="display:inline-block;width:95px">Email address</span><input id="Mail1" style="width:180px;border:0px;background:#D2D2D2"/></div><div style="margin-top:5px"><span style="display:inline-block;width:95px">Confirm email</span><input id="Mail2" style="width:180px;border:0px;background:#D2D2D2"/></div><div style="margin-top:7px;padding-left:95px"><img style="cursor:pointer" src="/img/btn-subscribe.jpg" onclick="javascript:dosubscribe()" /></div><div id="msgSubscribe" style="display:none;color:#990000">Subscription request has been sent.</div><div style="border-top:1px solid #D7B5B5;width:306px;padding-top:20px;padding-bottom:20px"><strong>Unsubscribe</strong></div><div style="padding-bottom:17px;">If you no longer wish to receive updates, please<br/>enter your email below.</div><div><div><span style="display:inline-block;width:95px">Email address</span><input id="Mail3" style="width:180px;border:0px;background:#D2D2D2"/></div><div style="margin-top:7px;padding-left:95px"><img style="cursor:pointer" src="/img/btn-unsubscribe.jpg" onclick="javascript:dounsubscribe()" /></div><div id="msgUnsubscribe" style="display:none;color:#990000">Unsubscription request has been sent.</div></div></div></div>';

    document.body.appendChild(divWin);
    document.body.appendChild(divLayer);
  }
  di('msgUnsubscribe').style.display='none';
  di('msgSubscribe').style.display='none';
  divWin.style.display='';
  divLayer.style.display='';
  di('Mail1').value='';
  di('Mail2').value='';
  di('Mail3').value='';
}
function dosubscribe()
{
  var m1=di('Mail1').value,m2=di('Mail2').value;
  if(m1=='' || m2=='')alert("Please enter the email id to subscribe");
  else if(m1!=m2)alert("The email ids entered do not match");
  else
  {
    di('msgSubscribe').style.display='';
    sendAjaxRequest("addMail="+m1);
  }
}
function dounsubscribe()
{
  var m1=di('Mail3').value;
  if(m1=='')alert("Please enter the email id to unsubscribe");
  else
  {
    di('msgUnsubscribe').style.display='';
    sendAjaxRequest("removeMail="+m1);
  }
}

var xmlHttp;
function sendAjaxRequest(data)
{
  try
  {
   xmlHttp=new XMLHttpRequest();
  }
  catch(e)
  { // indicates Internet Explorer prior to version 7
   try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
       alert("Your browser does not support AJAX!");
       return false;
      }
    }
  }
 xmlHttp.onreadystatechange=function(){var o;};
 xmlHttp.open("GET","subscribe.php?"+data,true);
 xmlHttp.send(null);
}

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100),timer = 0;
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    changeOpac(0, imageid);
    document.getElementById(imageid).src = imagefile;
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
}
function changeOpac(opacity, id) {
	if(opacity==100)setTimeout(rotate,6000);
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
