$(document).ready(function(){
	// Thanks to tilllate.com for inspiring this idea: http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/
	$('.Contact').each(function(){
		$('.Contact span').each(function(){$(this).remove();});
		var oLink = document.createElement('a');
		oLink.href = 'mailto:' + $(this).text();
		$(this).wrapInner(oLink);
	});
	function PopulateDay(){
		var iDay = $('#optDay').val();
		var iMonth = $('#optMonth').val()-1;
		var iYear = $('#optYear').val();
		var iDaysInMonth = new Date(new Date(iYear,iMonth+1,1)-86400000).getDate();
		$('#optDay').val((iDay>iDaysInMonth)?iDaysInMonth:iDay);
		iDay = $('#optDay').val();
		var d = new Date(iYear,iMonth,iDay);
		$('.spnDay').css('display','none');
		$('#spnDay'+d.getDay()).css('display','inline');
	}
	function PopulateNights(){
		$('.spnNights').css('display','none');
		$($('#optNights').val()==1?'#spnNight':'#spnNights').css('display','inline');
	}
	PopulateDay();
	PopulateNights();
	$('#optDay, #optMonth, #optYear').click(function(){PopulateDay();}).change(function(){PopulateDay();}).keyup(function(){PopulateDay();});
	$('#optNights').click(function(){PopulateNights();}).change(function(){PopulateNights();}).keyup(function(){PopulateNights();});
	$('.LightBox a').lightBox({
		imageLoading:'/images/lightbox-ico-loading.gif',
		imageBtnClose:'/images/lightbox-btn-close.gif',
		imageBtnPrev:'/images/lightbox-btn-prev.gif',
		imageBtnNext:'/images/lightbox-btn-next.gif',
		imageBlank:'/images/pixel.gif',
		fixedNavigation:true
	});
	var iPhoto = 0;
	$('#Thumbs a').click(function(){
		var oThis = $(this);
		var oImg = new Image();
		var iPhotos = $('#Thumbs a').length-1;
		oImg.src = oThis.attr('href');
		iPhoto = $('#Thumbs a').index(oThis);
		$('#Gallery .Photo img').attr('id', oThis.attr('id').replace('Thumb','Photo')).attr('src', oThis.attr('href')).attr('alt', oThis.attr('title'));
		$('#Gallery .PhotoTitle').text(oThis.attr('title'));
		$('#Gallery .PhotoFooter').text('Photo ' + eval(iPhoto+1) + ' of ' + eval(iPhotos+1));
		$('#Thumbs a').each(function(){$(this).removeClass('On');});
		$('#Thumbs a').eq(iPhoto).addClass('On');
		return false;
	});
	$('#Gallery .Photo').css('cursor', 'pointer').attr('title', 'Click to view the next photo...').click(function(){
		var iPhotos = $('#Thumbs a').length-1
		if(iPhoto == iPhotos){
			$('#Thumbs a').eq(0).click();
		}else{
			$('#Thumbs a').eq(iPhoto+1).click();
		}
	});
	$('#Thumbs a').eq(0).click();
});