var EventImages = Class.create();
EventImages.prototype = {
	initialize: function() {
		this.swapImageHandler = this.swapImage.bindAsEventListener(this);
		this.swapImageClickHandler = this.swapImageClick.bindAsEventListener(this);
		this.restoreDefaultHandler = this.restoreDefault.bindAsEventListener(this);
		this.registerEvents();
	},
	
	registerEvents: function() {
		var links = $$('div.eventImages a');
		var banner = $$('div.eventImages');
		
		if ((banner != null) && (typeof(banner[0]) != "undefined")) {
			Event.observe(banner[0], 'mouseout', this.restoreDefault); 
		}
		
		for ( var x = 0 ; x < links.length ; x++ ) {
			Event.observe(links[x], 'mouseover', this.swapImageHandler);
			Event.observe(links[x], 'click', this.swapImageClickHandler);
			
			var image = new Image;
			image.src = links[x].getAttribute('href');
		}
	},
	
	restoreDefault: function(e) {
		var element = Event.element(e);
		var hero = $$('img.hero');
		if (hero != null) {
			hero = hero[0];
			if ( hero.getAttribute('rel') != null ) {
				hero.src = hero.getAttribute('rel');
			}
		}
	},
	
	swapImage: function(e) {
		var element = Event.element(e);
		var hero = $$('img.hero');
		if (hero != null) {
			hero = hero[0];
			hero.src = element.up().getAttribute('href');
		}
	},
	
	swapImageClick: function(e) {
		Event.stop(e);
	}
}

Event.observe(window, 'load', function() { new EventImages(); });

