var vText1 = new Array
(""
,"pied de lampe en porcelaine &eacute;poque Napol&eacute;on III"
,"pied de lampe en m&eacute;tal argent&eacute; et "
,"r&eacute;paration et &eacute;lectrification de "
,"vue de l'atelier"
,"pied de lampe en pl&acirc;tre et abat-jour contre-coll&eacute; "
,"confection et r&eacute;alisation des abat-jour &agrave; partir de "
,"r&eacute;alisation d'abat-jour "
,"montage d'un vase en porcelaine en lampe et confection de "
,"confection d'un abat-jour ovale couture"
,"lampe &agrave poser, abat-jour"
,"bient&ocirc;t vous je vous montrerai"
,"pied en bois patin&eacute; et "
,""
)
var vText2 = new Array
(""
,"r&eacute;paration et &eacute;lectrification"
,"confection d'un abat-jour couture pliss&eacute; en soie"
,"lampes en bois &agrave; d&eacute;cors peints"
,"&nbsp; "
,"confectionn&eacute; en soie rayures"
,"tissus d'&eacute;diteurs: Burger, Canovas, Frey, Brunschwig ..."
,"aquarell&eacute;s personnalis&eacute;s "
,"son abat-jour en soie juponn&eacute;, finition galon couture"
,"doubl&eacute; et finition galon soie verte"
,"en cuir v&eacute;ritable ajour&eacute;"
,"la lampe compl&egrave;te..."
,"confection de son abat-jour trap&egrave;ze"
,""
)

var vImage = new Array
( "images/DSC00210.JPG"
, "images/DSC00560.JPG"
, "images/DSC00562.JPG"
, "images/DSC00606.jpg"
, "images/DSC00980.JPG"
, "images/DSC00983.JPG"
, "images/DSC00989.JPG"
, "images/DSC00996.JPG"
, "images/DSC00998.JPG"
, "images/DSC01000.JPG"
, "images/DSC01001.jpg"
, "images/DSC01012.jpg"
, "images/DSC01026.JPG"
, "images/Lampe.jpg"
)

var cxImage = new Array("360","360","360","360","360","360","360","360","360","360","360","360","360","360")
var cyImage = new Array("542","480","480","480","270","480","480","480","480","480","480","480","480","480")
var vThumb = new Array("images/DSC00210.thumb.JPG", "images/DSC00560.thumb.JPG", "images/DSC00562.thumb.JPG", "images/DSC00606.thumb.jpg", "images/DSC00980.thumb.JPG", "images/DSC00983.thumb.JPG", "images/DSC00989.thumb.JPG", "images/DSC00996.thumb.JPG", "images/DSC00998.thumb.JPG", "images/DSC01000.thumb.JPG", "images/DSC01001.thumb.jpg", "images/DSC01012.thumb.jpg", "images/DSC01026.thumb.JPG", "images/Lampe.thumb.jpg")
var cImage = 14
var twh = 120

var controlsDisplay = "yes"
var useTransitions = "yes"

var imagePath = ""+"images"
var prevPath = imagePath + "/prev.gif" 
var nextPath = imagePath + "/next.gif" 
var playPath = imagePath + "/play.gif" 
var pausePath = imagePath + "/pause.gif" 
var stopPath = imagePath + "/stop.gif" 
var blankPath = imagePath + "/blank.gif" 
var brandingPath = imagePath + "/branding.gif" 

var runSlidesFlag = 0
var iImage = 0
var Mode = "Welcome"
var controlsEnabled = 1
var buttonsEnabled = 1
var fullscreen = (window.parent != window)
var timeoutid

function loadedDoc()
{
    if (!(navigator.appName == "Netscape" || navigator.appName.indexOf("Microsoft") == -1))
    {
       var preload = new Image
       preload.src = vImage[0]

       if (controlsDisplay)
       {
           var contactText = "<center><table style=\"overflow-y: auto\">"
           for (i = 0 ; i < cImage / 5; i++)
           {
              contactText = contactText + "<tr>"
              for (j = 0; j < 5 ; j++)
              {
                 var x = (i * 5 + j)
                 if (x < cImage)
                 {
                    contactText = contactText + "<td height=" +twh +" width=" +twh +"><img onclick=filmJump(" + x + ") style=\"cursor:hand; padding: 20px\" src=\"" + vThumb[x] + "\"></td>"
                 }
              }
              contactText = contactText + "</tr>"
           }
           contactText = contactText + "</table></center>"
           contact.innerHTML = contactText

/* jw modification : insert <div...> before <table> */
           var filmThumbsText = "<div id=\"filmThumbsText\" style =\"width: " + (twh * cImage )+ "; left: 0px; position:absolute\">"

/* jw TBModified : calculate size dynamically */
/* jw TBModified : stop the scrolling bar for the bottom of the div-table */
/* jw modification : left, position */
           filmThumbsText = filmThumbsText + "<table style=\"width: " + (twh * cImage )+ "; left: 0px; position:relative; overflow-x: scroll\"><tr height=" +twh +">"

           for (i = 0 ; i < vThumb.length ; i++)
           {
              filmThumbsText = filmThumbsText + "<td align=center width=" +twh +" id=filmThumb" + i + "><div id=filmThumbCell" + i + " style = \"padding: 5px; border: solid 0 #00b; border-width:2px\"><img onclick=filmSelect(" + i + ") class=THUMB style=\"cursor:hand; padding: 20px\" src=\"" + vThumb[i] + "\"></div></td>"
           }
           filmThumbsText = filmThumbsText + "</tr></table>"
           filmthumbs.innerHTML = filmThumbsText
       }

       filmmain.style.cursor = "hand"
       slidemain.style.cursor = "hand"

       welcome.style.display = "none"
       forwButton.src=nextPath
       runButton.src=playPath
       prevButton.src=prevPath
       stopButton.src=stopPath

       if (fullscreen)
       {
           Slideshow('launch')
       }
       else
       {
           welcome2.style.display = ""
       }
    }
}

