function showPic(g, i){
	source = galleryImages[g][i];
	title = galleryTitles[g][i];
	caption = galleryCaptions[g][i];

	finishLoad = source;
	new Effect.Fade('iCont', {duration:.5, afterFinish:function(){switchImage()}});
}

function switchImage(){
	var placeHolder = $('placeHolder');

	oImage = new Image;
	oImage.src = "photos/" + source;
	
	var imageInfo = $('imageInfo');
	imageInfo.innerHTML = '<p><b>' + title + '</b><br />' + caption + '</p>';

	placeHolder.src = "loading.gif";
	new Effect.Appear('iCont', {duration:.01, afterFinish: startCheck()});			
}

function startCheck(){
	if (oImage.complete){
		new Effect.Fade('iCont', {duration:.1, afterFinish:function(){fadeIn()}});

	} else {
		self.setTimeout("startCheck()", 250);
	}
}

function fadeIn(){
	var placeHolder = $('placeHolder');
	placeHolder.src = "photos/" + source;
	new Effect.Appear('iCont', {duration:.5, from: 0.0, to: 1.0});
	
}

function startGallery(ref){
	if (currGallery){
		lastGalleryTag = $('gallery' + currGallery);
		lastGalleryTag.setAttribute("class", "none");
	}

	currGallery = ref;

	currGalleryTag = $('gallery' + currGallery);
	currGalleryTag.setAttribute("class", "current");

	currImage = 0;

	if (currSection != 'image'){
		new Effect.BlindDown('iCont', {duration:1});
		new Effect.BlindUp(currSection, {duration:1, afterFinish:function(){showPic(currGallery, 0)}});
	
	} else {
		
		showPic(ref,0);
	}

	

	iCount = galleryImages[ref].length;
	
	if (iCount > 1){
		new Effect.BlindDown('aRight', {duration:.25});
	} else {
		new Effect.BlindUp('aRight', {duration:.25});
	}

	new Effect.BlindUp('aLeft', {duration:.25});

	currSection = 'image';
}

function advance(){
	new Effect.BlindDown('aLeft', {duration:.25});

	currImage++;
	showPic(currGallery, currImage);

	if (currImage == (iCount -1)){
		new Effect.BlindUp('aRight', {duration:.25});
	}
}

function reverse(){
	new Effect.BlindDown('aRight', {duration:.25});

	currImage--;
	showPic(currGallery, currImage);

	if (currImage == 0){
		new Effect.BlindUp('aLeft', {duration:.25});
	}
}

var galleryStatus;
galleryStatus = 0;

function toggleBlinds(ref){

	if (galleryStatus == 0){
		new Effect.BlindDown(ref);
		galleryStatus = 1;
	} else {
		new Effect.BlindUp(ref);
		galleryStatus = 0;
	}
}

function showContent(ref){
	if (currGallery){
		currGalleryTag = $('gallery' + currGallery);
		currGalleryTag.setAttribute("class", "none");
	}

	if (currSection == 'image'){
		new Effect.BlindUp('iCont', {duration:1, scaleContent:false});
	} else {
		new Effect.BlindUp(currSection, {duration:1, scaleContent:false});
	}
	new Effect.BlindDown(ref, {duration:2});

	currSection = ref;

	new Effect.BlindUp('aLeft', {duration:.25});
	new Effect.BlindUp('aRight', {duration:.25});
}
