$(document).ready(function(){
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	/*$("a").click(function() {
		//window.location = "http://newtech-energy.com/temp/index.html";
		return false;
	});*/
	
	// submenu
	$('#nav > li > a').click(function() {
		var pause = 0;
		// pause
		if($('.submenu').css('display') != 'none' ) {
			pause = 300;
		}
		
		
		$('#nav > li > a').each(function() {
			$(this).removeClass('active');	
		});
		$(this).addClass('active');
		
		$('.submenu').slideUp(400);
		
		if($(this).hasClass('hassubmenu')) {
			$('.submenu > ul').slideUp(300);
			var submenu = $(this).attr('rel');
			
			$('.submenu > .submenu'+submenu).delay(pause).slideDown(400);
			$('.submenu').delay(pause).slideDown(400);
			
			return false;
		}
		
		
	});
	
	$("#slider3 img").each(function(n) {
		$(this).attr("id", "item"+(n+1));
	});

	$("#slider3").carouFredSel({
		prev: '.prev',
		next: '.next',
		auto: false
	});
	$("#slider3").trigger("linkAnchors", [".linkanchor", "a"]);

	
	
	// slideshow
	$('#carousel > ul').carouFredSel({
		prev: '.prev',
		next: '.next',
		auto: false,
		scroll    : {
			onBefore: function(oldItems, newItems) {
				//unhighlight( oldItems );
			},
			onAfter : function(oldItems, newItems) {
				$(newItems).find('.img_slide').animate({
					"width" : 0,
					}, 500, function() {
						//
				});
				$(oldItems).find('.img_slide').animate({
					"width" : "350px",
					}, 500, function() {
						//
				});
	       }
    	}
	});
	
	// actualities
	$("#act_carousel > ul").carouFredSel({
		prev: '.act_prev',
		next: '.act_next',
		auto: false,
		scroll    : {
			onAfter : function(oldItems, newItems) {
				$(this).trigger("currentPosition", function( pos ) {
					
                	$(".eng_number").html( pos+1 );
                });
			}
		}
	});
	
	// 2.slider 
	$('#slider2').carouFredSel();
	
	jQuery.validator.addMethod(
        "tel",
        function(value, element) {
           return (value.match(/^\d\d\d\d\d\d\d\d\d\d$/));
        },
         "Ce champs est obligatoire."
  	);
      
	 // validate inscription form
	$("#contactform").validate({
      errorPlacement: function(error, element) {
		 var el = $('.formstatus');
         el.html("Les champs sont obligatoire.");
      }
  });
});