function Ticker()
{
    if (runSlidesFlag == 1 && Mode == "Slideshow") 
    {
        nextImage()
        timeoutid = setTimeout("Ticker()", 5000)
    }
}

function ShowControls(x)
{
    if (controlsDisplay)
    {
        if (x=="Slideshow")
        {
           advcontrols1.style.color = "#ffffff"
           advcontrols2.style.color = "#03a0fc"
           advcontrols3.style.color = "#03a0fc"
        }
        else if (x=="Film")
        {
           advcontrols1.style.color = "#03a0fc"
           advcontrols2.style.color = "#ffffff"
           advcontrols3.style.color = "#03a0fc"
        }
        else if (x=="Contact")
        {
           advcontrols1.style.color = "#03a0fc"
           advcontrols2.style.color = "#03a0fc"
           advcontrols3.style.color = "#ffffff"
        }
    }
    else
    {
        advcontrols.style.visibility = "hidden"
    }
}

function ShowStopButton()
{
    if (fullscreen)
    {
       stopButton.width = 0;
       stopButton.style.cursor = "hand"
       stopButton.style.visibility = ""
    }
    else
    {
       stopButton.width = 0;
       stopButton.style.cursor = ""
       stopButton.style.visibility = "hidden"
    }

}

function ShowButtons(f)
{
    ShowStopButton();
    forwButton.filters[0].Apply();
    runButton.filters[0].Apply();
    prevButton.filters[0].Apply();
    stopButton.filters[0].Apply();
    if (f)
    {
        buttonsEnabled = 1
        forwButton.filters[0].transition = 3;
        runButton.filters[0].transition = 3;
        prevButton.filters[0].transition = 3;
        forwButton.src=nextPath
        runButton.src=playPath
        prevButton.src=prevPath
        forwButton.style.cursor="hand"
        runButton.style.cursor="hand"
        prevButton.style.cursor="hand"
    }
    else
    {
        buttonsEnabled = 0
        forwButton.filters[0].transition = 2;
        runButton.filters[0].transition = 2;
        prevButton.filters[0].transition = 2;
        prevButton.src=blankPath
        forwButton.src=blankPath
        runButton.src=blankPath
        forwButton.style.cursor=""
        runButton.style.cursor=""
        prevButton.style.cursor=""
    }
    forwButton.filters[0].Play();
    runButton.filters[0].Play();
    prevButton.filters[0].Play();
    stopButton.filters[0].Play();
}

function Film()
{
    if (controlsEnabled)
    {
        ShowControls('Film')
        Mode = "Film"
        runSlidesFlag = 0
        welcome.style.display = "none"
        welcome2.style.display = "none"
        controls.style.display = ""
	if ((document.body.clientHeight - 220) > 0)
        {
            film.height = 395 /* was document.body.clientHeight - 220*/
        }
        film.style.display = ""
        filmthumbs.style.display = ""
        contact.style.display = "none"
        slideshow.style.display = "none"
        ShowButtons(0)
        filmSelect(iImage)
        doResize()
    }
}

function Slideshow(x)
{
    if (controlsEnabled)
    {
        ShowControls('Slideshow')
        Mode = "Slideshow"
        welcome.style.display = "none"
        welcome2.style.display = "none"
        controls.style.display = ""
        slideshow.style.display = ""
        if (x == "launch")
        {
            ShowStopButton()
        }
        else
        {
            ShowButtons(1)
        }
        contact.style.display = "none"
        film.style.display = "none"
        filmthumbs.style.display = "none"
        slidemain.src = vImage[iImage]
        txt1.innerHTML = vText1[iImage]
        txt2.innerHTML = vText2[iImage]
        doResize()
    }
}

function Contact()
{
    if (controlsEnabled)
    {
        ShowControls('Contact')
        Mode = "Contact"
        runSlidesFlag = 0
        welcome.style.display = "none"
        welcome2.style.display = "none"
        controls.style.display = ""
        contact.style.display = ""
        slideshow.style.display = "none"
        ShowButtons(0)
        film.style.display = "none"
        filmthumbs.style.display = "none"
    }
}

