// 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 SS2011_ = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23);
var AW11website = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);


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 showCollections () {
  hideStockists();
  hideAbout();
  hideCredit();
  document.getElementById('collections').style.display='block';  
}

function hideCollections () {
  document.getElementById('collections').style.display='none';  
}

function showCredit () {
  document.getElementById('credit').style.visibility='visible';  
}

function hideCredit () {
  document.getElementById('credit').style.visibility='hidden';  
}

function showStockists () {
  hideCollections ();
  hideLeft();
  hideRight();
  hideCredit();
  hideAbout ();
  document.getElementById('stockists').style.display='inline';  
  document.getElementById('photos').style.display='none';  
}

function hideStockists () {
  document.getElementById('stockists').style.display='none';  
  document.getElementById('photos').style.display='inline';  
}

function showAbout () {
  hideStockists ();
  hideCollections ();
  hideLeft();
  hideRight();
  hideCredit();
  document.getElementById('abouttext').style.display='inline';  
  document.getElementById('photos').style.display='none';  
}

function hideAbout () {
  document.getElementById('abouttext').style.display='none';  
  document.getElementById('photos').style.display='inline';  
}

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

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

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

function showContact () {
  hideCollections ();
  hideStockists();
  hideLeft();
  hideRight();
  hideCredit();  
  hideAbout ();
  currType = 'none';
  currPhoto = 0;
  blendimage('blenddiv','blendimage','imgs/contact.gif',400);
}

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

function checkArrows(kind) {
  hideCredit();
  if (currPhoto == 1) {
    hideLeft();
  }  
  if (eval(currType).length == currPhoto) {
    hideRight();
    if (kind == 'SS2011_') {
      showCredit();
    }
  }
}

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

function showPhoto (kind, num) {
  hideStockists();
  hideAbout();
  currType = kind;
  currPhoto = num;
  checkArrows(kind);
  var nextPhoto = eval(kind)[num-1];
  if (kind == 'collection2010') {    
    var newUrl = "imgs/collection2010";
  }
  if (kind == 'SS2011_') {
    var newUrl = "imgs/SS2011_";
  }
  if (kind == 'AW11website') {
    var newUrl = "imgs/AW11website";
  }
  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";

