var params = {
  wmode: "transparent",
  allowscriptaccess:"always",
  loop: "false",
  play: "true"
}


$(function(){
	// HIDE ALL ELEMENTS VIA NO_JS CLASS
	//alert("looo");
	if($(".no_js").length > 0) $(".no_js").hide();
	if($(".yes_js").length > 0) $(".yes_js").show();
	
	
	
	// EMBED SWFs ON HOME PAGE
	if($("#home_flash_div").length > 0){
		closeSWFs();
		swfobject.embedSWF("larkspur_hotelsDropDown.swf", "swf1", "725", "325", "9.0.0", "expressInstall.swf", 0, params, {id:"larkspur_hotelsDropDown", name:"larkspur_hotelsDropDown"});
		swfobject.embedSWF("larkspur_restaurantsDropDown.swf", "swf2", "725", "325", "9.0.0", "expressInstall.swf", 0, params, {id:"larkspur_restaurantsDropDown", name:"larkspur_restaurantsDropDown"});
		cycleHomePage();
		$("#hotels").mouseover(function(){
			showHotelsFlash();		
		});
		$("#restaurants").mouseover(function(){
			closeSWFs();
		});
		$("#specialoffers").mouseover(function(){
			closeSWFs();
		});
		$("#meetings").mouseover(function(){
			closeSWFs();
		});
		$("#green").mouseover(function(){
			closeSWFs();
		});
		$("#headerContainer").mouseover(function(){
			closeSWFs();
		});
		$(".slide").show(); // show hidden slides - unobtrusive
		
	}
	// EMBED SWFs ON HOTELS PAGE
	if($("#hotels_flash_div").length > 0){
		swfobject.embedSWF("/larkspur-map/larkspur_map.swf", "swf1", "725", "325", "9.0.0", "expressInstall.swf", 0, params, {id:"larkspur_map", name:"larkspur_map"});
	}
	// RESTAURANTS PAGE
	if($("#restaurants_slide_div").length > 0){
		cycleRestaurantsPage();
		// RESTAURANT DROP DOWN REPLACES DETAILS FOR SELECTED RESTAURANT
		$(".rest_dropdown").change(function(){
				// hide then show selected restaurant details
				var selected_restaurant_id = $(this).val();
				if(selected_restaurant_id != "") {
					var restaraunt_selector = "#restaurant_details_" + selected_restaurant_id;
					$(".restaurant_details").hide();
					$(restaraunt_selector).show();
				}
			});
	}
	
	if($("#meetings_slide_div").length > 0){
		cycleMeetingsPage();
	}
    // // EMAIL focus/clear
    // if($(".email").length > 0){
    //  $(".email").attr("value","Enter Email Address");
    //  $(".email").focus(function(){
    //      if(this.value == "Enter Email Address"){
    //          this.value = "";
    //          $(this).css({color:"#000"})
    //      }   
    //  });
    // }
	// SEARCH focus/clear
	if($(".search").length > 0){
		$(".search").attr("value","Search");
		$(".search").focus(function(){
			if(this.value == "Search"){
				this.value = "";
				$(this).css({color:"#000"})
			}	
		});
	}
	
	// CONFIG RESERVATION FORM/DESTINATION UIs
	if($(".reservation_form").length > 0){
		$("#destination_reservation_div").hide();
		$("#reservation_radios").show();
		$(".destination_radio").click(
			function(){
					$("#destination_reservation_div").show();
					$("#hotel_reservation_div").hide();
					$(".destination_radio").attr("checked","checked");
				}
		);
		
		// SHOW RES FORM
		$(".hotel_radio").click(
			function(){
					$("#destination_reservation_div").hide();
					$("#hotel_reservation_div").show();
					$(".hotel_radio").attr("checked","checked");
				}
		).attr("checked","checked");
		
		// NAV TO DROPDOWN DESTINATION 
		$("#destination_select").change(function(){
			if($(this).val() != "") window.location = "/destinations/" + $(this).val()
			});
	}
	
	// MEETING AND EVENTS POPUPS - HANDLE IE's NON-SUPPORT FOR :Hover pseudo class
	// if ($(".hotels_list ul#hover").length > 0){
	// 	$(".hotels_list ul#hover li").hover(
	// 		function(){
	// 			$(this).addClass("ie_hover");
	// 		},
	// 		function(){
	// 			$(this).removeClass("ie_hover");
	// 		}
	// 	);
	// }
	
	// DATE PICKER CONFIG
   if($("#arrive").length > 0){
		$("#arrive").datepicker({minDate: "today",showOn: 'both', buttonImage: '/images/icon_calendar.gif',buttonImageOnly: true,
		onSelect: function(date_text) {
					validate_change();
				}});
		$("#depart").datepicker({hideIfNoPrevNext: true, minDate: $('#arrive').datepicker('getDate'),showOn: 'both',
		 	buttonImage: '/images/icon_calendar.gif',buttonImageOnly: true,	onSelect: function(date_text) {
							validate_change();
						} });
		
	}
	function validate_change(){
		var depart = $("#depart"); 
		var arrive = $("#arrive");
		var depart_date = depart.datepicker('getDate');
		var arrive_date = arrive.datepicker('getDate');
		if(depart_date <= arrive_date)
		{
			var newDate = new Date(arrive_date);
			newDate.setDate(newDate.getDate() + 1);
			depart.datepicker('setDate',newDate);
		}
	}
}); // end of jquery onload

