$(document).ready(function(){
	//Caption Sliding (Partially Hidden to Visible)
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'240px'},{queue:false,duration:160});
	});
	
	$("#cart_expand").click(function(event){
		toggleCart('out');
		event.preventDefault();
	});
	$("#cart_close").click(function(event){
		toggleCart('in');
		event.preventDefault();
	});
	$('body').click(function(event) {
	    if (!$(event.target).closest('#cart_detailed').length) {
	        $('#cart_detailed').hide();
	    };
	});
	$('.button_delete').click(function(event){
        var id = $(this).attr("id").substr(6,1);
        deleteItem(id);
	});
});

function toggleCart(dir){
	if($("#cart_detailed").is(":hidden") == true){
	    $("#cart_detailed").slideToggle("slow");
    }    
}

function deleteItem(id){
    var path = document.location.href;
    $.post(path,{ toDelete : id },function(data){
        window.location = document.location.href;
    });
}

function validateContact() {
	var name = $('.nameContact');
	var email = $('.emailContact');
	var subject = $('.subjectContact');
	var message = $('.messageContact');
	
	var checkForm = false;
	
	if(name.val() != "") {
		$('.name_label').css("color","#000000");
		checkForm = true;
	} else {
		$('.name_label').css("color","#FF3300");
		checkForm = false;
	}
	
	if(email.val() != "") {
		$('.email_label').css("color","#000000");
		checkForm = true;
	} else {
		$('.email_label').css("color","#FF3300");
		checkForm = false;
	}
	
	if(subject.val() != "") {
		$('.subject_label').css("color","#000000");
		checkForm = true;
	} else {
		$('.subject_label').css("color","#FF3300");
		checkForm = false;
	}
	
	if(message.val() != "") {
		$('.message_label').css("color","#000000");
		checkForm = true;
	} else {
		$('.message_label').css("color","#FF3300");
		checkForm = false;
	}
	
	if(checkForm) {
		// console.log($('form').serialize());
		$.post("index.php?article_id=7", $('form').serialize())
	
	//alert(checkForm);
	}
	
	return false;
	
}
