// This file is automatically included by javascript_include_tag :defaults

var RevealNext = Behavior.create({

	initialize: function(content) {
		this.content = this.element.next(content);
		this.content.hide();
	},
		
	onclick: function() {
		this.element.hide();
		this.content.show();
		return false;
	}
	
});

Event.addBehavior({ 
	'#reserve-button': RevealNext('#orderform')
});

var ReloadTwoSelections = Behavior.create({
	
	initialize: function(first, second) {
		this.firstSelect = document.getElementById(first);
		this.secondSelect = document.getElementById(second);
		this.action_path = /^\/\w+\/\w+/.exec(document.location.pathname);
	},
	
	onchange: function() {
		first = this.firstSelect.options[this.firstSelect.selectedIndex].value || 0;
		second = this.secondSelect.options[this.secondSelect.selectedIndex].value || 0;
		document.location.pathname = this.action_path + '/' + first + '/' + second;
	}

})

Event.addBehavior({
	'#section_select': ReloadTwoSelections('section_select', 'state_select'),
	'#state_select': ReloadTwoSelections('section_select', 'state_select')
})

var ViewContentOnMouseover = Behavior.create({

	initialize: function(defaultTarget) {
		this.defaultTargetId = 'target_' + defaultTarget
		this.defaultTargetElement = document.getElementById(this.defaultTargetId);
		this.targetId = 'target_' + this.element.id;
		this.targetElement = document.getElementById(this.targetId);
		//Unexplainable IE oddity: 
		//Use Element.hide() instead of this.contentElelement
		//But only once, then it works again!
    //this.targetElement.hide();
    Element.hide(this.targetElement);
		this.defaultTargetElement.show();
	},
		
	onmouseover: function() {
		this.defaultTargetElement.hide();
		this.targetElement.show();
	},
	
	onmouseout: function() {
		this.targetElement.hide();
		this.defaultTargetElement.show();
	}

});

Event.addBehavior({
	'.currency_switch': ViewContentOnMouseover('currency_1'),
	'.image_switch': ViewContentOnMouseover('image_1')	
})


