$(document).ready(function () {

	$(".privacy-link").click(function(e) {
		e.preventDefault();
		window.open ("/legal/privacy","mywindow","toolbar=0,menubar=0,resizable=0,location=0,status=0,scrollbars=1,width=1000,height=500"); 
	});

	$(".terms-link").click(function(e) {
		e.preventDefault();
		window.open ("/legal/terms-of-use","mywindow","toolbar=0,menubar=0,resizable=0,location=0,status=0,scrollbars=1,width=1000,height=500"); 
	});

	// intercept the click for all highslide images
	$('a.highslide').each(function() { 
		this.onclick = function() { 
			return hs.expand(this,{ slideshowGroup: 1 }); 
		}; 
	});


	/* Email form
	-----------------------------------*/

	$('.warning').remove();
	$.get('/_inc/token.php',function(txt){
/* 		alert(txt); */
		$('#guestbook').prepend('<input type="hidden" name="ts" id="ts" value="'+txt+'" />');
	});

	$("#guestbook").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
		},
		messages: {
			email: "Please enter a valid email address<br />",
		},
		submitHandler: function() {
			var action = $("input#action").val();
			var ts = $("input#ts").val();
			var email = $("input#email").val();
			var dataString = 'email=' + email + '&ts=' + ts + '&action=' + action;
			//alert (dataString);return false;
			
			$.ajax({
				type: "POST",
				url: "/_inc/mailform.php",
				data: dataString,
				success: showResponse
			});
			return false;
			
			// post-submit callback
			function showResponse(responseText, statusText) {
			
				$('#guestbook').html("<div id='message'></div>");
				$('#message').html("<h3>" + responseText + "</h3>")
				.hide()
				.fadeIn(1500);
			
			}
		},

	});
	
});


/* Highslide settings
-----------------------------------*/

	hs.graphicsDir = '/_js/highslide/graphics/';
	hs.showCredits = false;
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.fadeInOut = true;
	hs.numberPosition = 'caption';
	hs.dimmingOpacity = 0.75;
	hs.captionId = 'the-caption';

	// Add the controlbar
	if (hs.addSlideshow) hs.addSlideshow({
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .75,
			position: 'bottom center',
			hideOnMouseOut: true
		}
	});

