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;
}

function tripadvisor(id) {
	
	$.ajax({
		url: "/assets/tripadvisor.php",
		type: 'GET',
		cache: true,
		dataType: 'json',
		success: function(data) {
			if (data) {
				$('#tripadvisor')
				.append('<a href="http://www.tripadvisor.com/' + data.url + '" class="ta-logo notxt" rel="nofollow" target="_blank" onclick="var s=s_gi(s_account);s.linkTrackVars=\'events,eVar12\';s.linkTrackEvents=\'event7\';s.events=\'event7\';s.eVar12=\'TripAdvisor\';(s.tl(this,\'e\',\'Website Referral\') );">Tripadvisor</a>')
				.append('<div><strong>TripAdvisor Traveler Rating:</strong></div>')
				.append('<div class="ta-rating r' + data.stars*2 + '"><div class="notxt" title="' + data.stars + ' of 5 stars"></div></div>')
				.append('<small>Based on ' + data.reviews + ' traveler reviews</small>');
			}
		},
		beforeSend: function(xhr) {
			xhr.setRequestHeader('X-HotelID', id);
		}
	});

}

function getScript(url, id) {
	var d = document, script = d.createElement('script'),
		fjs = d.getElementsByTagName('script')[0];
	script.type = 'text/javascript';
	script.id = id?id:Math.random();
	script.src = url;
	script.async = true;
	fjs.parentNode.insertBefore(script, fjs);
};

