var m = MochiKit;
var CA = {
	init: function() {
		this.loading.hide();

		var fxOptions = {duration:500, fps:30, unit:'', transition:Fx.Transitions.sineInOut};
		this.hoverAreas.each(function(hoverArea) { hoverArea.hover.fadeHover = new Fx.FadeHover($(hoverArea.hover), hoverArea.trigger, fxOptions); });
	},
	goToUrl: function(url, wnd) {
		(typeof(wnd) != "undefined" ? wnd : window).location.href = url;
	},
	wireGalleryEntriesHover: function() {
		$S('.GalleryEntry').action({
			onmouseover: function() { this.addClass('GalleryEntryHover'); },
			onmouseout: function() { this.removeClass('GalleryEntryHover'); }
		});
	},
	ieSucks: function() {
		//alert('ieSucks');
		var homePageHref = $('BackButtonLink');
		var backButtonOnClickFn = this.goToUrl;
		// IE doesn't grok div nested in anchor, follows the standard, simply amazing, have to wire onClick
		$S('.backButton').action({onclick: function() { backButtonOnClickFn(homePageHref); }});
	}
};
CA.loading = {
	done: false,
	hide: function() {
		this.done = true;
		$('Body').removeClass('loading');
		$('Content').removeClass('notdisplayed');
		$('Loading').addClass('notdisplayed');
	},
	show: function() {
		if (!this.done) {
			$('Body').addClass('loading');
			$('Loading').removeClass('notdisplayed');
			$('Content').addClass('notdisplayed');
		}
	}
};
Fx.FadeHover = Fx.Style.extend({
	initialize: function(el, triggers, options) {
		this.parent(el, 'opacity', options);
		this.set(0.01);
		triggers.each(
			function(trigger) {
				trigger = $(trigger);
				trigger.addEvent('mouseover', function() { this.fadeUp(); }.bind(this) );
				trigger.addEvent('mouseout', function() { this.fadeDown(); }.bind(this) );
			}.bind(this)
		);
	},
	fadeUp: function(){
		this.clearTimer();
		this.goTo(1);
	},
	fadeDown: function(){
		this.clearTimer();
		this.goTo(0.01);
	}
	/*simplified,untested
    var fx = el.effect('opacity', {wait: false}).set(0.01);
    el.addEvent('mouseover', fx.goTo.pass(1).bind(fx));
    el.addEvent('mouseout', fx.goTo.pass(0.01).bind(fx));
	*/
});
