	//initiate validator on load 
	$(function() {
		var defa = {
			reMsg : 'Gracias por tu email, te contactare tan pronto me sea posible.',
			notMsg : 'Tu email no pudo ser enviado',
		};
		// validate contact form on keyup and submit
		$("#contactMail").validate({
			//set the rules for the fild names
			rules: {
				name: {
					required: true,
					minlength: 2
				},
				email: {
					required: true,
					email: true
				},
				comment: {
					required: true
				}
			},
			//set messages to appear inline
			messages: {
				name: "",
				email: "",
				comment: ""
			},
			submitHandler: function() {
				//trigger ajax to email me
				$.get('http://emaginar.com/js/mails.php', {name:$('#name').val(), phone:$('#phone').val(), email:$('#email').val(), comment:$('#comment').val()},
					function(data){
						if( data == 'success') {
							$('#callbackmail').show().append(defa.reMsg);
						} else {
							$('#callbackmail').show().append(defa.notMsg);
						}
					});						
				return false;	
			}
		});
		
});

var url="";

$(document).ready(function(){
	
	checkURL();
	$('ul li a').click(function (e){

			checkURL(this.hash);

	});
	
	//filling in the default content
// default_content = $('#nuevos').html();
	
	
	setInterval("checkURL()",250);
	

	$('ul#portfolio li a').hover(function() {
		$(this).find('span').animate({opacity: "show", top: "+5"}, "fast");
	}, function() {
		$(this).find('span').animate({opacity: "hide", top: "+20"}, "fast");
	});


});

var lasturl="";

function checkURL(hash)
{
	if(!hash) hash=window.location.hash;
	
	if(hash != lasturl)
	{
		lasturl=hash;
		
		// FIX - if we've used the history buttons to return to the homepage,
		// fill the pageContent with the default_content
		
		if(hash=="todos")
    $('ul#portfolio li').animate({opacity: 1}, 500 );
		
		else
		loadPage(hash);
	}
}


function loadPage(url)
{
 url=url.replace('#','');
 		if(url == 'all') {
			$('ul#portfolio li').fadeIn('slow');
		} else {
		$('ul#portfolio li').each(function() {
				if(!$(this).hasClass(url)) {
					$(this).fadeOut('slow');
				} else {
					$(this).fadeIn('slow');
				}
			});
		}


}

	function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
	}
	function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
	}
