if (document.images)
{
  fading = false;
  timeoutid=1;
  curphoto="img/white_area.png"; //starting photo
  curWorkArray = btbArray;
  curThumbArray = btbThumbArray;
  curTitleArray = btbTitleArray;
  curCreditArray = logoCreditArray;
  curInfoArray = btbInfoArray;
  curWorkType = "btb";
  curLogo = 0;
  counter = 0;
  //time = setInterval('forward()', 1000);
  timercheckloaded = null;
  imagePreload=new Array();
  logoFirst = true;
  btbFirst = true;
  packFirst = true;
  brochFirst = true;
  vidalFirst = true;
  bossFirst = true;
  oilFirst = true;
  illusFirst = true;
  printFirst = true;
  artFirst = true;
  workon=false;

  preloadtotal = 0;
  preloadcounter = 0;

  mac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1) ? true: false;
  ie = false;
  if(document.all)
    ie = true;
}

function stopMyTimer() // runs through frames 1 to 5
{
  //clearTimeout(time);
  pt=document.getElementById('progcontainer');
  pt.style.display='none';
}

function startTimer()
{
  pt=document.getElementById('progcontainer');
  pt.style.display='';
  //time = setInterval('forward()', 1000);
}

/*
 function forward()
 {
   counter = counter % 8;
   image=document.getElementById('progImg');
   if(image!=null)
   {
       image.src=progressArray[counter];
       counter++;
   }
 }
*/
 /*
 function preloadArray(arr)
 {
   //imageObj = new Image();
   var count = 0;
   var i=0;

   for(i=0; i<arr.length; i++)
   {
     imagePreload[count]=new Image();
     imagePreload[count].src=arr[i];
     count++;
   } 
 }
  */
//preload mainpage images and thumbnails
function preloader()
{
  //imageObj = new Image();
  //var count = 0;

  //startTimer();
  //preloadArray(progressArray);
  //preloadArray(logoThumbArray);
  //preloadArray(packThumbArray);
  //preloadArray(brochThumbArray);
  //preloadArray(illusThumbArray);
  //preloadArray(printThumbArray);

  //showAboutMe();

  //checkLoaded();
}
/*
function preloadSection(arr,first)
{
  stopMyTimer();
  clearTimeout(timercheckloaded);
  startTimer();
  preloadArray(arr);
  checkLoaded(first);
  first=false;
  return first;
}

function checkLoaded(first)
{
  var loaded = true;
  var i=0;
  var image;

  for(i=0;i<curWorkArray.length;i++)
  //for(i=0; i<imagePreload.length; i++)
  {
    if(imagePreload[i].complete)
    {
      if(first)
      {
	var imageid='thumb'+i;
	image=document.getElementById(imageid);
	image.style.visibility='visible';

	//var s = document.getElementById('box'+i);
	//s.style.display ='';
      }
    }
    else
      loaded = false;
  }

  if(loaded == false)
  {
    if (first)
      timercheckloaded = setTimeout('checkLoaded(true)',20);
    else
      timercheckloaded = setTimeout('checkLoaded(false)',20);
  }
  else
  {
    stopMyTimer();
  }
}
*/
function changeInfo(index)
{
  var titlediv = document.getElementById("ititle");
  //var creditdiv = document.getElementById("icredit");
  var infodiv = document.getElementById("itext");

  titlediv.innerHTML = "";
  infodiv.innerHTML = "";
  titlediv.innerHTML = curTitleArray[index];
  //creditdiv.innerHTML = curCreditArray[index];
  infodiv.innerHTML = curInfoArray[index];
}


function handleOver(index) 
{ 
	
  var image=document.getElementById('thephoto');
  var newimage=document.getElementById('thenewphoto');

  if(fading)
  {	
    setOpacity(image, 0);
    window.clearTimeout(timeoutid);
  }

  image.style.zIndex=1;    // place the current image on top
  newimage.style.zIndex=0; // place new image in the back

  image.src=curphoto;
  curphoto=curWorkArray[index];
  
  if (document.images)
    newimage.src=curWorkArray[index];
  
 
  if(mac && ie)
    image.src=curWorkArray[index];
  else
    fadeOutImage();

  changeInfo(index);
  
}

function fadeOutImage() 
{
  var imageid='thephoto';
  var image=document.getElementById(imageid);
  setOpacity(image, 100);
  fadeOut(imageid,100);
}

function fadeOut(objId,opacity,pathname)
{
  if (document.getElementById)
  {
    var obj=document.getElementById(objId);
    if (opacity>=0)
    {
      fading = true;
      setOpacity(obj, opacity);
      opacity-=5;
      //opacity-=100;
      timeoutid=window.setTimeout("fadeOut('"+objId+"',"+opacity+")",1);
    }
    else
    {
      fading = false;
    }
  }
}