function changeImage(x,y)
{
    iImage = (iImage + vImage.length + x) % vImage.length
    if (y == "notrans" || useTransitions != "yes")
    {
        slidemain.src = vImage[iImage]
        txt1.innerHTML = vText1[iImage]
        txt2.innerHTML = vText2[iImage]
    }
    else
    {
        slidemain.filters[0].Apply();
        slidemain.filters[0].transition = 17
        slidemain.src = vImage[iImage]
        txt1.innerHTML = vText1[iImage]
        txt2.innerHTML = vText2[iImage]
        slidemain.filters[0].Play();
    }
    doResize()
}

function prevImage(x)
{
    changeImage(-1,x)
}
function nextImage(x)
{
    changeImage(+1,x)
}

function slideClick()
{
   if (runSlidesFlag == 1)
   {
      runSlides()
   }
   nextImage("notrans")
}

function nextImageButton()
{
    if (buttonsEnabled)
    {
        if (runSlidesFlag == 1)
        {
           runSlides()
        }
        nextImage("notrans")
    }
}

function runSlidesButton()
{
    if (buttonsEnabled)
    {
        if (runSlidesFlag == 0)
        {
	   nextImage()
        }
        runSlides()
    }
}

function prevImageButton()
{
    if (buttonsEnabled)
    {
        if (runSlidesFlag == 1)
        {
           runSlides()
        }
        prevImage("notrans")
    }
}

function exitButton()
{
    /*window.parent.close()*/
}

function runSlides()
{
    runSlidesFlag = (runSlidesFlag + 1) % 2
    if (runSlidesFlag == 1)
    {
        runButton.src = pausePath
        timeoutid = setTimeout("Ticker()", 5000)
    }
    else
    {
        clearTimeout(timeoutid)
        runButton.src = playPath
    }
}

var xftt = 0; /* jw */

function filmPosition(i) 
/* jw handles the position of div with thumbs */  
/* jw need to get the width of the parent, not the screen client */
{
    var ftt = document.getElementById("filmThumbsText") ;
    var ii = i; 

    xftt = parseInt( ftt.style.left ) ; 
    lii = xftt + ii * twh ; 

    if ( lii < 02 ) 
    {
        ftt.style.left = ( 02 - ii * twh ) + 'px' ;
    }
    else if ( lii < ( document.body.clientWidth - 140 ) ) 
    {
    }
    else if ( lii > ( document.body.clientWidth - 140 ) ) 
    {
        ftt.style.left = (document.body.clientWidth - ii * twh - 140 ) + 'px' ;    
    }
}

function filmSelect(i)
{
    iImage = i;
    filmmain.src = vImage[i];
    txt1.innerHTML = vText1[i];
    txt2.innerHTML = vText2[i];
    for (var j = 0 ; j < cImage ; j++)
    {
        document.all["filmThumbCell"+j].style.border=""
    }
    document.all["filmThumbCell"+i].style.border="#00b 2px solid"
    doResize()
}

function filmJump(i)
{
    iImage = i;
    Film();
}

function changeFilmImage(x)
{
    filmSelect((iImage + vImage.length + x) % vImage.length)
}

function prevFilmImage()
{
    changeFilmImage(-1)
}

function nextFilmImage()
{
    changeFilmImage(+1)
}

function contactSelect(i)
{
    iImage = i
    Film()
    filmmain.src = vImage[i]
    txt1.innerHTML = vText1[i]
    txt2.innerHTML = vText2[i]
    doResize()
}

document.onkeydown = keyDown

function keyDown()	
{
   if (27 == event.keyCode)
   {         
     if (fullscreen == 1)
     {
	exitButton()    /* jw original : exitebutton */
     }
   }
   else if (Mode != "Welcome")
   {
      if (37 == event.keyCode)
      {
         if (Mode == "Slideshow")
         {
            prevImageButton()
         }
         else if (Mode == "Film")
         {
             prevFilmImage()
         }
      }
      else if (39 == event.keyCode)
      {
         if (Mode == "Slideshow")
         {
             nextImageButton()
         }
         else if (Mode == "Film")
         {
             nextFilmImage()
         }
      }
      else if (32 == event.keyCode)
      {
         if (Mode == "Slideshow")
         {
            runSlidesButton()
         }
         else
         {
            Slideshow()
         }
      }
   }
}

function doResize()
{
    var clientWidth = (document.body.clientWidth - 60)
    var clientHeight = (document.body.clientHeight - document.all.controls.offsetHeight - 40)

    if (Mode == "Film")
    {
        clientHeight -= document.all.filmthumbs.offsetHeight
    }

    var cx = cxImage[iImage]
    var cy = cyImage[iImage]

    if (clientWidth < cx)
    {
        cy = cy * clientWidth / cx;
        cx = clientWidth
    }
    if (clientHeight < cy)
    {
        cx = cx * clientHeight / cy;
        cy = clientHeight
    }

    if (Mode == "Film")
    {
        filmmain.width = cx;
        filmmain.height = cy;
    }
    else
    {
        slidemain.width = cx;
        slidemain.height = cy;
    }

    filmPosition(iImage);
}
