$(document).ready(function() {
   $('#cycle').cycle({ 
	fx:    'fade', 
	timeout: 8000,
	prev:   '#prev2',
	next:   '#next2' 
	});
		
//	$("a.page-img").fancybox({
//		'transitionIn'	:	'elastic',
//		'transitionOut'	:	'elastic',
//		'speedIn'		:	600, 
//		'speedOut'		:	200, 
//		'overlayShow'	:	true
//	});


	$("#slider").easySlider({
		prevId: 		'prevBtn',
		prevText: 		'Previous',
		nextId: 		'nextBtn',	
		nextText: 		'Next',
		controlsShow:		false,
		controlsBefore:	'',
		controlsAfter:		'',	
		controlsFade:		true,
		firstId: 		'firstBtn',
		firstText: 		'First',
		firstShow:		false,
		lastId: 		'lastBtn',	
		lastText: 		'Last',
		lastShow:		false,				
		vertical:		false,
		speed: 		800,
		auto:			true,
		pause:			5000,
		continuous:		true, 
		numeric: 		false,
		numericId: 		'controls'
	});

});
$(function() {
	$("#subscribeSubmit").click(function(event) {
		event.preventDefault();
		validateEmail();
	});
});

$(function() {
	$("#countrySelector").change(function()
	{
		if($("#countrySelector").val() != '')
		{
			window.location.href = $("#countrySelector").val();
		}
	});
});

function isValidEmailAddress(emailAddress)
{
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function validateEmail()
{
	var errorHTML = '';
	var error = false;
	
	if($('#email').val() == '' || $('#email').val() == null)
	{
		error = true;
		errorHTML += '<ul><li><strong>EMAIL NOT SUPPLIED</strong>.</li><li>You must enter an email address to subscribe for our newsletter.</li></ul>';
	}
	
	if(!isValidEmailAddress($('#email').val()))
	{
		error = true;
		errorHTML += '<ul><li><strong>EMAIL NOT VALID</strong>.</li><li>You must enter a real, valid email address. It should be something similar to <strong>someone@somewhere.com</strong></li></ul>';
	}

	if(error)
	{
		$("#dialog").dialog("destroy");
		$('#dialog').bgiframe();
		$("#dialog-modal-email").dialog({	modal: true, width:400, height:200	});
		$("#dialog-modal-email").html(errorHTML);
	}
	else
	{
		var email = $('#email').val();
		var dataString = 'email=' + email;
		//alert (dataString);return false;  
		$.ajax({  
		type: "POST",
		url: "emailSubscribe",
		data: dataString,  
		success: function(data) {  
		  if(data == '<span style="color:#900;">Sorry, your email address was not valid. Please try again.</span>')
		  {
			  $('#subscriptionText').html(data)
			  .hide()
			  .fadeIn(1500);
		  }
		  else
		  {
			  $('#subscribeFormWrapper').html("");
			  $('#subscriptionText').html("<strong>Subscription Successful!</strong> - ")  
			  .append(data)
			  .hide()
			  .fadeIn(1500);
		  }
		}  
		});  
		return false;
	}
}

function goto(form) 
{ 
	var index=form.ArrivalPointGroupId.selectedIndex
	if (form.ArrivalPointGroupId.options[index].value != "0") {
	location=form.ArrivalPointGroupId.options[index].value;
}}
