var vImage = new Array("images/welcome.jpg", "images/table.jpg", "images/specialchars.jpg", "images/link2.jpg", "images/link1.jpg", "images/image2.jpg", "images/image1.jpg", "images/filemanager.jpg", "images/editmode.jpg", "images/color2.jpg", "images/color1.jpg", "images/browsemode.jpg")
var cxImage = new Array("567","506","416","421","421","419","417","567","567","346","346","567")
var cyImage = new Array("354","400","295","275","275","324","323","353","354","315","315","354")
var vThumb = new Array("images/welcome.thumb.jpg", "images/table.thumb.jpg", "images/specialchars.thumb.jpg", "images/link2.thumb.jpg", "images/link1.thumb.jpg", "images/image2.thumb.jpg", "images/image1.thumb.jpg", "images/filemanager.thumb.jpg", "images/editmode.thumb.jpg", "images/color2.thumb.jpg", "images/color1.thumb.jpg", "images/browsemode.thumb.jpg")
var cImage = 12
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
var transit=1;

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=120 width=120><img onclick=filmJump(" + x + ") style=\"cursor:hand; padding: 20px\" src=\"" + vThumb[x] + "\"></td>"
                 }
              }
              contactText = contactText + "</tr>";
           }
           contactText = contactText + "</table></center>";
           contact.innerHTML = contactText;

           var filmThumbsText = "<table style=\"width: 1440; overflow-x: scroll\" border=0><tr height=120>"
           for (i = 0 ; i < vThumb.length ; i++) {
              filmThumbsText = filmThumbsText + "<td align=center width='100%' 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;
       Slideshow('launch');
    }
}

function Ticker() {
    if (runSlidesFlag == 1 && Mode == "Slideshow") {
        nextImage();
        timeoutid = setTimeout("Ticker()", 8000);
    }
}

function ShowControls(x) {
    if (controlsDisplay)
    {
        if (x=="Slideshow")
        {
           advcontrols1.style.color = "#a0a0a0"
           advcontrols2.style.color = "#03a0fc"
           advcontrols3.style.color = "#03a0fc"
        }
        else if (x=="Film")
        {
           advcontrols1.style.color = "#03a0fc"
           advcontrols2.style.color = "#a0a0a0"
           advcontrols3.style.color = "#03a0fc"
        }
        else if (x=="Contact")
        {
           advcontrols1.style.color = "#03a0fc"
           advcontrols2.style.color = "#03a0fc"
           advcontrols3.style.color = "#a0a0a0"
        }
    }
    else
    {
        advcontrols.style.visibility = "hidden"
    }
}

function ShowStopButton()
{
    if (fullscreen)
    {
       stopButton.width = 32;
       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 = 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]
        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]
    }
    else
    {
        slidemain.filters[0].Apply();
        slidemain.filters[0].transition = transit++
        slidemain.src = vImage[iImage]
        slidemain.filters[0].Play();
	if (transit>17) transit=1;
    }
    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
    }
}

function filmSelect(i)
{
    iImage = i;
    filmmain.src = vImage[i];
    for (var j = 0 ; j < cImage ; j++)
    {
        document.all["filmThumbCell"+j].style.border=""
    }
    document.all["filmThumbCell"+i].style.border="silver 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]
    doResize()
}

document.onkeydown = keyDown

function keyDown()	
{
   if (27 == event.keyCode)
   {         
     if (fullscreen == 1)
     {
	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 - 40)
    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;
    }
}

