/**
 * Controller class
 * 
 * base class for page specific controllers
 */
var Controller = new Class({
	
	Implements: Options,
	
	options: {
	},
	
	initialize: function() {
		
	},
	
	popUp: function(ev) {
		window.open(ev.target.href);
		ev.preventDefault();
	}
	
});

/**
 * HomeController class
 * 
 * features of the homepage
 */
var HomeController = new Class({
	
	Extends : Controller,
	
	initialize: function() {
		this.parent();
		var imgs = [
			{src: 'images/slideshow/homepage1.jpg', alt: ''},
			{src: 'images/slideshow/homepage2.jpg', alt: ''},
			{src: 'images/slideshow/homepage3.jpg', alt: ''},
			{src: 'images/slideshow/homepage4.jpg', alt: ''}
		]
		this.slideshow = new Slideshow('slideshow', {delay : 5, images : imgs});
	}
	
});

/**
 * CollectionController
 * 
 * changing collection image
 */
var CollectionController = new Class({
	
	Extends : Controller,
	
	initialize: function() {
		
		this.main = $('mainImage');
		this.description = $('description');
		this.reference = $('reference');
		
		$('images').getElements('a').each(function(link) {
			link.addEvent('click', this.display.bindWithEvent(this, link));
		}, this);
	},
	
	display: function(ev, link) {
		ev.preventDefault();
		this.main.src = link.href;
		this.description.set('text', link.title);
		this.reference.set('text', link.getElement('img').alt);
	}
	
});

/* initialisation */

Controller.setup = function() {
	
	switch (document.body.id) {
		case 'homepage':	return new HomeController();
		case 'collection':	return new CollectionController();
		default:			return new Controller();
	}
	
}

var app;
window.addEvent('domready', function() {
	app = Controller.setup();
});

