jQuery(document).ready(function(){

	$('#contact_form').submit(function() {		
		$.ajax({
			url: basePath+'index/contactajax',
			type: 'POST',
			data: $(this).serializeArray(),
			dataType: "html",
			contentType: "application/x-www-form-urlencoded",
			success:function(data){
				data = JSON.parse(data);
				if(data != null) {
					$.prompt((data.error!=null)?data.error:data.text,{ opacity: 0.8 });
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){alert('Error: '+XMLHttpRequest.responseText + ' ' + textStatus + ' ' + errorThrown);}
		});
        //
		
		return false;
    });

	$('.scrolling').jScrollPane({
		scrollbarWidth:6,
		scrollbarMargin:5,
		showArrows:false
	});

	theRotator();

});

function theRotator() {
	$('div#rotator ul li').css({opacity: 0.0});
	$('div#rotator ul li:first').css({opacity: 1.0});
	setInterval('rotate()',5000);
}

function rotate() {
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1500);
	current.animate({opacity: 0.0}, 1500).removeClass('show');
}
