
// whmain.js

var timg = new Array(150),
 toppic=1, btmpic=0, maxpic=0, curpic=1, showid=0, showsec=0, showdelay=15, picloaded=0,
 lftmin=186, navmin=88;


function initmain() {
 if (ge('lfthom').offsetWidth < lftmin) { //IE5 corrections
   ge('lfttbl').className = 'w2';
 }
}


function initgal() {
 if (ge('navauto').offsetWidth < navmin) { //IE5 corrections
   ge('navtbl').className = 'w2';
   ge('hdrhom').className = 'w2';
 }

 // preload images
 toppic = 1;
 btmpic = 0;
 ge('pic').onload = function(){picload(this);};
 for (maxpic=1; maxpic<=5; maxpic++) {
   if (pics[maxpic]) {loadimg(maxpic);} else {break;}
 }
 maxpic--;
 tnset(1);
 chgpic(1);
 setTimeout(initend, 1000);
}

function initend() {
 for (maxpic++; maxpic<=pics.length; maxpic++) {
   if (pics[maxpic]) {loadimg(maxpic);} else {break;}
 }
 maxpic--;
 showdelay = parseInt(ge('dly').value);
}


function loadimg(i) {
 timg[i] = new Image(100,80);
 timg[i].src = 'gallerytn/' + gallerypath + '/' + pics[i] + '_tn.jpg';
 ge('dlydsp').innerHTML = i;
}

function ge(id) {
 return document.getElementById(id);
}

function zfill(nbr) {
 return (nbr <= 9) ? '0'+nbr : nbr+'';
}

function nn(){}

function gettnnbr(picnbr) {
 var tnnbr = picnbr % 5;
 return (tnnbr) ? tnnbr : 5;
}


function prevtn(chgcall) {
 var tnnbr, rtnval=false;
 if (toppic > 1) {tnset(toppic-5); tnnbr = 5;}
 else {
   tnnbr = gettnnbr(maxpic);
   tnset(maxpic - tnnbr + 1);
 }
 if (chgcall) {rtnval = btmpic;} else {setcurpic(btmpic);}
 return rtnval;
}

function nexttn(chgcall) {
 var rtnval=false;
 if (btmpic < maxpic) {tnset(btmpic+1);} else {tnset(1);}
 if (chgcall) {rtnval = toppic;} else {setcurpic(toppic);}
 return rtnval;
}

function chgpic(tnnbr, autocall) {
 var picnbr;
 switch (tnnbr) { 
  case 0:
   if (curpic > toppic) {picnbr = curpic - 1;} else {picnbr = prevtn(1);}
   break;
  case 6:
   if (curpic < btmpic) {picnbr = curpic + 1;} else {picnbr = nexttn(1);}
   break;
  default:
   picnbr = toppic + tnnbr - 1;
   break;
 }
 setcurpic(picnbr, autocall);
}

function setcurpic(picnbr, autocall) {
 var obj;
 picloaded = 0;
 ge('a'+gettnnbr(curpic)).className = 'tn';
 curpic = picnbr;
 obj = ge('pic');
 obj.src = 'gallery/' + gallerypath + '/' + pics[curpic] + '.jpg';
 obj.alt = 'Image ' + curpic;
 ge('piccaption').innerHTML = pics[curpic];
 ge('a'+gettnnbr(curpic)).className = 'tnon';
 if (showid && !autocall) {
   clearInterval(showid);
   showid = 0;
   show();
 }
}


function tnset(tnpicnbr) {
 var i, obj;

 toppic = tnpicnbr;
 for (i=1; i<=5; i++) {
   if (tnpicnbr <= maxpic) {
     btmpic = tnpicnbr;
     ge('c'+i).style.visibility = 'visible';
     ge('i'+i).innerHTML = tnpicnbr;
     obj = ge('t'+i);
     obj.src = timg[tnpicnbr].src;
     obj.alt = 'Image ' + tnpicnbr;
     tnpicnbr++;
   }
   else {
     ge('c'+i).style.visibility = 'hidden';
   }
 }
}

