var xmlhttp;
var imageFull = "view entire image";
var imageDetail = "view image detail";

/* General functions */
function display(objId) {
  if (document.getElementById) {
  document.getElementById(objId).style.display = 'inline';
  } else if (document.all) {
    document.all(objId).style.display = 'inline';
  }
}

function hide(objId) {
  if (document.getElementById) {
  document.getElementById(objId).style.display = 'none';
  } else if (document.all) {
    document.all(objId).style.display = 'none';
  }  
}

function writeHtml(objId,str) {
  if (document.getElementById) {
  document.getElementById(objId).innerHTML = str;
  } else if (document.all) {
    document.all(objId).innerHTML = str;
  }     
}

/* Credit Suckerfish for solution to IE6 hover issue */
function sfHover(navContainer) {
  var sfEls = document.getElementById(navContainer).getElementsByTagName('li');
  for (var i=0; i < sfEls.length; i++) {
    sfEls[i].onmouseover = function() {
      this.className += 'sfhover';
		}
    sfEls[i].onmouseout=function() {
      this.className = this.className.replace(new RegExp('sfhover\\b'), '');
    }
  }
}

/* Portfolio Photo Mgr */
function displayImage(imageTitle,filePath,pageLoad) {
  if (!pageLoad) {
    disableSelectedTn();
  }
  /* Hide detail if currently displayed */
  hide('detailImg');
  /* Display full photo */
  if (document.getElementById) {
    var photo = document.getElementById('photoImg');
    /* Fix for Safari image resize bug */
    if (navigator.userAgent.indexOf('Safari') != -1) {
      photo.src = "../images/white-dot.gif";
    }
    photo.src = filePath;
    photo.style.display = 'inline';
  } else if (document.all) {
    document.all('photoImg').src = filePath;
    document.all('photoImg').style.display = 'inline';
  }
  /* Display image title */
  writeHtml('navContainerImageTitle',imageTitle)
  /* Check for existance of detail image */
  var detailFilePath = filePath.replace(/.jpg/,"_detail.jpg");
  detailLoaded = null;
  loadDetail(detailFilePath);
}

function disableSelectedTn() {
  var lists = document.getElementsByTagName('a');
  for (var i = 0; i < lists.length; i++) {
  	if (lists[i].className == 'tnSelected') {
  		lists[i].className = 'tn';
		}
	}
}

/* Portfolio detail view - AJAX */
function getXmlHttpObject() {
  if (window.ActiveXObject) {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    if (!xmlhttp) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  } else if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest;
  }
  return xmlhttp;
}

function loadDetail(filePath) {
  var viewDetail = imageDetail;
  xmlhttp = null;
  xmlhttp = getXmlHttpObject();
  if (xmlhttp) {
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
          if (document.getElementById) {
            document.getElementById('detailImg').src = filePath;          
          } else if (document.all) {
            document.all('detailImg').src = filePath;
          }
        } else {
          viewDetail = "";
        }
        writeHtml('navLinksViewDetail',viewDetail);
      }
    }
    xmlhttp.open("GET",filePath,true);
    xmlhttp.send(null);
  }
}

function displayDetail() {
  if ((document.getElementById && document.getElementById('detailImg').style.display == 'inline') || (document.all && document.all('detailImg').style.display == 'inline')) {
    hide('detailImg');
    display('photoImg');
    writeHtml('navLinksViewDetail',imageDetail);  
  } else {
    hide('photoImg');
    display('detailImg');
    writeHtml('navLinksViewDetail',imageFull);
  } 
}