function fadeInImage() 
{
  var imageId='thephoto';
  var image=document.getElementById(imageId);
  setOpacity(image,0);
  image.style.visibility="visible";
  fadeIn(imageId,0);
}

function fadeIn(objId,opacity) 
{
  if (document.getElementById) 
  {
    var obj=document.getElementById(objId);
    if (opacity<=100) 
    {
      setOpacity(obj,opacity);
      opacity+=10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")",100);
    }
  }
}


function setOpacity(obj, opacity) 
{
  opacity=(opacity==100)?99.999:opacity;
  // IE/Win
  obj.style.filter="alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity=opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity=opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity=opacity/100;
}

// work switch
function setWorkingArray(worktype, over)
{
  if(over == undefined)
    over = 0;
	
  changeClass(worktype, "clicked");
  
  if(worktype == "aboutme")
    showAboutMe();
  else if(worktype == "philosophy")
    showPhilosophy();
  else if(worktype == "work")
    showWork();
  else if(worktype == "contact")
    showContact();
  else
    showWorkSection(worktype, over);
}

function showAboutMe()
{
  var image=document.getElementById('thenewphoto');
  image.src='img/aboutMe.jpg';

  image=document.getElementById('thephoto');
  image.src='img/aboutMe.jpg';

  var photoC=document.getElementById('photocontainer');
  photoC.src='img/aboutMe.jpg';
  //photoC.style.overflowX='hidden';
  //photoC.style.overflowY='scroll';

  hideWork();
}

function showPhilosophy()
{
  var image=document.getElementById('thenewphoto');
  image.src='img/philosophy.jpg';

  image=document.getElementById('thephoto');
  image.src='img/philosophy.jpg';

  var photoC=document.getElementById('photocontainer');
  photoC.src='img/philosophy.jpg';
  //photoC.style.overflowX='hidden';
  //photoC.style.overflowY='hidden';
  hideWork();
}

function showWork()
{
  var image=document.getElementById('thenewphoto');
  image.src='img/white_area.png';
  image=document.getElementById('thephoto');
  image.src='img/white_area.png';
  
  //photoC=document.getElementById('photocontainer');
  //photoC.style.overflowX='hidden';
  //photoC.style.overflowY='hidden';

  if(!ie)
  {
    photoC=document.getElementById('photocontainer');
    photoC.style.width = '675px';
    photoC.style.height = '450px';
  }


  var wd=document.getElementById('workdiv');
  wd.style.display='';
  workon=true;

  var footer=document.getElementById('footer');
  footer.style.borderTop = '0px';
}

function hideWork()
{
  var wd=document.getElementById('workdiv');
  wd.style.display='none';

  var pdfC = document.getElementById('pdfcontainer');
  pdfC.style.display='none';
  workon=false;

  hideAllThumbs();
}

function showContact()
{
  var image=document.getElementById('thenewphoto');
  image.src='img/contact.jpg';
  
  image=document.getElementById('thephoto');
  image.src='img/contact.jpg';

  //photoC=document.getElementById('photocontainer');
  //photoC.style.overflowX='hidden';
  //photoC.style.overflowY='hidden';

  hideWork();
}



