﻿var lastscrollpos;
var currentimg;
var currentgroup;
var imgcount;
var show;
var currentdiv;
    
function startup ()
{
    setFooter();
    currentimg = 0;
    currentgroup = 0;
    imgcount = 0;
    show = false;
}

function setFooter() 
{
    if (document.getElementById) 
    {
        var windowHeight=getWindowHeight();
        if (windowHeight>0) 
        {
            var contentDiv= document.getElementById('contentdiv');
            var footerDiv= document.getElementById('footer');
            
            if (contentDiv != null && contentDiv.offsetHeight > 450)
            {
                footerDiv.style.top = contentDiv.offsetHeight + 125;
            }
        }
    }
}

function getWindowHeight() 
{
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') 
    {
        windowHeight=window.innerHeight;
    }
    else 
    {
        if (document.documentElement&&document.documentElement.clientHeight) 
        {
            windowHeight=document.documentElement.clientHeight;
        }
        else 
        {
            if (document.body&&document.body.clientHeight) 
            {
                windowHeight=document.body.clientHeight;
            }
        }
    }
return windowHeight;
}

function nextImage()
{
    currentimg++;
    showImage(currentgroup,currentimg,imgcount);
}

function previousImage()
{
    currentimg--;
    showImage(currentgroup,currentimg,imgcount);
}

function showImage(group,image,imagecount)
{
    var imagewindow = document.getElementById('imagewindow');
    imagewindow.style.visibility='visible';
    var imagewindowimg = document.getElementById('imagewindowimg');
    imagewindowimg.src = document.getElementById(group+image).src;
    
    currentimg = image;
    currentgroup = group;
    imgcount = imagecount;
    
    var imagewindowprevious = document.getElementById('imagewindowprevious');
    var imagewindownext = document.getElementById('imagewindownext');
     
    if (image > 0)
    {
        imagewindowprevious.style.visibility = 'visible';
    }
    else
    {
        imagewindowprevious.style.visibility = 'hidden';
    }
    
    if (image < imgcount-1)
    {
        imagewindownext.style.visibility = 'visible';
    }
    else
    {
        imagewindownext.style.visibility = 'hidden';
    }
    
    lastscrollpos = document.body.scrollTop;
    window.scroll(0,0);    
}

function hideImage()
{
    var imagewindow = document.getElementById('imagewindow');
    imagewindow.style.visibility='hidden';
    window.scroll(0,lastscrollpos);
}

function ToggleDiv(divid,image,showimage,hideimage)
{
    var imageimg = document.getElementById(image);
    
    if (!show)
    {
        show = true;
        imageimg.setAttribute('src',hideimage);
        opacity(image, 100, 100, 500)
        ShowDiv(divid);
    }
    else
    {
        show = false;
        imageimg.setAttribute('src',showimage);
        opacity(image, 100, 100, 10)
        CloseDiv(divid);
    }
}

function ShowDiv(divid)
{
    try
    {
        var divref = document.getElementById(divid);
        divref.style.display='';
        opacity(divid,0,100,500);
    }
    catch (e)
    {
        window.alert('Exception in ShowDiv');
    }
}

function CloseDiv(divid)
{
    try 
    {
        opacity(divid,100,0,500);
        setTimeout("closediv('" + divid + "')",500);
    }
    catch (e)
    {
        window.alert('Exception in CloseDiv');
    }
}

function closediv (divid)
{
    var thediv = document.getElementById(divid);
    thediv.style.display='none';
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 


function cycleDiv(group,id,max,timeout)
{
    document.getElementById(group+id).style.display='none';
    if (id < max-1)
        id++;
    else
        id = 0;
    document.getElementById(group+id).style.display='';

    setTimeout("cycleDiv('" + group + "'," + id + "," + max + "," + timeout + ")",timeout);        
}