$(document).ready(function() {
	$("#nav_links img").each(function() {
			$("<img>").attr("src", $(this).attr("src").replace(/.gif$/ig,"_sel.gif"));
	});
		
	$("#nav_links a").each(function() {
		$(this).hover(function(){
			imgsrc = $(this).children("img").attr("src");		
			if (!imgsrc.match(/_sel/)) {
				$(this).children("img").attr("src", imgsrc.replace(/.gif$/ig,"_sel.gif"));
			}

		},
		function(){
			$(this).children("img").attr("src", imgsrc);
		});

		$(this).click(function() {
			imgsrc = $(this).children("img").attr("src");
			if (imgsrc.match(/_sel/)) {
				$(this).children("img").attr("src", imgsrc.replace(/.gif$/ig,"_sel.gif"));
			}
		});
	});
	
	$("#content_body a").click(function() {
		if ($(this).attr("href") == "where") {
			alert("where does this link go?");
			return false;
		}
		return true;
	});
	
	if (typeof setupZoom != "undefined") setupZoom();
	
	if ($("#arrival_date")) $("#arrival_date").date_input({
	  stringToDate: function(string) {
	    var matches;
	    if (matches = string.match(/^(\d{2,2})\/(\d{2,2})\/(\d{4,4})$/)) {
	      return new Date(matches[3], matches[1]-1, matches[2]);
	    } else {
	      return null;
	    };
	  },

	  dateToString: function(date) {
	    var month = (date.getMonth() + 1).toString();
	    var dom = date.getDate().toString();
	    if (month.length == 1) month = "0" + month;
	    if (dom.length == 1) dom = "0" + dom;
			
	    return month + "/" + dom + "/" + date.getFullYear();
	  }
	});
});

function decrypt(s) {
	var i, c, d, b; d = "";
	for (i=0; i < s.length; i++) {
		c = String.fromCharCode(((s.charCodeAt(i)+16) % 96) + 32);
		d = d.concat(c);
	}
	return d;
}

var currMonth = 1;
var dateIndex = new Date().getMonth() - 1;

var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

function nextmonth() {
	if (currMonth < 12) {
		var idx = (dateIndex+currMonth+1) % 12;
		
		currMonth++;
		$('#calendar').attr("src", 'http://www2.webervations.com/calendars/calendar_9705_avail'+currMonth+'.gif');
		
		var last_idx = idx - 1;
		if (last_idx < 0) last_idx = 11;
		$('#prev_month').attr('innerHTML', "&lsaquo; " + months[last_idx] );
		
		if (currMonth < 12) {
			$('#next_month').attr('innerHTML', months[(idx+1)%12] + " &rsaquo;");
		}
		else {
			$('#next_month').attr('innerHTML', '');
		}
	}
	return false;
}

function lastmonth() {
	if (currMonth > 1) {
		var idx = (dateIndex+currMonth-1) % 12;
		
		currMonth--;
		$('#calendar').attr("src", 'http://www2.webervations.com/calendars/calendar_9705_avail'+currMonth+'.gif');
		
		if (currMonth > 1) {
			var last_idx = idx - 1;
			if (last_idx < 0) last_idx = 11;
			$('#prev_month').attr('innerHTML', "&lsaquo; " + months[last_idx] );
		}
		else {
			$('#prev_month').attr('innerHTML', '');
		}
		
		$('#next_month').attr('innerHTML', months[(idx+1)%12] + " &rsaquo;");
	}
	return false;
}
