/**
 * 
 */

$(document).ready(function() {
	
	var theY; // the YOffset
	
	// display the photo thumnail slideshow
	$(".script-on").css("display", "block");
	
	//photo thumbnail slideshow
	$("#gallery").cycle({
		fx: 'fade'
	});

	// Photo Gallery
	$("#gallery a").lightBox();
	
	// Open Photo Gallery for the showcase photo
	$(".showcase").lightBox();
	
	// create a calendar thumbnail
	$("#calendar-thumb").datepicker();
	
	// click the calendar thumbnail to display the calendar
	$("#calendar-thumb").click(function() {
		displayCalendar();
	});
		
	// for IE, display the calendar if <a> is clicked
	$("#calendar-thumb a").click(function() {
		displayCalendar();
		return false;
	});
	
	// hide the calendar by clicking anywhere outside the calendar
	$("#calendar-overlay, #calendar-lightbox").click(function(){
		finish();
	});
	
	// hide the calendar by clicking on the close button
	$("#close-button").click(function() {
		finish();
	});	
	
	// toggle acknowledgement
	$("#ack").click(function(){
	    $("#credits ul").slideToggle("slow");
	});	
});

//get the XOffset and YOffset
function getXYOffsets() {
	var xOffset, yOffset;
	var xyOffsets;
	
	if (self.pageYOffset) {
		xOffset = self.pageXOffset;
		yOffset = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		xOffset = document.documentElement.scrollLeft;
		yOffset = document.documentElement.scrollTop;
	} else if (document.body) {	// all other Explorers
		xOffset = document.body.scrollLeft;	
		yOffset = document.body.scrollTop;
	}
	xyOffsets = new Array(xOffset,yOffset);
	return xyOffsets;	
}

// display calendar
function displayCalendar() {
	// decide where to display the calendar vertically
	theY = getXYOffsets()[1] + 20;
	theY = theY + "px";
	$("#calendar-lightbox").css("top", theY);
	
	// display calendar-overlay
	$("#calendar-overlay").fadeIn();
	
	// show calendar-lightbox
	$("#calendar-lightbox").show(1000);
}

// hides the calendar 
function finish() {
	$("#calendar-lightbox").hide();
	$("#calendar-overlay").fadeOut();
}
