var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
var portloaded = false;
var testing = false;

function PortInit(start){
  PreloadPortfolio();
  portloaded = true;  
  ChangeImg(start);
  }
  
/* preload images */
function PreloadPortfolio(){
if (document.images){
  
  highlight_left = new Image();
  highlight_left.src = "images/port_highlight_left.gif";
  
  highlight_top = new Image();
  highlight_top.src = "images/port_highlight_top.gif";

  normal_left = new Image();
  normal_left.src = "images/port_normal_left.gif";
  
  normal_top = new Image();
  normal_top.src = "images/port_normal_top.gif";

  houses = new Array(6);
  for (var i = 0; i < 6; i++){ houses[i] = new Image(); }
  //pre-load big images
  houses[0].src = "images/portfolio/3809elev.jpg";
  houses[1].src = "images/portfolio/900elev2.jpg";
  houses[2].src = "images/portfolio/905elev.jpg";
  houses[3].src = "images/portfolio/Blantonelev1.jpg";
  houses[4].src = "images/portfolio/Burrowselev1.jpg";
  houses[5].src = "images/portfolio/trevino1_m.jpg";
	}
}

//set variable for link follow
var linkto = 0;

// determines what image loads
function ChangeImg(whichone){
  if (document.images){
    document.images['changer'].src = houses[whichone].src;
    }
  if (testing) { alert("normal-" + linkto); }
  Normal(linkto+1);
  linkto = whichone;
  if (testing) { alert("highlight-" + linkto); }
  Highlight(linkto+1);
  ShowText(whichone);
  }

function Highlight(index){
  //highlight around picture
  if (testing) { alert("highlight-" + index); }
  this_left = 'thumb_left' + (index-1);
  this_right = 'thumb_left' + index;
  this_top = 'thumb_top' + index;
  this_bottom = 'thumb_bottom' + index;
  if (testing) { alert("left " +this_left + ", right " + this_right + ", top " + this_top + ", bottom " + this_bottom); }
  if (document.images){
    document.images[this_left].src = highlight_left.src;
    document.images[this_right].src = highlight_left.src;
    document.images[this_top].src = highlight_top.src;
    document.images[this_bottom].src = highlight_top.src;
    }
  }
  
function Normal(index){
  //turn off highlight on previous picture
  if (testing) { alert("normal-" + index); }
  this_left = 'thumb_left' + (index-1);
  this_right = 'thumb_left' + index;
  this_top = 'thumb_top' + index;
  this_bottom = 'thumb_bottom' + index;
  if (testing) { alert("left " +this_left + ", right " + this_right + ", top " + this_top + ", bottom " + this_bottom); }
  if (document.images){
    document.images[this_left].src = normal_left.src;
    document.images[this_right].src = normal_left.src;
    document.images[this_top].src = normal_top.src;
    document.images[this_bottom].src = normal_top.src;
    }
  }

//functions for going forward and backward thru photos
function MoveBack(){
  if (testing) { alert('moveback'); }
  Normal(linkto+1);
  linkto--;
  if (linkto == -1) { linkto = 5; }
  ChangeImg(linkto);
  Highlight(linkto+1);
  }
  
function MoveNext(){
  if (testing) { alert('movenext'); }
  Normal(linkto+1);
  linkto++;
  if (linkto == 6) { linkto = 0; }
  ChangeImg(linkto);
  Highlight(linkto+1);
  }

//show referenced element
function ShowText(elementId) {
  //set current value
  currentId = elementId;
  
  //hide previous
  for (counter = 0; counter < 6; counter++) { HideText(counter); }
  //if (currentId != previousId && previousId != null){
    //HideText(previousId);
    //}
  //else{
    //HideText(0);
    //}
  
  //show current
  if (ie4 || ie5){
    //menu and background
    eval('document.all.description' + currentId + '.style.visibility = "visible"');
    
    }
  else if (ns4){
    //menu and background
    eval('document.description' + currentId + '.visibility = "show"');
    
    }
  else if (ns6){
    //menu and background
    eval('document.getElementById("description' + currentId + '").style.visibility = "visible"');
    }
  
  //track in order to turn off later
  previousId = currentId;
  }

//hide referenced element
function HideText(elementId){
  //hide current
  if (ie4 || ie5){
    //menu and background
    eval('document.all.description' + elementId + '.style.visibility = "hidden"');
    
    }
  else if (ns4){
    //menu and background
    eval('document.description' + elementId + '.visibility = "hide"');
    
    }
  else if (ns6){
    //menu and background
    eval('document.getElementById("description' + elementId + '").style.visibility = "hidden"');
    }
  }
