/**
 * Swart Advocatuur 
 * (c) 2006-2008 Omines - www.omines.com
 * 
 * All rights explicitly reserved - unauthorized reproduction strictly prohibited
 */

// Compatibility stuff
Element.implement({
	effect: function(property, options){
		return new Fx.Tween(this, $extend({property: property}, options));
	}
});

// Site class - main active content wrapper
var Site = {
	start: function()
	{
		// Check if we can use console.log, assuming no
		this.console		= false;
		if (window.console && window.console.firebug != '')
			this.console	= true;
		
		Filmstrip.initialize();
	},
	log: function(message, level)
	{
		if (!this.console)
			return;
		switch (level)
		{
			case 0:	console.log(message);	break;
			case 1:	console.info(message);	break;
			case 2: console.warn(message);	break;
			case 3: console.error(message);	break;
		}
	}
};

function Log(message)	{ Site.log(message, 0); }
function Info(message)	{ Site.log(message, 1); }
function Warn(message)	{ Site.log(message, 2); }
function Error(message)	{ Site.log(message, 3); }

var Filmstrip = {
	initialize: function()
	{
		if (!$('artwork-container'))
			return false;
		this.largeView		= $('artwork-image');
		this.thumbContainer	= $('artwork-filmstrip-container');
		this.thumbs			= $$('.filmstrip-image');

		this.thumbs.each(function (r, idx) { r.addEvent('click', function() { this.showImage(r, idx); }.bind(this)); }.bind(this));
		this.thumbs[0].fireEvent('click');
	},
	showImage: function (element, index)
	{
		this.thumbs.each(function (r) {
			r.removeClass('active');
		});
		var src = element.get('src').replace('/thumbnail/', '/');
		this.largeView.set('src', src);
		element.addClass('active');

		this.thumbContainer.scrollLeft	= (index * 158) / 2;
	}
};

var CharLimit = new Class({
	elementName:	null,
	elementContent: null,
	elementDisplay: null,
	limit:			2500,

	initialize: function(elementName) {
		if ($(elementName)) {
			this.elementName = elementName;
			this.elementContent = $(elementName);
			if ($('charLimit-' + elementName)) {
				this.elementDisplay = $('charLimit-' + elementName);
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
		/*this.elementContent.addEvent('change', function() {
			this.display();
		}.bind(this));*/
		this.elementContent.addEvent('keyup', function() {
			this.display();
		}.bind(this));
		this.elementContent.addEvent('paste', function() {
			this.display();
		}.bind(this));
		this.elementContent.addEvent('cut', function() {
			this.display();
		}.bind(this));
		//this.display();
	},

	display: function() {
		var len = $(this.elementName).get('value').length;
		this.elementDisplay.set('text', len+'/'+this.limit);
		if (len > this.limit)
			this.elementDisplay.addClass('lenError');
		else
			this.elementDisplay.removeClass('lenError');
	}
});

// Set event to start running active content when DOM is loaded
window.addEvent('domready', function() { Site.start(); });

