//=============================================================================
// file: js.js
// auth: nick 07/04/05
// desc: the js for wolsey
//=============================================================================

//==========================================================
// func: changeTeam(imageNum)
// auth: nick 12/04/05
// desc: changes the team displayed
// args: imageNum - the number of the team to show
// retn: none
//==========================================================
function changeTeam(imageNum)
{
    // loop through all teams
    for (var i = 1; i <= 4; i ++)
    {
        // if this is the correct image then show, else hide
        if (imageNum == i)
            document.getElementById('team' + i).style.display = 'block';
        else
            document.getElementById('team' + i).style.display = 'none';
    }
}

//==========================================================
// func: office(officeId)
// auth: nick 14/04/05
// desc: creates the directions to the office
// args: officeId - the id of the office
// retn: none
//==========================================================
function office(officeId,site)
{
    // open the new window
    window.open('/popup.office.php?id=' + officeId +'&site=' +site, 'officePopup', 'width=610,height=580,scrollbars, status');
}

//==========================================================
// func: slides(caseId)
// auth: nick 15/04/05
// desc: creates the slide show popup
// args: caseId - the id of the case history
// retn: none
//==========================================================
function slides(caseId)
{
    // open the new window
    window.open('/popup.slides.php?id=' + caseId, 'slidesPopup', 'width=500,height=500,scrollbars, status');
}

//==========================================================
// func: slideShow(objectId)
// auth: nick 15/04/05
// desc: creates a slide show
// args: objectId - the image to be changed
// retn: none
//==========================================================
function slideShow(objectId)
{
    // init vars
    imageArray = new Array();
    descArray  = new Array();
    automatic  = true;
    counter    = 0;
    
    //==========================================================
    // func: add(newImage, description)
    // auth: nick 15/04/05
    // desc: adds an image to the slide show
    // args: newImage    - the path of the image to be added
    //       description - a description of the image
    // retn: none
    //==========================================================
    this.add = function(newImage, description)
    {
        // store the position
        position = imageArray.length;
        
        // store the image and description
        imageArray[position]     = new Image();
        imageArray[position].src = newImage;
        descArray[position]      = description;
    }
    
    //==========================================================
    // func: init()
    // auth: nick 15/04/05
    // desc: starts the slide show
    // args: none
    // retn: none
    //==========================================================
    this.init = function()
    {
        slide.updateImage();
    }
    
    //==========================================================
    // func: updateImage()
    // auth: nick 15/04/05
    // desc: update the slide show
    // args: none
    // retn: none
    //==========================================================
    this.updateImage = function()
    {
        // look for ie and blend
        if (document.all)
        {
            document.getElementById(objectId + 'Image').style.filter = "blendTrans(duration = 3)";
            document.getElementById(objectId + 'Image').filters.blendTrans.Apply();
        }
        
        // swap the images
        document.getElementById(objectId + 'Image').src = imageArray[counter].src;
        
        // swap the text
        document.getElementById(objectId + 'Title').innerHTML   = descArray[counter];
        document.getElementById(objectId + 'Current').innerHTML = (counter + 1);
        document.getElementById(objectId + 'Total').innerHTML   = imageArray.length;
        
        // look for ie and play the transition
        if (document.all)
        {
            document.getElementById(objectId + 'Image').filters.gray();
            document.getElementById(objectId + 'Image').filters.blendTrans.Play();
        }
        
        // increment the counter
        counter++;
        
        // make the counter wrap if needed
        if (counter >= (imageArray.length))
            counter = 0;
        
        // replay the automation
        if (automatic == true)
            var t = setTimeout('slide.autoUpdateImage()', 5000);
    }
    
    //==========================================================
    // func: autoUpdateImage()
    // auth: nick 15/04/05
    // desc: automate the slide show
    // args: none
    // retn: none
    //==========================================================
    this.autoUpdateImage = function()
    {
        // if this is set to be automated
        if (automatic == true)
            slide.updateImage();
    }
    
    //==========================================================
    // func: forward()
    // auth: nick 15/04/05
    // desc: pause and go to the next image
    // args: none
    // retn: none
    //==========================================================
    this.forward = function()
    {
        // turn off automatic updates
        automatic = false;
        
        // change the pause button
        document.getElementById(objectId + 'Pause').src   = '/img/slideControls/play.gif';
        document.getElementById(objectId + 'Pause').alt   = 'Play Slide Show';
        document.getElementById(objectId + 'Pause').title = 'Play Slide Show';
        
        // update image
        slide.updateImage();
    }
    
    //==========================================================
    // func: back()
    // auth: nick 15/04/05
    // desc: pause and go to the last image
    // args: none
    // retn: none
    //==========================================================
    this.back = function()
    {
        // turn off automatic updates
        automatic = false;
        
        // change the pause button
        document.getElementById(objectId + 'Pause').src   = '/img/slideControls/play.gif';
        document.getElementById(objectId + 'Pause').alt   = 'Play Slide Show';
        document.getElementById(objectId + 'Pause').title = 'Play Slide Show';
        
        // change counter
        counter = counter - 2;
        
        // make the counter wrap if needed
        if (counter == -1)
            counter = (imageArray.length - 1);
        else if (counter == -2)
            counter = (imageArray.length - 2);
        
        // update image
        slide.updateImage();
    }
    
    //==========================================================
    // func: pause()
    // auth: nick 15/04/05
    // desc: alternate between pause and play
    // args: none
    // retn: none
    //==========================================================
    this.pause = function()
    {
        // invert automatic updates
        automatic = !automatic;
        
        // change the pause button
        if (automatic == true)
        {
            document.getElementById(objectId + 'Pause').src = '/img/slideControls/pause.gif';
            document.getElementById(objectId + 'Pause').alt   = 'Pause Slide Show';
            document.getElementById(objectId + 'Pause').title = 'Pause Slide Show';
        }
        else
        {
            document.getElementById(objectId + 'Pause').src = '/img/slideControls/play.gif';
            document.getElementById(objectId + 'Pause').alt   = 'Play Slide Show';
            document.getElementById(objectId + 'Pause').title = 'Play Slide Show';
        }
        
        // if automatic is on, update image
        if (automatic == true)
            slide.updateImage();
    }
}

//==========================================================
// func: showDiv(divName, level, e)
// desc: shows the div and moves to the correct place
// args: divName - the name of the div
//       level   - the correct data to use
//       e       - the event handler
// retn: none
//==========================================================
function showDiv(divName, level, e)
{
    document.getElementById(divName).innerHTML = dataArray[level];
    document.getElementById(divName + 'Container').style.display = 'block';
}

//==========================================================
// func: hideDiv(divName)
// desc: hides the div
// args: divName - the name of the div
// retn: none
//==========================================================
function hideDiv(divName)
{
  document.getElementById(divName + 'Container').style.display = 'none';
}