// Dynamically compute the current year and add 2 more years
var now = new Date;
var thisYear = now.getUTCFullYear();
var nextYear = thisYear + 2;
var thisMonth = now.getMonth() + 1;
var thisDay = now.getUTCDate();


function currentDate() { document.write("Todays Date: " + thisMonth +  "/"  + thisDay + "/" + thisYear); }

function advResTrack(arri, lenStay, r, goal) {
	_gaq.push(['_trackPageview',goal]);
	var arriDate = new Date(arri.value);
	var arriY = arriDate.getFullYear();
	var arriM = arriDate.getMonth();
	arriM = arriM + 1;
	var arriYM = arriM + '/' + arriY;
	var LOS = lenStay.options[lenStay.selectedIndex].value;
	var roomNites = LOS * r;

	_gaq.push(['_trackEvent', 'Reservation Requests', arriYM, 'from ' + arri.value, roomNites]);
	return true;
}

function specials_res(specials_name) {
	_gaq.push(['_trackPageview','/special-res']);
	_gaq.push(['_trackEvent', 'Special Res Requests', specials_name]);
	return true;
}

$(document).ready(function(){ //jQuery functions will need to be placed inside the ready event so that they are executed when the document DOM has been fully loaded and ready to be manipulated.
	
		if($(".equalHeight").length > 0) {
			$(".equalHeight").equalHeight();
		}
		
		//prevents link tags from executing their default behavior
		$("a.preventDefault").click(function(event) {
		  event.preventDefault();
		});

		
		//Reservation Widget
		$("#startDate").datepicker({
			showOn: "button", 								 
			buttonImage: "/css/images/reservation_wdgt/icn-calendar.gif", 
			buttonImageOnly: true,
			buttonText: 'Date',
			changeMonth: true,
			changeYear: true,
			yearRange: thisYear + ":" + nextYear, //see date calculation variables above
			//yearRange: "2008:2018",
			monthRange: "January:December",
			dateFormat: 'm/d/yy'
		});
		
	
	
	// Suckerfish Menu (Main Nav)
	if($("ul.sf-menu").length > 0) {
		$("ul.sf-menu").supersubs({ 
				minWidth:    12,   // minimum width of sub-menus in em units 
				maxWidth:    27,   // maximum width of sub-menus in em units 
				extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
								   // due to slight rounding differences and font-family 
			}).superfish();  // call supersubs first, then superfish, so that subs are 
							 // not display:none when measuring. Call before initialising 
							 // containing tabs for same reason.
	}
	
	
	//global image rollover
	if ($(".rollover").length > 0) {
		$(".rollover").hover(
			 function()
			 {
			  this.src = this.src.replace("_off","_on");
			 },
			 function()
			 {
			  this.src = this.src.replace("_on","_off");
			 }
		);
	} 
	
	// Specials Panel on Home page
	if ($('div#specialsPreview').length > 0) {
		$('div#specialsPreview').bxSlider({
			alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
			controls: false,                 // determines if default 'next'/'prev' controls are displayed
			speed: 500,                     // amount of time slide transition lasts (in milliseconds)
			pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
			pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
			pager_short_separator: ' / ',   // text to be used to separate the short pager
			margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
											// bottom margin is applied. example: margin: 50
			next_text: 'next',              // text to be displayed for the 'next' control
			next_image: '',                 // image to be used for the 'next' control
			prev_text: 'prev',              // text to be displayed for the 'prev' control
			prev_image: '',                 // image to be used for the 'prev' control
			auto: true,                    // determines if slides will move automatically
			pause: 5000,                    // time between each slide transition (auto mode only) 
			auto_direction: 'next',         // order in which slides will transition (auto mode only)
			auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
			auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
			ticker: false,                  // determines if slideshow will behave as a constant ticker
			ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
			ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
			ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
			stop_text: 'stop',              // text to be displayed for the 'stop' control
			start_text: 'start',            // text to be displayed for the 'start' control
			wrapper_class: 'bxslider_wrap'  // class name to be used for the outer wrapper of the slideshow
		});
	}
	
	// Masthead transitions
	if ($('#slideshow').length > 0) {
		$('#slideshow').cycle({ 
			delay:  5000, 
			speed:  1000,
			timeout: 2500
		});
	}
	
	
	
	// Pikachoose Gallery
	if($("#pikame").length > 0) {
		$("#pikame").PikaChoose();
	
			$("#pikame").jcarousel({scroll:4,					
				initCallback: function(carousel) 
				{
					$(carousel.list).find('img').click(function() {
						//console.log($(this).parents('.jcarousel-item').attr('jcarouselindex'));
						carousel.scroll(parseInt($(this).parents('.jcarousel-item').attr('jcarouselindex')));
					});
				}
				
		});
	}
	
	if($('.accordGallContainer').length > 0) {
		// Gallery via jqgalscroll
		
		if($('.jqGallery').length > 0) {
			$('.jqGallery').jqGalScroll({
				width: 380,
				height: 252,
				ease: null,
				speed:500,
				titleOpacity : .60,
				direction : 'horizontal' // vertical horizontal diagonal
			});
		}
		
		if($('.jqGallery2').length > 0) {
			$('.jqGallery2').jqGalScroll({
				width: 580,
				height: 383,
				ease: null,
				speed:500,
				titleOpacity : .60,
				direction : 'horizontal' // vertical horizontal diagonal
			});
		}
		
		// Accordian Widgets
		$(".details").hide();
		
		// toggle section details		
		$("#haciendaSuites .button").click(function(event) {
				event.preventDefault();
				$("#haciendaSuites .details").toggle("blind", function(){
					var txt = $("#haciendaSuites .details").is(':visible') ? 'close' : 'learn more';
					$("#haciendaSuites .button").text(txt);
				});
				return false;
		});
		
		$("#casitaSuites .button").click(function(event) {
				event.preventDefault();
				$("#casitaSuites .details").toggle("blind", function(){
					var txt = $("#casitaSuites .details").is(':visible') ? 'close' : 'learn more';
					$("#casitaSuites .button").text(txt);
				});
				return false;
		});
		
		$("#posadaRooms .button").click(function(event) {
				event.preventDefault();
				$("#posadaRooms .details").toggle("blind", function(){
					var txt = $("#posadaRooms .details").is(':visible') ? 'close' : 'learn more';
					$("#posadaRooms .button").text(txt);
				});
				return false;
		});
		
		$("#otero .button").click(function(event) {
				event.preventDefault();
				$("#otero .details").toggle("blind", function(){
					var txt = $("#otero .details").is(':visible') ? 'close' : 'learn more';
					$("#otero .button").text(txt);
				});
				return false;
		});

		
		// dining page
		$("#stables .button").click(function(event) {
				event.preventDefault();
				$("#stables .details").toggle("blind", function(){
					var txt = $("#stables .details").is(':visible') ? 'close' : 'learn more';
					$("#stables .button").text(txt);
				});
				return false;
		});
		
		
		// golf page
		$("#anzaNine .button").click(function(event) {
				event.preventDefault();
				$("#anzaNine .details").toggle("blind", function(){
					var txt = $("#anzaNine .details").is(':visible') ? 'close' : 'learn more';
					$("#anzaNine .button").text(txt);
				});
				return false;
		});
		
		$("#ranchoNine .button").click(function(event) {
				event.preventDefault();
				$("#ranchoNine .details").toggle("blind", function(){
					var txt = $("#ranchoNine .details").is(':visible') ? 'close' : 'learn more';
					$("#ranchoNine .button").text(txt);
				});
				return false;
		});
		
		$("#oteroNine .button").click(function(event) {
				event.preventDefault();
				$("#oteroNine .details").toggle("blind", function(){
					var txt = $("#oteroNine .details").is(':visible') ? 'close' : 'learn more';
					$("#oteroNine .button").text(txt);
				});
				return false;
		});
		
		// wedding - ballrooms and spaces
		$("#weddingChapel .button").click(function(event) {
				event.preventDefault();
				$("#weddingChapel .details").toggle("blind", function(){
					var txt = $("#weddingChapel .details").is(':visible') ? 'close' : 'view specs';
					$("#weddingChapel .button").text(txt);
				});
				return false;
		});
		
		$("#geronimoBallroom .button").click(function(event) {
				event.preventDefault();
				$("#geronimoBallroom .details").toggle("blind", function(){
					var txt = $("#geronimoBallroom .details").is(':visible') ? 'close' : 'view specs';
					$("#geronimoBallroom .button").text(txt);
				});
				return false;
		});
		
		$("#oteroLawn .button").click(function(event) {
				event.preventDefault();
				$("#oteroLawn .details").toggle("blind", function(){
					var txt = $("#oteroLawn .details").is(':visible') ? 'close' : 'view specs';
					$("#oteroLawn .button").text(txt);
				});
				return false;
		});
		
		$("#outdoorLocation .button").click(function(event) {
				event.preventDefault();
				$("#outdoorLocation .details").toggle("blind", function(){
					var txt = $("#outdoorLocation .details").is(':visible') ? 'close' : 'view specs';
					$("#outdoorLocation .button").text(txt);
				});
				return false;
		});
		
		// meetings facilities
		$("#geronimoBallroom2 .button").click(function(event) {
				event.preventDefault();
				$("#geronimoBallroom2 .details").toggle("blind", function(){
					var txt = $("#geronimoBallroom2 .details").is(':visible') ? 'close' : 'view specs';
					$("#geronimoBallroom2 .button").text(txt);
				});
				return false;
		});
		
		$("#geronimoPatio .button").click(function(event) {
				event.preventDefault();
				$("#geronimoPatio .details").toggle("blind", function(){
					var txt = $("#geronimoPatio .details").is(':visible') ? 'close' : 'view specs';
					$("#geronimoPatio .button").text(txt);
				});
				return false;
		});
		
		$("#apachePatio .button").click(function(event) {
				event.preventDefault();
				$("#apachePatio .details").toggle("blind", function(){
					var txt = $("#apachePatio .details").is(':visible') ? 'close' : 'view specs';
					$("#apachePatio .button").text(txt);
				});
				return false;
		});
		
		$("#tackRoom .button").click(function(event) {
				event.preventDefault();
				$("#tackRoom .details").toggle("blind", function(){
					var txt = $("#tackRoom .details").is(':visible') ? 'close' : 'view specs';
					$("#tackRoom .button").text(txt);
				});
				return false;
		});
		
		$("#oteroMeeting .button").click(function(event) {
				event.preventDefault();
				$("#oteroMeeting .details").toggle("blind", function(){
					var txt = $("#oteroMeeting .details").is(':visible') ? 'close' : 'view specs';
					$("#oteroMeeting .button").text(txt);
				});
				return false;
		});
		
		$("#missionBallroom .button").click(function(event) {
				event.preventDefault();
				$("#missionBallroom .details").toggle("blind", function(){
					var txt = $("#missionBallroom .details").is(':visible') ? 'close' : 'view specs';
					$("#missionBallroom .button").text(txt);
				});
				return false;
		});
	}
	
	//tab interface
	$("#tabs").tabs({
		ajaxOptions: {
			error: function(xhr, status, index, anchor) {
				$(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible.");
			}
		}
	});
	
	//buttons
	$("a.buttonLink, .form input:submit").button();
	//$("a.button").click(function() { return false; });
	$( ".radioButtons" ).buttonset();
	
	//colorbox
	if($('a.colorbox').length > 0) {
		$("a.colorbox").colorbox();
	}
	
	//spa and salon
	if($('.services').length > 0)
	{
		
		$(".details").hide();
		
		//massage therapy
		$("#massageTherapy img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#massageTherapy .details:hidden').length > 0) {
				$('#massageTherapy .details').slideDown();
				$(this).attr('src','../../images/spa_salon/spa/treatments/massage_hdr_active.jpg');
			} else { 
				$('#massageTherapy .details').slideUp();
				$(this).attr('src','../../images/spa_salon/spa/treatments/massage_hdr_on.jpg');
			}               
		});
		
		//body treatments
		$("#bodyTreatments img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#bodyTreatments .details:hidden').length > 0) {
				$('#bodyTreatments .details').slideDown();
				$(this).attr('src','../../images/spa_salon/spa/treatments/body_hdr_active.jpg');
			} else { 
				$('#bodyTreatments .details').slideUp();
				$(this).attr('src','../../images/spa_salon/spa/treatments/body_hdr_on.jpg');
			}               
		});
		
		//skin care
		$("#skinCare img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#skinCare .details:hidden').length > 0) {
				$('#skinCare .details').slideDown();
				$(this).attr('src','../../images/spa_salon/spa/treatments/skin_hdr_active.jpg');
			} else { 
				$('#skinCare .details').slideUp();
				$(this).attr('src','../../images/spa_salon/spa/treatments/skin_hdr_on.jpg');
			}               
		});
		
		//hair services
		$("#hairServices img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#hairServices .details:hidden').length > 0) {
				$('#hairServices .details').slideDown();
				$(this).attr('src','../../images/spa_salon/salon/services/hair_services_hdr_active.jpg');
			} else { 
				$('#hairServices .details').slideUp();
				$(this).attr('src','../../images/spa_salon/salon/services/hair_services_hdr_on.jpg');
			}               
		});
		
		//nailServices
		$("#nailServices img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#nailServices .details:hidden').length > 0) {
				$('#nailServices .details').slideDown();
				$(this).attr('src','../../images/spa_salon/salon/services/nail_services_hdr_active.jpg');
			} else { 
				$('#nailServices .details').slideUp();
				$(this).attr('src','../../images/spa_salon/salon/services/nail_services_hdr_on.jpg');
			}               
		});
		
		//day experiences
		$("#dayExperiences img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#dayExperiences .details:hidden').length > 0) {
				$('#dayExperiences .details').slideDown();
				$(this).attr('src','../../images/spa_salon/salon/services/day_experiences_hdr_active.jpg');
			} else { 
				$('#dayExperiences .details').slideUp();
				$(this).attr('src','../../images/spa_salon/salon/services/day_experiences_hdr_on.jpg');
			}               
		});
		
		//wedding packages
		$("#weddingPackages img.rollover").click(function () {
			//using this method since jquery toggle method bugs out when trying to manipulate more than one selector
			if ($('#weddingPackages .details:hidden').length > 0) {
				$('#weddingPackages .details').slideDown();
				$(this).attr('src','../../images/spa_salon/salon/services/wedding_packages_hdr_active.jpg');
			} else { 
				$('#weddingPackages .details').slideUp();
				$(this).attr('src','../../images/spa_salon/salon/services/wedding_packages_hdr_on.jpg');
			}               
		});
		
		
	}
	
	
	
  	 
}); //end of ready event
