var languageSelector = new Class({
	Implements: Options,

	options: {
		element: false,
		container: false,
		delay: 500,
		offset: {
			x: 15,
			y: 10
		}
	},

	initialize: function(options) {
		this.setOptions(options);

		if(this.hasElements()) {
			this.initializeElements();
			this.initializeEvents();
		}
	},

	hasElements: function() {
		if($type(document.id(this.options.container)) != "object") {
			return true;
		}
	},

	initializeElements: function() {
		this.container = document.id(this.options.container);
	},

	initializeEvents: function() {
		document.id(this.options.element).addEvent("click", this.showContainer.bindWithEvent(this));
//		document.id(this.options.element).addEvent("mouseover", this.showContainer.bindWithEvent(this));
//		document.id(this.options.element).addEvent("mousemove", this.moveContainer.bindWithEvent(this));
//		document.id(this.options.element).addEvent("mouseout", this.runTimer.bindWithEvent(this));

		this.container.addEvent("mouseenter", this.cancelTimer.bindWithEvent(this));
		this.container.addEvent("mouseleave", this.runTimer.bindWithEvent(this));
	},

	showContainer: function(event) {
		this.container.setStyle("display", "block");
		this.moveContainer(event);
	},
	
	moveContainer: function(event) {
		this.container.setStyles({
			"position": "absolute",
			"top": screen.height / 2 - 200,
			"left": 300
		});
	},	
	
/*
	moveContainer: function(event) {
		this.container.setStyles({
			"position": "absolute",
			"top": "100px",
			"left": "250px"
		});
	},
*/
	runTimer: function() {
		this.timer = this.disposeContainer.bind(this).delay(this.options.delay);
	},

	cancelTimer: function() {
		$clear(this.timer);
	},

	hideContainer: function(event) {
		this.disposeContainer();
	},

	disposeContainer: function() {
		this.container.setStyle("display", "none");
	}
});

window.addEvent("domready", function() {
	new languageSelector({
		element: "language",
		container: "language-container",
		delay: 2000
	});
});
