// JavaScript Document
//load js files
function scriptLoad(url){
	document.write( '<script type="text/javascript" src="', url, '">', '<\/script>' ); 			   
}
scriptLoad('js/jquery.lightbox-0.5.pack.js');
//links
$(function(){ 
	$("a[rel='external']").attr("target","_blank");
}); 
function clearStatusBar(){
	window.status = '';
	return true;
}
//mail list
$(function(){
	$("#firstName").focus();
	$("#mailListSend").click(validateMailList);
});
//reviews
$(function(){
	$("a[name='revShow']").each(function(){
		$(this).click(function(){
			if($(this).html() == "-"){
				$("#longReview_"+this.id).slideUp("normal", function(){
					$(this).prev().show();
				});
				$(this).html("+");
			}else{
				$("#shortReview_"+this.id).hide();
				$("#longReview_"+this.id).slideDown("normal");
				$(this).html("-");
			}
		});
	});
});
//flash loaders
function buildFlashScript(path, width, height){
	var fc = "<object type='application/x-shockwave-flash' data='"+path+"' width='"+width+"' height='"+height+"' id='NTHeader'>\n";
	fc += "<param name='movie' value='"+path+"' />\n";
	fc += "<param name='allowScriptAcess' value='sameDomain' />\n";
	fc += "<param name='quality' value='best' />\n";
	fc += "<param name='scale' value='noScale' />\n";
	fc += "<param name='salign' value='TL' />\n";
	fc += "<param name='wmode' value='transparent' />\n";
	fc += "</object>";
	return fc;
}
$(function(){
	$("#flash").html(buildFlashScript("swf/header.swf", 230, 120));
	$("#flashSacredHill").html(buildFlashScript("swf/sacred.swf", 400, 30));
	$("#flashPuketapu").html(buildFlashScript("swf/puketapu.swf", 400, 30));
	$("#flashEdgeOfADream").html(buildFlashScript("swf/edge_of_a_dream.swf", 400, 30));
});
//print page
$(function(){
	$("#printPage").click(function(){window.print();});
});
function validateMailList(){
	var f = document.getElementById('firstName');
	var l = document.getElementById('lastName');
	var e = document.getElementById('email');
	var m = document.getElementById('mobile');
	var p = document.getElementById('mailListMsg');
	var msg = "";
	
	if($("#firstName").val().length < 1){
		msg = "Please enter a First Name...";
		$("#mailListMsg").html(msg);
		$("#firstName").css('backgroundColor','#d07b02').focus();
	}else{
		$("#firstName").css('backgroundColor','#d4d4b2');
		if($("#email").val().length < 3){
			msg = "Please enter a valid email address...";
			$("#mailListMsg").html(msg);
			$("#email").css('backgroundColor','#d07b02').focus();
		}else{
			if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#email").val())){
				msg = "Please enter a valid email address...";
				$("#mailListMsg").html(msg);
				$("#email").css('backgroundColor','#d07b02').focus();
			}else{
				$("#email").css('backgroundColor','#d4d4b2').focus();
				var formData = $("#mailListForm").serialize();
				$.get("process_mail.php", formData, function(data){
					if(data == 1){
						msg = "THANK YOU. Your details have been added to our list. Enter more details below if you wish...";
					}else{
						msg = "ERROR: Your details could not be processed at this time. Please try again Later...";
					}
					$("#mailListMsg").html("");
					$('#firstName').val("").focus();
					$('#lastName').val("");
					$('#email').val("");
					$('#mobile').val("");
					$('#region').val(0);
					$("#mailListMsg").html(msg);
				});
			}
		}
	}
}
//Gallery - activate lightbox
$(function(){
	$("div.contentGallery a[rel='lightbox']").lightBox({
		imageLoading: 'img/lightbox-ico-loading.gif',
		imageBtnClose: 'img/lightbox-btn-close.gif',
		imageBtnPrev: 'img/lightbox-btn-prev.gif',
		imageBtnNext: 'img/lightbox-btn-next.gif',
	});
	$("div.contentGallery div h3").click(function(){
		$(this).next().slideToggle("normal");											  
	});
});


/*---Unsubscribe---*/
$(function(){
	$('#unSubCancel').click(function(){
		window.location.href = "index.php";	
	});
});