$(function(){
	$("#aerial-flash").css("display","none");
	$("#aerial-flyover").click(function(){
		if($("#aerial-flash").css("display")=="none"){
			$("#aerial-flash").css("display", "block");
			$.fn.colorbox({
				'href':'#aerial-flash',
				'open':true, 'inline':true,
				'width':'640px',
				'height':'436px',
				'onLoad':function(){
					$("#colorbox").css("background-color", "#000000");
					$("#cboxContent").css("background-color", "#000000");
					$("#cboxClose").css("background-image", "url(../images/colorbox-cross-black.gif)");
					$("#cboxTitle").remove();
				},
				'onComplete':function(){
					$("#cboxTitle").css("z-index", "1!important");
				},
				'onClosed':function(){$("#aerial-flash").css("display", "none");}
			});
		}
		else{
			$("#aerial-flash").css("display", "none");
		}
	});
	
	tripadvisor(1762915);
//	getScript('https://apis.google.com/js/plusone.js');
	
/*	$('.photo .inner').nivoSlider({
	    effect:'fold', //Specify sets like: 'fold,fade,sliceDown, random'
      slices:8,
      animSpeed:1000, //Slide transition speed
      pauseTime:5000,
      startSlide:0, //Set starting Slide (0 index)
      directionNav:false, //Next & Prev
      directionNavHide:false, //Only show on hover
      controlNav:false, //1,2,3...
      controlNavThumbs:true, //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(){
											var $lefty = $(".nivo-caption");
									    $lefty.animate({
									      left: parseInt($lefty.css('left'),10) == 0 ?
									        -$lefty.outerWidth() :
									        0
									    });
											
										},
      afterChange: function(){
											var $lefty = $(".nivo-caption");
									    $lefty.animate({
									      left: parseInt($lefty.css('left'),10) == 0 ?
									        $lefty.outerWidth() :
									        0
									    });
										},
      slideshowEnd: function(){}, //Triggers after all slides have been shown
      lastSlide: function(){}, //Triggers when last slide is shown
      afterLoad: function(){
										var $lefty = $(".nivo-caption");
								    $lefty.animate({
								      left: parseInt($lefty.css('left'),100) == 0 ?
								        $lefty.outerWidth() :
								        0
								    });
									} //Triggers when slider has loaded
  });*/

	$('#fx').coinslider({
		delay: 4500,
		height: 542,
		links: false,
		spw: 5,
		sph: 3,
		sDelay: 80,
		effect: 'rain',
		opacity: 1,
		navigation: false,
		hoverPause: false, // pause on hover
		width: 1400
	});
	
	$("a.colorbox").colorbox();
	$("a.colorbox-iframe").colorbox({width:"950px", height:"670px", iframe:true});
	$("a.colorbox-booking").colorbox({width:"950px", height:"470px", iframe:true});

/* EFFECTS */

//	$('body').append('<div id="eff"></div>');

//	var wwidth = $(document).width() / 2;	
//	var eff = $('#eff');

//	$('body').mousemove(function(e) { window.mX = e.pageX;});

//	eff.fadeOut(45);

//	function magicFade() {
//		wwidth = $(document).width() / 2;
//		op = Math.abs(wwidth - window.mX) / wwidth * .5;
//		eff.stop().fadeTo(100, op);
		// menu.css({'background-position': window.mX/100 + 'px 0'});
	
	//	document.title=window.mX;
//	}

//	setInterval(magicFade, 100);

	/* DATES */
	
	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=dark&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[rel="external"]').attr({'target':'_blank'});
	
	$('.booking select, #header .controls select, .form select').sSelect();
	$('.form select').parent().css("position", "relative");
	
	$('div.events-btn').hover(function(){
		$(this).children('ul').show();
	}, function(){
		$(this).children('ul').hide();
	});
	
	$("ul#main li, .button, #submit, .text").hover(
		 function () {
			$(this).addClass('hover');
		 }, 
		 function () {
			$(this).removeClass('hover');
		 }
	);
	
		$(".marriott_place_promo").hover(
		 function () {
			$(this).addClass('marriott_place_promo_hover');
			$(this).removeClass('marriott_place_promo');
		 }, 
		 function () {
			$(this).removeClass('marriott_place_promo_hover');
			$(this).addClass('marriott_place_promo');
		 }
	);
	
	if($("#googlemap").length) {
		
		$("#googlemap").mapfu({
      latitude: 39.766096,
      longitude: -86.16961,
			scrollwheel: false,
			data: [{
			    "hotel": {
			      "id":1,
			      "name":"JW Marriott Indianapolis",
			      "address":"10 South West Street",
			      "city":"Indianapolis",
			      "state":"IN",
			      "zip_code":"46204",
			      "country":"US",
			      "lat":39.766096,
			      "lng":-86.16961,
			      "phone_number":"317-822-8554",
						"fax":"317-822-8464"
			    }
			  }],
			zoom: 15,
			mapType: "roadmap",
			icon: {
        image: "images/pointer.png",
				shadow: "images/pointer-shadow.png"
      },
      title: function(item) {
        return "" + item.name + "";
      },
      html: function(item) {
        return "<h3>" + item.name + "</h3><p> " + item.address + "<br>" + item.city + ", " + item.state + " " + item.zip_code + "</p><p>Phone: " + item.phone_number + "</p>";
      }
    });
	}
	
	/** 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 });
		
		HeBS_Link_Checkin_Checkout_Inputs('#checkin', '#checkout');
	
	
	var close_xxx = function (event) {
			 event.stopPropagation();

		if ($(this).parents().filter(".booking").length == 0 && $(this).hasClass('booking') == 0) {
	
			$("#book-field").removeClass('opened');
			$(".more-field").hide();
			$("body *").unbind("click", close_xxx);
		}
	}
	
		
		$("#checkin").bind('dateSelected', function(){
			$(".booking").css("overflow","visible");
			$("#book-field").addClass('opened');
			$(".more-field").show();

			$("body *").click(close_xxx);
		});
		$("#checkout").bind('dateSelected', function(){
		$(".booking").css("overflow","visible");
			$("#book-field").addClass('opened');
			$(".more-field").show();

			$("body *").click(close_xxx);
		});
	
	$(".rates dt").click(function(){
		$(this).next('dd').slideToggle('100', function(){
			if($(".rates").attr("class") != "opened"){
				$(".rates").addClass("opened");
			} else if($(".rates").attr("class") == "opened"){
				$(".rates").removeClass("opened");
					alert('lala');
			}
		});
	});
	
	$(".mult input.radio").change(function(){
		$(".mult input.text").val("");
	});
	
	
	//	end of booking
	
	$('#exclusive_deals_yes').attr('checked','checked');
	
});
