function emailCheck(emailFormField, showerror) {

	var txt = emailFormField.value;
	var error = "";

	var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	var phoneRe = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/

	if (!(emailRe.test(txt))) {
		error = "Please enter a valid email address.\n";
	}

	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (txt.match(illegalChars)) {
		error += "The email address contains illegal characters.\n";
	}

	if (error.length > 0) {
		if (showerror) {
			emailFormField.focus();
			alert(error);
		}
		return false;
	}
	return true;
}



var log = true;
var src = 'images/photos/gallery/';
var smpref = 'sm';
var phpref = 'ph';

function getData(url, cat){
	
	var result = $.getJSON(url, function(data){
		
		var imgs = [];
		
		$.each(data[cat], function(i, val) {
			imgs.push(val);
		});
		
		initImgs(imgs);
		
	});
	
	
}

/*image gal*/
function initImgs(imgs){

	var div = $("<div/>");
	
	for(var i=0; i< imgs.length; i++){
		div.append('<a href="'+src+phpref+imgs[i]+'"><img src='+src+smpref+imgs[i]+' alt=""></a>');
	}
	$.when( 
		div.galleria({
			data_source: div,
			transitionSpeed: 300,
			queue: false,
			preload: 3,
			imageCrop: 'width',
			imagePan: true,
			width:780,
			height: 475,
			thumbFit:false,
			thumbCrop:true
		})
	).then(function(){
		$.fancybox({
			padding: 10,
			autoDimensions: false,
			centerOnScroll: true,
			titleShow: false,
			width: 780,
			height: 475,
			overlayColor: '#222',
			content: div,
			onClosed: function(){
				$('iframe').css('visibility','visible');
				div.empty();
			},
			onStart: function(){
				$('iframe').css('visibility','hidden');
			}
		});
		
	});
}

