var FontSize = {
	min: 0.7,
	max: 1.3,
	init: function() { if (FontSize.element = document.getElementById('zoomable')) {
		FontSize.originalFontSize = parseFloat(FontSize.element.style.fontSize || 1);
		FontSize.reset();
	}},
	reset: function() { if (FontSize.element) {
		FontSize.element.style.fontSize = FontSize.originalFontSize + 'em';
	}},
	incr: function() { if (FontSize.element) { if (parseFloat(FontSize.element.style.fontSize) < FontSize.max) {
		FontSize.element.style.fontSize = (parseFloat(FontSize.element.style.fontSize) + 0.1) + 'em';
	}}},
	decr: function() { if (FontSize.element) { if (parseFloat(FontSize.element.style.fontSize) > FontSize.min) {
		FontSize.element.style.fontSize = (parseFloat(FontSize.element.style.fontSize) - 0.1) + 'em';
	}}}
};

if (window.addEventListener) {
	window.addEventListener('load', FontSize.init, false);
} else {
	window.attachEvent('onload', FontSize.init);
}


(function() {
	var contacts = function() {
		var container = document.getElementById('carousel_contacts').getElementsByTagName('ul')[0],
			elements = $A(container.getElementsByTagName('li')),
			element = null,
			width = 10,
			need = $('carousel_contacts').offsetWidth,
			x = 0,
			y = 0;

		// calculate ul width..
		while (element = elements[x++]) {
			width += element.offsetWidth;
		}

		// add some gap if needed..
		while (width < need) {
			width += (element = elements[y++]).offsetWidth;
			//container.appendChild(element.cloneNode(true));
			if (y >= elements.length) {
				y = 0;
			}
		}

		// store container and elements..
		this.elements = (this.container = container).getElementsByTagName('li');

		// bind the next control..
		if ($('control_next_contacts')) $('control_next_contacts').observe('click', function(evt) {
			if (!this.moving) {
				new Effect.Move(container, {
					x: -this.elements[0].offsetWidth,
					duration: .555,
					beforeSetupInternal: function() {
						this.moving = true;
						this.container.appendChild(this.container.firstChild.cloneNode(true));
					}.bind(this),
					afterFinishInternal: function() {
						this.container.style.left = (parseInt(this.container.style.left) + this.container.firstChild.offsetWidth) + 'px';
						this.container.removeChild(this.container.firstChild);
						this.elements = $A(container.getElementsByTagName('li'));
						this.moving = false;
					}.bind(this)
				});
			}
		}.bind(this));

		// bind the prev control..
		if ($('control_prev_contacts')) $('control_prev_contacts').observe('click', function(evt) {
			if (!this.moving) {
				new Effect.Move(container, {
					x: this.elements[this.elements.length - 1].offsetWidth,
					duration: .555,
					beforeSetupInternal: function() {
						this.moving = true;
						this.container.insertBefore(this.container.lastChild.cloneNode(true), this.container.firstChild);						
						this.container.style.left = (parseInt(this.container.style.left || 0) - this.container.lastChild.offsetWidth) + 'px';
					}.bind(this),
					afterFinishInternal: function() {
						this.container.removeChild(this.container.lastChild);
						this.elements = $A(container.getElementsByTagName('li'));
						this.moving = false;
					}.bind(this)
				});
			}
		}.bind(this));
	};

	// put that crap on the load stack..
	document.observe('dom:loaded', contacts.bind(contacts));
})();

