$(document).ready(function() {
	// external links opening in new window
	// $('a[href*=http]').attr('target', '_blank');
	
	// smooth scroll
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target
			|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body')
				.animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
	
	$('div.panel:last-child').css({'background': 'none', 'padding-bottom': '10px'}); // no separator for last panel
	
	$('#creas a[href*=upload].portfolio').lightBox({
		imageLoading:			"static/img/lightbox/lightbox-ico-loading.gif",
		imageBtnPrev:			"static/img/lightbox/lightbox-btn-prev.gif",
		imageBtnNext:			"static/img/lightbox/lightbox-btn-next.gif",
		imageBtnClose:			"static/img/lightbox/lightbox-btn-close.gif",
		imageBlank:				"static/img/blank.gif",
		txtImage:				"",
		txtOf:					"/",
		containerBorderSize:	5
	});
	
	$("#contact form").validate({
		submitHandler: function(form) {
		
			
			jQuery(form).ajaxSubmit({
				target: "p.submit"
			});
			$("#contact form input, #contact form textarea").attr("disabled","disabled").addClass('disabled');
		},
		errorPlacement: function(error, element) {
						error.insertBefore(element.siblings("label"));
		},
		highlight: function(element, errorClass) {
						$(element).parent("p").addClass(errorClass);
		},
		unhighlight: function(element, errorClass) {
			$(element).parent("p").removeClass(errorClass).find("label.error").remove();
		},
		
		rules: {  
	        first_name: { 
	            required: true
	        },
	        email: { 
	            required: true, 
	            email: true
	        },
			last_name: {
				required: true
			},
			message: {
				required: true
			}
	    },
		messages: {
			first_name: "Veuillez spécifier votre prénom",
			last_name: "Veuillez spécifier votre nom",
			email: {
				required: "J'ai besoin de votre e-mail pour vous recontacter !",
				email: "Votre e-mail doit être au format nom@domaine.com"
			},
			message: "Vous n'avez pas laissé de message !"
		}
	});
	
	
});