function cycleHomePage(){
	$('#home_flash_div').cycle({
	       fx:        'fade',
	       delay:    0,
		   timeout: 4000,
	       cssBefore: { opacity: 1 },
	       animOut:   { opacity: 0 },
		   slideExpr: 'img'
	    });
}

function cycleRestaurantsPage(){
	$('#restaurants_slide_div').cycle({
	       fx:        'fade',
	       delay:    0,
		   timeout: 4000,
	       cssBefore: { opacity: 1 },
	       animOut:   { opacity: 0 },
		   slideExpr: 'img'
	    });
}
function cycleMeetingsPage(){
	$('#meetings_slide_div').cycle({
	       fx:        'fade',
	       delay:    0,
		   timeout: 4000,
	       cssBefore: { opacity: 1 },
	       animOut:   { opacity: 0 },
		   slideExpr: 'img'
	    });
}
function showHotelsFlash(){
	$('#home_flash_div').cycle('pause');
	 $("#outer_hotels").animate({height:"325px"});
	 $("#outer_restaurants").css({height:"0px"});
}


function showRestaurantsFlash(){
	$('#home_flash_div').cycle('pause');
	$("#outer_restaurants").animate({height:"325px"});
	$("#outer_hotels").css({height:"0px"});	
}


function closeSWFs(){
	$("#outer_hotels").css({height:"0px"});
	$("#outer_restaurants").css({height:"0px"});
	$("#outer_hotels").addClass("hidden");
	$("#outer_restaurants").addClass("hidden");
	$('#home_flash_div').cycle('resume');
}

function reservation_form_submit ( form ) {
	createLinkerUrl(form);
	
	var hotel_id = $("#hotel_select").val();
	var arrive_date =	$("#arrive").datepicker("getDate");
	var depart_date =	$("#depart").datepicker("getDate");
	var alt_url = $('#hotel_select :selected').attr("alt_reservation_url")

	if (hotel_id == ""){
		alert("Please select a hotel."); 
		return false;
	}
	if (alt_url != "") {
		window.open(alt_url, "Reservations");
		return false;
	}
	if (depart_date <= arrive_date){
		alert("Your departure date must be later than your arrival date.");
		return false;
	}
	
	var alt_dest = "";
	if (hotel_id == "11012" || hotel_id == "11158" ) {  //LL Bellevue, Renton
		alt_dest = "SEA";
	}
	else if (hotel_id == "11170" || hotel_id == "11009") {  //RiverPlace, LL Hillsboro
		alt_dest = "PDX";
	}
	else if (hotel_id == "11008" || hotel_id == "11159" || hotel_id == "11163") {  //LL Folsom, Roseville, Sacramento
		alt_dest = "SAC";
	}
	else if (hotel_id == "11169" || hotel_id == "11365" || hotel_id == "11160" || hotel_id == "11162" || hotel_id == "11010" || hotel_id == "11161") {   //LL Campbell, Milpitas, Sunnyvale, St. Claire, Toll House, Pruneyard
		alt_dest = "SJC";
	}
	else if (hotel_id == "17622" || hotel_id == "17233" || hotel_id == "11165" || hotel_id == "11164" || hotel_id == "16793") {  //Hotel Abri, LHUS, Villa Florence, LL SSF, Lodge at Tiburon
		alt_dest = "BAY";
	}
	else {
		alt_dest = "";  //Belamar Hotel, Casa Munras, LL Pleasnton (doesn't have alt_dest)
	}
	if(alt_dest == ""){
		$("#altdest").remove(); // removed hidden field so that there will not be an empty altdest attr
	}
	else {
		$("#altdest").attr("value", alt_dest);
	}
	
	return formLinker(form);
}

// For use with Flash
function pageTracker_link ( url ) {
	pageTracker._link(url);
}
