/* ---------------------------------------------------------------------------------------------------- */
/* =bellevue-palace.js */
/* ---------------------------------------------------------------------------------------------------- */

/* -------------------------------------------------- */
/* =DropNavigation */

var DropNavigation = new Class({
	initialize: function(elements){
		this.timer = null;
		this.active = null;
		this.elements = $$(elements);
		this.elements.each(function(el){
			el.addEvents({
				'mouseenter': this.show.pass(el,this),
				'mouseleave': this.leave.pass(el,this)
			});
		},this);
	},
	show: function(element){
		this.timer = $clear(this.timer);
		if (this.active === element) return false;
		if (this.active) this.hide(this.active);
		this.active = element;
		var img = element.getElement('img');
		if (!img.getProperty('src').test('_hover')) {
			img.setProperty('src',img.getProperty('src').replace('.','_hover.'));
			img.$tmp.hovered = true;
		}
		var subnav = element.getElement('ul');
		if (subnav) subnav.setStyle('display','block');
	},
	
	leave: function(element){
		this.timer = this.hide.delay(500,this,element);
	},
	
	hide: function(element){
		var img = element.getElement('img');
		if (img.$tmp.hovered) {
			img.setProperty('src',img.getProperty('src').replace('_hover.','.'));
			img.$tmp.hovered = false;
		}
		var subnav = element.getElement('ul');
		if (subnav) subnav.setStyle('display','none');
		this.active = null;
	}
});

window.addEvent('domready',function(){
	new DropNavigation($$('ul#mainnav-container li.main'));
});


/* -------------------------------------------------- */
/* =ImageHover */

var ImageHover = new Class({
	initialize: function(elements,options){
		this.elements = $$(elements);
		this.options = options;
		this.elements.each(function(el){
			el.addEvents({
				'mouseover': this.set.pass(el,this),
				'mouseout': this.remove.pass(el,this)
			});
		},this);
	},
	set: function(element){
		if (!element.getProperty('src').test(this.options.extension)) {
			element.setProperty('src',element.getProperty('src').replace('.',this.options.extension+'.'));
			element.$tmp.hovered = true;
		}
	},
	remove: function(element){
		if (element.$tmp.hovered) {
			element.setProperty('src',element.getProperty('src').replace(this.options.extension+'.','.'));
			element.$tmp.hovered = false;
		}
	}
});

window.addEvent('domready',function(){
	//new ImageHover($$('#mainnav-container img'),{ extension: '_hover' });
	new ImageHover($$('#footer-container img'),{ extension: '_hover' });
});


/* -------------------------------------------------- */
/* =tooltips */

var tooltips = {
	
	init: function () {
		this.tips = $ES('.tooltip');
		this.tips.each(function (tip) {
			tip.addEvent('mouseover', this.showTip.bindAsEventListener(this, tip));
			tip.addEvent('mousemove', this.adjustTip.bindAsEventListener(this, tip));
			tip.addEvent('mouseout', this.hideTip.pass(tip, this));
		}, this);
	},
	
	showTip: function (event, tip) {
		this.adjustTip(event, tip);
		tip.getElement('.tooltip-txt').setStyle('display', 'block');
	},
	
	adjustTip: function (event, tip) {
		var event = new Event(event);
		tip.getElement('.tooltip-txt').setStyles({
			'left': event.page.x + 20,
			'top': event.page.y + 10
		});
	},
	
	hideTip: function (tip) {
		tip.getElement('.tooltip-txt').setStyle('display', 'none');
	}
	
};

window.addEvent('domready', function () {
	tooltips.init();
});