function showWorkSection(worktype, over)
{
  //if (worktype != curWorkType)
  {
    hideAllThumbs();
  
    if(worktype == "logos")
    {
      curWorkArray = logoArray;
      curThumbArray = logoThumbArray;
      curTitleArray = logoTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = logoInfoArray;

      handleOver(over);
      handleWorkSwitch(logoFirst);
      if (logoFirst)
        //logoFirst = preloadSection(logoArray,logoFirst);
	preloadSection(logoArray,logoFirst);
    }
    else if(worktype == "btb")
    {
      curWorkArray = btbArray;
      curThumbArray = btbThumbArray;
      curTitleArray = btbTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = btbInfoArray;
      handleOver(over);
      handleWorkSwitch(btbFirst);
      if (btbFirst)
	//btbFirst = preloadSection(btbArray,btbFirst);
	preloadSection(btbArray,btbFirst);
    }
    else if(worktype == "packaging")
    {
      curWorkArray = packArray;
      curThumbArray = packThumbArray;
      curTitleArray = packTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = packInfoArray;
      handleOver(over);
      handleWorkSwitch(packFirst);
      if (packFirst)
        //packFirst = preloadSection(packArray,brochFirst);
	preloadSection(packArray,brochFirst);
    }
    else if(worktype == "brochure")
    {
      curWorkArray = brochArray;
      curThumbArray = brochThumbArray;
      curTitleArray = brochTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = brochInfoArray;
      handleOver(over);
      handleWorkSwitch(brochFirst);
      if (brochFirst)
	//brochFirst = preloadSection(brochArray,brochFirst);
	preloadSection(brochArray,brochFirst);
    }
    else if(worktype == "vidal")
    {
      curWorkArray = vidalArray;
      curThumbArray = vidalThumbArray;
      curTitleArray = vidalTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = vidalInfoArray;
      handleOver(over);
      handleWorkSwitch(vidalFirst);
      if (vidalFirst)
	//vidalFirst = preloadSection(vidalArray,vidalFirst);
	preloadSection(vidalArray,vidalFirst);
    }
    else if(worktype == "boss")
    {
      curWorkArray = bossArray;
      curThumbArray = bossThumbArray;
      curTitleArray = bossTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = bossInfoArray;
      handleOver(over);
      handleWorkSwitch(bossFirst);
      if (bossFirst)
	//bossFirst = preloadSection(bossArray,bossFirst);
	preloadSection(bossArray,bossFirst);
    }
    else if(worktype == "illustrations")
    {
      curWorkArray = illusArray;
      curThumbArray = illusThumbArray;
      curTitleArray = illusTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = illusInfoArray;
      handleOver(over);
      handleWorkSwitch(illusFirst);
      if (illusFirst)
	//illusFirst=preloadSection(illusArray,illusFirst);
	preloadSection(illusArray,illusFirst);
    }
    else if(worktype == "oil")
    {
      curWorkArray = oilArray;
      curThumbArray = oilThumbArray;
      curTitleArray = oilTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = oilInfoArray;
      handleOver(over);
      handleWorkSwitch(oilFirst);
      if (oilFirst)
	//oilFirst = preloadSection(oilArray,oilFirst);
	preloadSection(oilArray,oilFirst);
    }
    else if(worktype == "print")
    {
      curWorkArray = printArray;
      curThumbArray = printThumbArray;
      curTitleArray = printTitleArray;
      curInfoArray = printInfoArray;
      curCreditArray = logoCreditArray;
      handleOver(over);
      handleWorkSwitch(printFirst);
      if (printFirst)
        //printFirst=preloadSection(printArray,printFirst);
	preloadSection(printArray,printFirst);
    }
    else if(worktype == "art")
    {
      curWorkArray = artArray;
      curThumbArray = artThumbArray;
      curTitleArray = artTitleArray;
      curCreditArray = logoCreditArray;
      curInfoArray = artInfoArray;
      handleOver(over);
      handleWorkSwitch(artFirst);
      if (artFirst)
        //artFirst=preloadSection(artArray,artFirst);
	preloadSection(artArray,artFirst);
    }
    //handleWorkSwitch();
    curWorkType=worktype;

    var image=document.getElementById('thenewphoto');
    curphoto=image.src; //starting photo for blending
  }
}

function hideAllThumbs()
{
  var i=0;
  var imageid;
  var image;

  for(i=0;i<curWorkArray.length;i++)
  {
    imageid='thumb'+i;
    image=document.getElementById(imageid);
    image.style.visibility='hidden';
  }

/*
  for(i=0;i<10;i++)
  {
    imageid='thumb'+i;
    image=document.getElementById(imageid);
    image.style.visibility='hidden';
  }
*/
  var ibox=document.getElementById('infobox');
  ibox.style.display='none';  
}

function handleWorkSwitch(first)
{
  var i=0;
  var imageid;
  var image;

  for(i=0;i<curWorkArray.length;i++)
  {
    imageid='thumb'+i;
    image=document.getElementById(imageid);
    image.src=curThumbArray[i];
    if(first == false)
      image.style.visibility='visible';
  }

  var ibox=document.getElementById('infobox');
  ibox.style.display=''; 
}

//clicked link remains black
function changeClass(id, newClass)
{
  var identity=document.getElementById('logos');
  identity.className='worktext';
  identity=document.getElementById('btb');
  identity.className='worktext';
  identity=document.getElementById('packaging');
  identity.className='worktext';
  identity=document.getElementById('brochure');
  identity.className='worktext';
  identity=document.getElementById('vidal');
  identity.className='worktext';
  identity=document.getElementById('oil');
  identity.className='worktext';
  identity=document.getElementById('boss');
  identity.className='worktext';
  identity=document.getElementById('illustrations');
  identity.className='worktext';
  identity=document.getElementById('print');
  identity.className='worktext';
  identity=document.getElementById('art');
  identity.className='worktext';

  
  identity=document.getElementById(id);
  if(identity != null)
    identity.className=newClass;
}

function browserInit()
{
  if(ie)
  {
    var tn = document.getElementById('topnav');
    tn.style.top = '80px';
  }
}


