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;

  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);
}

//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 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,packFirst);
    }

    //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(id);
  if(identity != null)
    identity.className=newClass;
}

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


