$(function()
{	
	$('ul#nav li:not(.current_page_item) a').hover(
		function()
		{
			$(this).stop().animate({ backgroundColor: '#ffffff', borderLeftColor: '#d1d1d0', color: '#a9a07d' }, 500);
		},
		function()
		{
			$(this).stop().animate({ backgroundColor: '#cfcaa9', borderLeftColor: '#b0ac90', color: '#343434' }, 100);
		}
	);
	
	$('#contatto').submit(
		function()
		{
			var nome 		= $('#nome'),
				cognome 	= $('#cognome'),
				email		= $('#email'),
				messaggio 	= $('#msg'),
				error		= false;
			
			if( !nome.val() ){
				error = true;
				add_error( nome );
			}
			else{
				rmv_error( nome );
			}

			if( !cognome.val() ){
				error = true;
				add_error( cognome );
			}
			else{
				rmv_error( cognome );
			}

			if( !email.val() ){
				error = true;
				add_error( email );
			}
			else{
				rmv_error( email );
			}

			if( !messaggio.val() ){
				error = true;
				add_error( messaggio );
			}
			else{
				rmv_error( messaggio );
			}

			if(error){
				$('#msg-error').slideDown('fast');
				return false;
			}
			
			return true;
		}
	);

	$( '#filter-per-category' ).change( function()
	{
		var cat = this.value;
		
		if( cat == 0 )
			cat = 3;
		
		location.href = '/?cat=' + cat;
	} );
	
	if( $( '#ticker' ).find( 'li' ).size() > 1 )
	{
		var $ticker = $( '#ticker' ),
		    pause   = 4000
		    tick    = function()
			{
				$ticker.find( 'li:first-child' ).animate( {
					marginTop : -45
				}, {
					duration : 700,
					complete : function()
					{
						$( this ).detach().removeAttr( 'style' ).appendTo( $ticker.find( 'ul' ) );
						
						timer = setTimeout( tick, pause );
					}
				} );
			},
			timer  = setTimeout( tick, pause );
	}
	
/*	
	$( '#filter-per-country' ).change( function()
	{
		var cat = this.value;
		
		if( cat == 0 )
			cat = 3;
		
		location.href = '/?country=' + cat;
	} );	
	*/
});

function add_error( obj )
{
	obj.parent().addClass('error');
}

function rmv_error( obj )
{
	obj.parent().removeClass('error');
}
