/*
 All JavaScript functions, filename is a 2-keyword combination and can be changed if desired.
 (only need to rename file and name a single change in header.php to achieve this)
*/

var scrolling=true;

 // values for the rotating text
 var whiteId =Math.round(2*Math.random());
 var whiteTxt=new Array(
   'Solar Shading can improve the aesthetic appeal of buildings'
  ,'Save on your energy costs and reduce your carbon footprint'
  ,'Reduce glare and heat gain for a healthier working environment'
 );

 function showBenefits() {
  whiteId++; if(whiteId==whiteTxt.length) { whiteId=0; }
  document.getElementById('benefits').innerHTML=whiteTxt[whiteId]+'...';
  setTimeout('showBenefits()', 8000);
 }



 // track the mouse pointer
 var mouseX=0;
 var mouseY=0;
 
 function mouseCoords(e) {
  var posx = 0;
  var posy = 0;
  if (!e) { var e = window.event; }
  if (e.pageX || e.pageY) {
   posx = e.pageX;
   posy = e.pageY;
  } else if (e.clientX || e.clientY) 	{
   posx = e.clientX + document.body.scrollLeft;
   posy = e.clientY + document.body.scrollTop;
  }
  mouseX=posx;
  mouseY=posy;
 }
 
 
 // show the secure area
 function secureShow(showMode) {
  hideOptions();
  var box=document.getElementById('secureOuter');
  var st='none'; if(showMode==1) { st='block'; }
  box.style.display=st;
  if(showMode==1) { 
   box=document.getElementById('secureInner');
   box.innerHTML='<div style="position:relative;"><div class="securePad"><object data="/secure.php" type="text/html" class="secureFrame"></object></div><div class="secureClose" title="Click to Close Window" onclick="secureShow(0);"></div></div>'; 
  }
 }
 

 // pop up a window to show a project
 function show_project( projectId, productId ) {
  var w=window.open('/project.php?id='+projectId+'&pr='+productId, 'project'+projectId, 'width=650,height=500,scrollbars=1');
 }

 // time saver - I'm soooo lazy
 function go2( url ) {
  document.location.href=url;
 }

 // validate an email address
 function isMail(email) {
  return email.search(/^[\.\w_'-]+@[\w_'-]+\.[\w_-]+(\.[\w_-]+)*$/)==-1 ? false : true;
 }
 
 // force links with rel="external" to open in new window
 function extLinks() {
  if(!document.getElementsByTagName) { return; }
  var links=document.getElementsByTagName('a');
  var lnk=''; var rel=''; var ext=/external/;
  for(l=0; l<links.length; l++) {
   lnk=links[l];
   rel=lnk.getAttribute('rel');
   if(ext.test(rel)) { lnk.target='_blank'; }
  }
 }


 // highlight entire table row
 function hlRow( objRow, hlMode ) {
  var tdList=objRow.getElementsByTagName('td');
  var hlColor='transparent'; if(hlMode==1) { hlColor='#eeeeee'; }
  for(td=0; td<tdList.length; td++) {
   tdList[td].style.backgroundColor=hlColor;
  }
 }

 
 // show the product details for the image
 function prodInfo( objImg, hlMode ) {
  var prod=document.getElementsByTagName('div');
  for(p=0; p<(prod.length); p++) {
   if(prod[p].id.substr(0, 4)=='prod') {
    if(prod[p].id.substr(4,1)==objImg.id.substr(4,1)) {
	 prod[p].style.display='block';
	} else {
	 prod[p].style.display='none';
	}
   }
  }
 }

 // returns the X and Y ordinates of a given object
 function findPos(obj) {
  var curleft=0;
  var curtop =0;
  if(obj.offsetParent) {
   curleft=obj.offsetLeft;
   curtop =obj.offsetTop;
   while(obj=obj.offsetParent) {
    curleft+=obj.offsetLeft;
	curtop +=obj.offsetTop;
   }
  }
  return [curleft,curtop];
 } 

 
  // show a menu item based on the mouse going over objTab
 function showOptions( objTab ) {
  var tabId=objTab.id.substr(3,1);
  var tabPos=findPos(objTab);
  var tabOpts=document.getElementById('tabOptions'+tabId);
  hideOptions();
  dx=2; if( tabId==1 ) { dx=4; } // offset because we're now using PNGs
  if(tabOpts) { 
   tabOpts.style.left=(tabPos[0]+dx)+'px'; 
   tabOpts.style.top='260px'; 
   tabOpts.style.visibility='visible'; 
  } 
 }


 // hide all menu and submenu options.
 // Max 10 of each.
 function hideOptions() {
  var tt='';
  for(t=1;t<11;t++) { 
   tt=document.getElementById('tabOptions'+t); 
   if(tt) { 
    tt.style.visibility='hidden'; 
	tt.style.left='0px';
   } 
   tt=document.getElementById('subMenu'+t);
   if(tt) {
    tt.style.visibility='hidden'; 
	tt.style.left='0px';
   }
  }
 }
 

 // Highlight a main menu option
 function hlMenu( menuId, hlMode, tab ) {
  if(menuId!=tab) {
   var mil=document.getElementById('mil'+menuId);
   var mim=document.getElementById('mim'+menuId);
   var mir=document.getElementById('mir'+menuId);
   if(hlMode==0) {
    mil.src='/_gfx/gui/trans.png';
	mim.style.background='transparent';
    mir.src='/_gfx/gui/trans.png';
   } else {
    mil.src='/_gfx/gui/menu-l.png';
	mim.style.backgroundImage="url('/_gfx/gui/menu-m.png')";
	mim.style.backgroundRepeat='repeat-x';
    mir.src='/_gfx/gui/menu-r.png';
   }
  }
 }


 // highlight a menu option with the highlight colour based on its ID
 function hlOption( objItem, hlMode ) {
  var tabId =objItem.id.substr(3,1);
  var itemId=objItem.id.substr(8,1);
  var hlColours=new Array('', '#FFA473', '#90CAC6', '#F37BBA', '#93D8F6');
  if(hlMode==1) {
   objItem.style.backgroundColor=hlColours[tabId];

   if((objItem.id.substr(0,3)=='tab')&&(objItem.id.substr(8,1)!='2')) {
    subMenu( document.getElementById('subMenu'+tabId), tabId, 0 )
   }

  } else {
   objItem.style.backgroundColor='transparent';
  }
 }


 // self-calling slideshow - call it once to start it and it'll continue ad infinitum
 function slideshow( imgName, imgPath, imgNum, imgMax, imgDelay ) {
  document.getElementById(imgName).src=imgPath+imgNum+'.jpg';
  imgNum++; if(imgNum>imgMax) { imgNum=1; }
  setTimeout(" slideshow('"+imgName+"', '"+imgPath+"', "+imgNum+", "+imgMax+", "+imgDelay+") ", imgDelay);
 }
 
 // rewritten because we now have the slides in an array.
 function advanceSlideShow() {
  currentSlide++;
  if(currentSlide==slides.length) { currentSlide=0; }
  var ss=document.getElementById('slideImage');
  ss.src=slides[currentSlide];
  setTimeout('advanceSlide()', 7000);
 }
 
 
 // start the scroll
 function doScroll() {
  var scrollbox=document.getElementById('scrollbox');
  if(scrollbox) { reScroll(400); }
 }
 
 // continue a scroll
 function reScroll(boxPos) {
  var divs=document.getElementsByTagName('div');
  var ypos=0;
  for(d=0; d<divs.length; d++) {
   if(divs[d].className=='scrollHTML') {
    ypos=divs[d].style.top;
	if(!ypos) { ypos=0; } else { ypos=parseInt(ypos); }
    ypos=ypos-1; if(ypos<-175) { ypos=resetPosition; }
	divs[d].style.top=(+ypos+'px');
   }
  }
  
  setTimeout('reScroll('+boxPos+')', 20);
 }
 
 // check the 'Contact Us' form
 function submitContact() {
  var cf=document.getElementById('contactform');
  var de=0;
  if((de==0)&&(cf.name.value.length<4))      { de=1; alert('Please enter your Full Name'); cf.name.focus(); }
  if((de==0)&&(!isMail(cf.email.value)))     { de=2; alert('Please enter a Valid Email Address'); cf.email.focus(); }
  if((de==0)&&(cf.comments.value.length<10)) { de=3; alert('Please enter a More Detailed Comment'); cf.comments.focus(); }
  if(de==0) { cf.submit(); }
 }
 
 // show a sub menu item
 function subMenu( objSrc, menuId, hlMode ) {
  if(hlMode==1) {
   var sm=document.getElementById('subMenu'+menuId);
   var mpos=findPos(objSrc);
   sm.style.left=(mpos[0]+100)+'px';
   sm.style.top =(mpos[1]+2)+'px';
   sm.style.visibility='visible';
  } else {
   if(objSrc) { objSrc.style.visibility='hidden'; }
  }
 }

 function thumbShow(thumbId) {
  var thumb=document.getElementById('thumbfloat');
  thumb.innerHTML='<img src="/files/thumbs/'+thumbId+'.jpg" width="150" height="150" alt=""/>';
  thumb.style.left=(mouseX+16)+'px';
  thumb.style.top =(mouseY-160)+'px';
  thumb.style.visibility='visible';
 }
 
 function thumbHide() {
  var thumb=document.getElementById('thumbfloat');
  thumb.style.visibility='hidden';
 }

 function thumbMove() {
  var thumb=document.getElementById('thumbfloat');
  if(thumb.style.visibility=='visible') {
   thumb.style.left=(mouseX+16)+'px';
   thumb.style.top =(mouseY-160)+'px';
  } else {
   thumb.style.left='0px';
   thumb.style.top ='0px';
  }
  setTimeout('thumbMove()', 30);
 }
