// Node Functions



//--------------------these numbers are the order of the photos -------------
var collection2010 = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22);




var currType = '';
var currPhoto = 1;
var imageObj = new Image();

function showLeft () {
  document.getElementById('leftArrow').style.visibility='visible';  
}

function hideLeft () {
  document.getElementById('leftArrow').style.visibility='hidden';  
}

function showRight () {
  document.getElementById('rightArrow').style.visibility='visible';  
}

function hideRight () {
  document.getElementById('rightArrow').style.visibility='hidden';  
}

function hideLoader () {
  document.getElementById('loadingThing').style.visibility='hidden';  
}

function showLoader () {
  document.getElementById('loadingThing').style.visibility='visible';  
}

function advancePhoto () {
  if (currPhoto < eval(currType).length) {
    currPhoto++;
    showPhoto(currType, currPhoto);
  }  
}

function backPhoto () {
  if (currPhoto > 1) {
    currPhoto--;
    showPhoto(currType, currPhoto);
  }
}

function showBio () {
  hideLeft();
  hideRight();
  currType = 'none';
  currPhoto = 0;
  blendimage('blenddiv','blendimage','photos/bio.jpg',400);
}

function showContact () {
  hideLeft();
  hideRight();
  currType = 'none';
  currPhoto = 0;
  blendimage('blenddiv','blendimage','photos/contacts.jpg',400);
}

function goHome () {
  hideLeft();
  hideRight();
  currType = 'none';
  currPhoto = 0;
  blendimage('blenddiv','blendimage','imgs/first.jpg',400);
}

function checkArrows() {
  if (currPhoto == 1) {
    hideLeft();
  }  
  if (eval(currType).length == currPhoto) {
    hideRight();
  }
}

function checkLoaded (theImage) {
  if (!theImage.complete) {
    var t=setTimeout("checkLoaded(theImage)",500);
  }
}

function showPhoto (kind, num) {
  currType = kind;
  currPhoto = num;
  checkArrows();
  var nextPhoto = eval(kind)[num-1];
  if (kind == 'collection2010') {    
    var newUrl = "imgs/collection2010";
  }
  if (currPhoto < eval(currType).length) {
    var tempImg = new Image();
    tempImg.src = newUrl + eval(kind)[num] + ".jpg";
  }
  var currImage = new Image();
  newUrl += nextPhoto + ".jpg";
  currImage.src = newUrl;
 // if (!currImage.complete) {
   // showLoader();
   // window.setTimeout(function(){showPhoto(kind,num)},500);
 // } else {
   // hideLoader();
    blendimage('blenddiv','blendimage', newUrl,400);
  //}
} 

//change the opacity for different browsers
function changeOpac(opacity, id) {
  var object = document.getElementById(id).style;
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec) {
  var speed = Math.round(millisec / 200);
  var timer = 0;

  //set the current image as background
  document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

  //make image transparent
  changeOpac(0, imageid);

  //make new image
  document.getElementById(imageid).src = imagefile;

  //fade in image
  for(i = 0; i <= 100; i++) {
    setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
    timer++;
  }
}  


imageObj.src = "imgs/collection2010" + collection2010[0] + ".jpg";
//imageObj.src = "photos/bio.jpg";
//imageObj.src = "photos/contacts.jpg";
