var DropDownMenu = Class.create();

DropDownMenu.prototype = {
	initialize:function(menuElement) {
		menuElement.childElements().each(function(node){
			node.onmouseover = function() {
				node.addClassName('hover');
			}
			node.onmouseout = function() {
				node.removeClassName('hover');
			}
		});
	}
};

var CalendarChooser = Class.create();

CalendarChooser.prototype = {
	initialize:function(calendarOptions, calendarElement, monthLinks, monthContainers, yearLinks) {
		this.calendarElement = calendarElement;
		
		this.currentYear = $(calendarOptions).firstDescendant().identify();
		this.currentMonth = $(this.currentYear+'_months').firstDescendant().identify();
		
		$$('.'+monthContainers).each(function(container){
			container.hide();
		});
		
		$(this.currentMonth).addClassName('active');
		$(this.currentYear).addClassName('active');
		$(this.currentYear+'_months').show();
		
		$$('.'+monthLinks).each(function(Link){
			Link.onclick = function() {
				this.getCalendar(Link.readAttribute('href'),Link.up().identify());
				return false;
			}.bind(this);
		}.bind(this));
		
		$$('.'+yearLinks).each(function(yearLink){
			yearLink.onclick = function() {
				this.showYear(yearLink.up().identify());
				return false;
			}.bind(this);
		}.bind(this));
	},
	
	getCalendar:function(urlToGet,elementToActivate){
		/*alert('Hello');*/
		new Ajax.Updater(this.calendarElement, urlToGet, {method:'get'});
		$(this.currentMonth).removeClassName('active');
		$(elementToActivate).addClassName('active');
		this.currentMonth = elementToActivate;
	},
	
	showYear:function(year){
		$(this.currentYear).removeClassName('active');
		$(this.currentYear+'_months').hide();
		$(year).addClassName('active');
		$(year+'_months').show();
		this.currentYear = year;
	}
};

function addDates(result, form) {
	dateArray = $('fullArrivalDate').value.split("/");
	$('arriveMonth').value = dateArray[0];
	$('arriveDate').value = dateArray[1];
	$('arriveYear').value = dateArray[2];
	if (result) {$('bookNow').submit();}
}

//preloader for images, fires immeadiatly

var preloadedImages = new Array('nav-waterpark-on.png','nav-lodging-on.png','nav-kids-on.png','nav-gallery-on.png','nav-parites-on.png','nav-hours-on.png','nav-tickets-on.png','nav-ground-arrow.png','nav-ground-drop.png','nav-ground-drop-footer.png');

preloadedImages.each(function(image){
	var preload = new Image();
	preload.src = 'http://www.avalanchebay.com/2009/GlobalAssets/images/'+image;
});