function loadCarousel(pageIndex)
{
	function initCallback(carousel) {
		jQuery('#menu a').bind('click', function() {
			$('.active').removeClass('active');
			$(this).parent('li').addClass('active');
			carousel.scroll($(this).attr('rel'));
			return false;
		});
	}
	
	$('#pages').css({
		'top': '0px'
	});
	
	jQuery('#pages').jcarousel({
		vertical: true,
		scroll: 1,
		start: pageIndex,
		initCallback: initCallback,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	$('#languages ul').listSelect({
		onSelect: function(li) {
			document.location.href = li.attr('rel');
		}
	});
	
	spinner = $('<img />').attr('src', '/images/spinner_big.gif')
		.attr('id', 'loading')
		.css({
			'position': 'absolute', 
			//'top': '143px', 
			//'left': '20px', 
			'top': '50%',
			'left': '50%',
			'border': '1px solid #ccc', 
			'padding': '4px',
			'padding-bottom': '3px',
			'background-color':'#fff', 
			'display':'none', 
			'z-index':'1000000000000000',
			'-moz-border-radius':'3px'
		});
	$('body').append(spinner);
	
	spinner.ajaxStart(function(){
		spinner.show();
	}).ajaxStop(function(){
		spinner.hide();
	});
}

(function($){
	$('#contact_form').live('submit', function(){
		$.ajax({
			url: $(this).attr('action'),
			data: $(this).serialize(),
			dataType: 'json',
			//method: 'POST',
			success: function(data, textStatus) {
				if( data['error'] == true ) {
					$('div.error').html(data['message']).fadeIn();
					if( data['email'] != '' )
						$('#contact_email').addClass('error');
					else
						$('#contact_email').removeClass('error');
						
					if( data['object'] != '' )
						$('#contact_object').addClass('error');
					else
						$('#contact_object').removeClass('error');
					
					if( data['body'] != '' )
						$('#contact_body').addClass('error');
					else
						$('#contact_body').removeClass('error');
				} else {
					// ok
					$('div.error').fadeOut();
					$('.success').html(data['message']).fadeIn();
					$('#contact_form input[type=text], #contact_form textarea').val('').removeClass('error');
					setTimeout(function(){
						$('.success').html(data['message']).fadeOut();
					}, 3000);
				}
			}
		});
		
		return false;
	});
	
	$.fn.listSelect = function(options) {
		
		var options = $.extend({
			onSelect: function(li) {}
		}, options);
		
		return this.each(function(){
			
			$(this).css({
				'position': 'absolute'
			});
			
			$(this).children(':not(.selected)').hide();
			
			$(this).mouseover(function(){
				$(this).children('li').show();
				
				top = $(this).children('.selected').position().top-5;
				
				$(this).css({
					'top': '-'+top+'px'
				});
			});
			
			$(this).mouseout(function(){
				$(this).children(':not(.selected)').hide();
				$(this).css({
					'top': '5px'
				});
			});
			
			$(this).children('li').click(function(){
				li = $(this);
				options.onSelect.call(this, li);
			});
			
		});
	}
})(jQuery);