
var openLB = "";

// function that displays lightbox
function openLightBox(currOpen)
{
	document.getElementById('lightbox_overlay').style.display = "block";
	document.getElementById(currOpen).style.display = "block";

	openLB = currOpen;
}

// function that hides lightbox
function closeLightBox()
{
        document.getElementById('lightbox_overlay').style.display = 'none';
        document.getElementById(openLB).style.display = 'none';
}

function LightboxFormSubmit()
{
	if(openLB == "lightbox_thoughts")
	{
                var name = document.thoughtsForm.lName.value;
                var email = document.thoughtsForm.email.value;
                var message = document.thoughtsForm.message.value;
	}
	else
	{
		var name = document.emailForm.lName.value;
		var email = document.emailForm.email.value
		var message = "none";
	}

	new Ajax.Request("emailSubmit.php", 
	{ 
        	method: 'post', 
        	postBody: 'name='+name+'&email='+email+'&message='+message,
        	onComplete: Done
	});

	closeLightBox();
	
	return false;
}

function Done(request)
{
	
}

function ImageChange(newImg, imageID)
{
	document["mainPhoto"].src = newImg;
	document.imageView.imageID.value = imageID;
}

function StartFade()
{

        setInterval('Rotate()', imageTime);
        PreLoad(currIndex + 1);
}       

function PreLoad(index)
{
        var preLoadImg = document.getElementById('preLoadImg');
        preLoadImg.src = imageArr[index];
}

function Rotate()
{
        lastIndex = currIndex;
        if(lastIndex == -1)
                lastIndex = imageArr.length - 1;

        currIndex++;
        var img = document.getElementById('mainImage');

        var background = document.getElementById('mainImageDiv');
        background.style.backgroundImage = "url(" + img.src + ")";
        background.style.backgroundRepeat = 'no-repeat';
	background.style.backgroundPosition = 'center center';

        imgSrc = imageArr[currIndex]
        currOpacity = 0;
        SetOpacity(img, currOpacity);
        img.src = imgSrc;

	img.alt = imgAltArr[currIndex];
	link = document.getElementById('mainImageLink');
	link.href = linkArr[currIndex];

        setTimeout('Fade()', 10);

        if(currIndex + 1 == imageArr.length)
                currIndex = -1;
        else
                PreLoad(currIndex + 1);
}

function Fade()
{
        currOpacity = currOpacity + 2;

        img = document.getElementById('mainImage');

        SetOpacity(img, currOpacity);   
        
        if(currOpacity != 100)
                setTimeout('Fade()', 10);
	else
	{
		var background = document.getElementById('mainImageDiv');
		background.style.backgroundImage = "none";
	}
}

function SetOpacity(img, percent)
{
        //ie
        img.style.filter = "alpha(opacity = " + percent + ")";
        
        //ff
        img.style.MozOpacity = percent / 100;
        
        //webkit
        img.style.opacity = percent / 100;
}