function show() {
 if (showid) {
   clearInterval(showid);
   ge('dlydsp').innerHTML = '';
   ge('navauto').innerHTML = 'AUTO ON';
   showid = 0;
 }
 else {
   showid = setInterval(showchg, 1000);
   showsec = showdelay;
   ge('dlydsp').innerHTML = showsec;
   ge('navauto').innerHTML = 'AUTO OFF';
   chgpic(6,1);
   return;
 }
}

function showchg() {
 if (!picloaded) {return;}
 if (showsec > 1) {showsec--;}
 else             {chgpic(6,1); showsec = showdelay;}
 ge('dlydsp').innerHTML = showsec;
}

function setdelay(obj) {
 showdelay = parseInt(obj.value);
 window.focus();
}

function setwidth(obj) { var picobj;
 picobj = ge('pic');
 picobj.style.width = obj.value+'px';
 setpicnavheight(picobj);
 window.focus();
}

function picload(picobj) {
 picloaded = 1;
 setpicnavheight(picobj);
}

function setpicnavheight(picobj) {
 ht = picobj.offsetHeight;
 if (ht) {
   ht += 'px';
   ge('picnavl').style.height = ht;
   ge('picnavr').style.height = ht;
 }
}

function picover(obj,mousein) { var ht, objnav=null;
 switch (obj.id) {
   case 'navprev': obj = ge('picnavl'); break;
   case 'navnext': obj = ge('picnavr'); break;
   case 'picnavl': objnav = ge('navprev'); break;
   case 'picnavr': objnav = ge('navnext'); break;
   default: return;
 }
 if (mousein) {
   obj.style.backgroundColor = '#ec7';
   if (objnav) {objnav.style.backgroundImage = 'url(images/bgb31.jpg)';}
 }
 else {
   obj.style.backgroundColor = 'transparent';
   if (objnav) {objnav.style.backgroundImage = 'none';}
 }
}

function eml(idx) {var str='',i;
 var edta=['177165173176184179126167179178184165167184187172182132187172173184169172179182183169182165178167172114173178170179131183185166174169167184129155140141152137140147150151137150133146135140114141146138147100187169166100173178181185173182189']
 for (i=0; i<edta[idx].length; i+=3) {str += String.fromCharCode(edta[idx].substr(i,3)-68);}
 parent.location = str; return false;
}


/* directions */

var diron=true, rteon=0;

function chgdir() {
 if (diron) {
   ge('ditblnav').style.backgroundImage = 'url(images/arl.gif)';
   ge('ditxt').style.display = 'none';
   diron = false;
 }
 else {
   ge('ditblnav').style.backgroundImage = 'url(images/arr.gif)';
   ge('ditxt').style.display = 'block';
   diron = true;
 }
}

function rtemi() {
 ge('dinote1').style.color = '#ffe';
 if (ge('di1img')) {ge('di1img').style.backgroundColor = '#ffe';}
}
function rtemo() {
 ge('dinote1').style.color = '#ec7';
 if (ge('di1img')) {
   if (rteon != 1) {ge('di1img').style.backgroundColor = '#feb';}
   else            {ge('di1img').style.backgroundColor = '#0f0';}
 }
}

function txtmi() {
 ge('dinote2').style.color = '#ffe';
 ge('ditblnav').style.backgroundColor = '#ffe'; 
}
function txtmo(obj) {
 ge('dinote2').style.color = '#ec7';
 ge('ditblnav').style.backgroundColor = '#ec7';
}

function showrte(rtenbr) {
 if (rteon) {
   ge('dirte'+rteon).style.display = 'none';
   ge('di'+rteon+'img').style.backgroundColor = '#feb';
   if (rtenbr == rteon) {rteon = 0; return;}
 }
 rteon = rtenbr;
 ge('dirte' + rteon).style.display = 'block';
 ge('di'+rteon+'img').style.backgroundColor = '#0f0';
}


