﻿var slide;
function preloadPics()
{
	for(x=0;x<galImages.length;x++)
	{
		thumbPreload[x] = new Array();
		imagePreload[x] = new Array();
		for(y=1;y<galImages[x].length;y++)
		{
			thumbPreload[x][y] = new Image;
			thumbPreload[x][y].src = "images/gallery/"+galImages[x][0]+"/thumbs/"+galImages[x][y];
		}
		for(y=1;y<galImages[x].length;y++)
		{
			imagePreload[x][y] = new Image;
			imagePreload[x][y].src = "images/gallery/"+galImages[x][0]+"/"+galImages[x][y];
		}
	}
}

function getGallery(galNumb)
{
    clearInterval(slide);
    document.getElementById('frameWork').className='gal'+galNumb; 
	document.getElementById('thumbCont').className = galNumb;
	document.getElementById('controls').className='pause';
	var imgPre = document.getElementById('imagePreview');
	imgPre.src="images/imagePreview.gif";
	imgPre.width='250';
	imgPre.height='400';
	document.getElementById('portHeader').innerHTML = galImages[galNumb][0]+"<span class=\"text2\">photographs</span>";
	var thmbChldrn = document.getElementById('thumbCont').childNodes;
	if(thmbChldrn.length>0)
	{
		for(x=thmbChldrn.length-1;x>=0;x--)
		{
			document.getElementById('thumbCont').removeChild(document.getElementById('thumbCont').childNodes[x]);
		}
	}
	for(x=1;x<galImages[galNumb].length;x++)
	{
		var thumbLink = document.createElement('a');
		thumbLink.setAttribute('href','javascript: imageLoader('+galNumb+','+x+');');
		thumbLink.className='img'+x;
		if(x%3==0)
		{
		    thumbLink.style.marginRight = 0;
		}
		var thumbs = document.createElement('img');
		thumbs.src = thumbPreload[galNumb][x].src;
		thumbs.setAttribute("alt",galImages[galNumb][0]+": image "+x);
		var thumbsContainer = document.getElementById('thumbCont');
		thumbLink.appendChild(thumbs);
		var textBr = document.createElement('br');
		thumbLink.appendChild(textBr);
		var thumbText = document.createTextNode("["+galImages[galNumb][x]+"]");
		thumbLink.appendChild(thumbText);
		thumbsContainer.appendChild(thumbLink);
		if(x%3==0)
		{
		    var lineBr = document.createElement('br');
		    lineBr.style.clear='left';
		    thumbsContainer.appendChild(lineBr);
        }
	}
	document.getElementById('content').className="gallery";
}

function imageLoader(galNumb,imgNumb)
{
	var imgViewer = document.getElementById('imagePreview');
	imgViewer.width = imagePreload[galNumb][imgNumb].width;
	imgViewer.height = imagePreload[galNumb][imgNumb].height;
	imgViewer.src = imagePreload[galNumb][imgNumb].src;
   	imgViewer.style.filter="alpha(opacity:"+0+")";
   	imgViewer.opacity=0;
   	imgViewer.style.MozOpacity=0;
    imgViewer.style.opacity=0;
    imgFade(0);
    document.getElementById('frameWork').className='imgAct'+imgNumb; 
}

function imgFade(imgOpacity)
{
    imgLoad=document.getElementById('imagePreview');
	imgLoad.style.filter="alpha(opacity:"+imgOpacity+")";
    imgLoad.opacity=imgOpacity;
    imgLoad.style.MozOpacity=imgOpacity;
    imgLoad.style.opacity = imgOpacity/100;
    if(imgOpacity<=100)
    {
        var fadeIn=setTimeout("imgFade("+(imgOpacity+=4)+")",10);
    }
}

function slideShow()
{
	if(document.getElementById('controls').className=='play')
	{
		var gal = document.getElementById('thumbCont').className;
		var imgViewer = document.getElementById('imagePreview');
		imgNumb = 1;
		for(x=1;x<imagePreload[gal].length-1;x++)
		{
			if(imgViewer.src == imagePreload[gal][x].src)
			{
				imgNumb = x+1;
			}
		}
		imgViewer.width = imagePreload[gal][imgNumb].width;
		imgViewer.height = imagePreload[gal][imgNumb].height;
		imgViewer.src = imagePreload[gal][imgNumb].src;
   	    imgViewer.style.filter="alpha(opacity:"+0+")";
   	    imgViewer.opacity=0;
   	    imgViewer.style.MozOpacity=0;
        imgViewer.style.opacity=0;
        imgFade(0);
    document.getElementById('frameWork').className='imgAct'+imgNumb; 
	}
}

function writeGalleries()
{
    document.write("<strong>galleries:</strong> ");
    for(x=0;x<galImages.length;x++)
    {
	    document.write("<a href=\"javascript: getGallery("+x+");\">"+galImages[x][0]+"</a>");
	    if(x<galImages.length-1)
	    {
		    document.write(" | ");
	    }
    }
}