$(function(){	
	
	
	$("a.gal").bind('click', function(event){
		event.preventDefault();
		var categ = $(this).attr('rev');
		
		getData('assets/gallery/gallery.json', categ);
		
	});
	
	
	if($(".fancybox").length) {
		$("a.fancybox").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200,
				'cyclic' : true,
				'centerOnScroll' : true,
				'overlayOpacity' : 0.8,
				'overlayColor' : '#fff',
				'overlayShow'	:	true,
				onClosed: function(){
					$('iframe').css('visibility','visible');
				},
				onStart: function(){
					$('iframe').css('visibility','hidden');
				}
			});
	}
	
	
	if($('#fx img').length > 1) {
		$('#fx').nivoSlider({
		    effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
	      slices:15,
	      animSpeed:500, //Slide transition speed
	      pauseTime:3000,
	      startSlide:0, //Set starting Slide (0 index)
	      directionNav:false, //Next & Prev
	      directionNavHide:false, //Only show on hover
	      controlNav:false, //1,2,3...
	      controlNavThumbs:false, //Use thumbnails for Control Nav
	      controlNavThumbsFromRel:false, //Use image rel for thumbs
	      controlNavThumbsSearch: '.jpg', //Replace this with...
	      controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
	      keyboardNav:false, //Use left & right arrows
	      pauseOnHover:true, //Stop animation while hovering
	      manualAdvance:false, //Force manual transitions
	      captionOpacity:1, //Universal caption opacity
	      beforeChange: function(){},
	      afterChange: function(){},
	      slideshowEnd: function(){}, //Triggers after all slides have been shown
	      lastSlide: function(){}, //Triggers when last slide is shown
	      afterLoad: function(){} //Triggers when slider has loaded
	  });
	}
	
	var current_url = $('#fb-index').attr("title");
	$('#fb-index').html('<iframe src="http://www.facebook.com/plugins/like.php?href=' +current_url+ '&amp;layout=standard&amp;show_faces=false&amp;width=530&amp;action=like&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" allowTransparency="true" class="facebook-like"></iframe>');
	
	$("#ping").after($('<input>').attr({'name':'pong','value':$("#ping").val(),'class':'hide'}));

	$('a[rel="external"], form.form-external').attr({'target':'_blank'});
	
	
	$("ul#top li, .button, #submit, .text").hover(
		 function () {
			$(this).addClass('hover');
		 }, 
		 function () {
			$(this).removeClass('hover');
		 }
	);
	
	if($("#googlemap").length>0){
				$("#googlemap").gMap({
					latitude:  32.79053279484778,
			    longitude: -117.25514620542526,
					markers: [{
						latitude: 32.79053279484778,
			    		longitude: -117.25514620542526,
						html: '<h3>Best Western Blue Sea Lodge</h3><p style="padding-bottom: 15px;">707 Pacific Beach Drive<br>San Diego, CA 92109<br>Local: 858.488.4700<br>Toll-Free Phone: 800.258.3732<br>Email: <a href="mailto:Reservations440@bestwestern-bluesea.com">Reservations440@bestwestern-bluesea.com</a><br><a href="http://maps.google.com/maps?f=d&geocode=&daddr=707 Pacific Beach Dr, San Diego, CA 92109-5028 (Best Western Blue Sea Lodge)&z=13" target="_blank">Get Directions</a></p>',
						popup: false
					}],
					zoom: 15,
					mapTypeControl : true,

		//			controls: ["GLargeMapControl3D", "GMapTypeControl"],
					scrollwheel: false,
					maptype: google.maps.MapTypeId.ROADMAP,
					icon:
					{
						image:              "images/pointer.png",
						iconsize:           [31, 39],
						shadow:              "images/pointer-shadow.png",
						shadowsize:         [31,39],
						iconanchor:         [10, 39],
						infowindowanchor:   [8, 2]
				}
			});
		}
	
	/** booking **/
	
		var HeBS_Link_Checkin_Checkout_Inputs = function HeBS_Link_Checkin_Checkout_Inputs_function(checkin_selector, checkout_selector) {
			Date.format = 'mm/dd/yyyy';
	
			
			
			$(checkin_selector).bind('dateSelected', function(e, selectedDate, $td, state) {
				var t = new Date(selectedDate);
				var dt = new Date.fromString($(checkin_selector).val());		
			    var edate = new Date.fromString($(checkout_selector).val());			
			    var one_day=1000*60*60*24;
			    var days_diff = Math.ceil((edate.getTime() - dt.getTime())/(one_day));
			    
			    if(edate.getTime() <= dt.getTime()) {
			        $(checkout_selector).val(t.addDays(1).asString());
			    }
			});
			
			$(checkout_selector).bind('dateSelected', function(e, selectedDate, $td, state) {
				var t = new Date(selectedDate);
				var dt = new Date.fromString($(checkin_selector).val());	
			    var edate = new Date.fromString($(checkout_selector).val());				
			    var one_day=1000*60*60*24;
			    var days_diff = Math.ceil((edate.getTime() - dt.getTime())/(one_day));
			    
			    var edate = new Date.fromString($(checkout_selector).val());			
			    if(edate.getTime() <= dt.getTime()) {
			        $(checkin_selector).val(t.addDays(-1).asString());
			    }		
			});
			
			var today = new Date();
			$(checkin_selector).val(today.asString());
			$(checkout_selector).val(today.addDays(1).asString());
			
		    $(checkout_selector).dpSetStartDate(today.asString());
		};
		
		$('#checkin, #checkout, .date-pick').datePicker({'clickInput' : true });
		var today = new Date();
		$('#checkin').val(today.asString());
		
		HeBS_Link_Checkin_Checkout_Inputs('#arrival', '#departure');
	//	end of booking
	
	if ($("#jquery_jplayer_1").length) {
		$("#jquery_jplayer_1").jPlayer({
			ready: function () {
				$(this).jPlayer("setMedia", {
					m4v: "http://www.bestwesternlighthouse.com/video/BestWesternLighthouseHotel.mp4",
					ogv: "http://www.bestwesternlighthouse.com/video/BestWesternLighthouseHotel.ogv",
					poster: "http://www.bestwesternlighthouse.com/video/BestWesternLighthouseHotel.jpg"
				
				});
			},
			swfPath: "js",
			supplied: "m4v, ogv"
		});
	}
		
});

