// JavaScript Document

// JavaScript Document
// set up vars for the important things
var $galleryFrame = false;
var $galleryMask = false;

function createGalleryHolder () {
		// add the holder divs onto the body
		$("body").append('<div id="galleryMask"></div><div id="galleryFrame"><div class="galleryPopup"></div></div>');
		// and save references to them to make subsequent code quicker
		$galleryFrame = $("#galleryFrame");	
		$galleryMask = $("#galleryMask");	
}
function closeGallery() {
	// fade everything out.
	$galleryFrame.fadeOut(100,function () {
		// get rid of gallery when gone
		$("div.galleryPopup",this).html("");									
	});
	// fade out the mask
	// slower than content box gives a gloopy feel
	$galleryMask.fadeOut(250);
}
function refreshGallery (href) {
	// ajax get to get document
	$(".galleryPopup",$galleryFrame).loadJFrame(href, function(data){
		// load the content into te div
		$(".galleryPopup",$galleryFrame).html(data);
		// fade in the gallery if this is the first time		
		if ($galleryFrame.css("display") == "none") {
			$galleryFrame.fadeIn(100);
		}
		
	});
}
function loadGallery (href) {
	// first run
	// create and fade in mask
	//alert(href);
	if ($galleryFrame == false) {
		createGalleryHolder();
	}
	// click bg to close
	$galleryMask.click(closeGallery);
	// fade in
	$galleryMask.fadeIn(250);
	// and load the page
	refreshGallery(href);
}
// set up gallery images
$(document).ready(function () {							
	var $gallery = $("#galleryContent");
	if ($gallery.attr("id")!= null) {
		$(".galleryImage a",$gallery).each(function () {
			$(this).attr("href","javascript:loadGallery('"+$(this).attr("href")+"')").attr("target","_self");
		});
	}		
});


function subscribe () {
	loadGallery("subscribe.php");	
}

function clf(e) { e.value = ""; }

function clearform () {		
	for (var n = 0; n < document.updateForm.elements.length; n++) { 
		field = document.updateForm.elements[n];
		if (field.type == "text") {
			if (field.value.substring(0,5)=="enter" || field.value.substring(0,6)=="please") field.value = "";
		}
	}	
}

