// JavaScript Document
$(document).ready(function () {	
	
	//HOME BLOCS
	$('#blocs_menu>div div[id$="_over"]').css('opacity','0');
	$('#blocs_menu>div').stop().hover(function(){
			var theId = $(this).attr('id');
			$('#'+theId+'_over').stop().animate({opacity:'0.9'}, 200);
		}, function(){
			var theId = $(this).attr('id');
			$('#'+theId+'_over').stop().animate({opacity:'0'}, 200);
		}
	);
	
	$('#rechercher_area div#[id$="_rechercher"]').hide();
	$('#rechercher_area').css('display', 'block');
	$('#rechercher_area').css('visibility', 'visible');
	$('#blocs_menu>div#arrow').hide();
	//HOME BLOCK CLICK
	if($('#blocs_menu').length > 0){
		$('#blocs_menu div#[id$="_over"]').click(function(){
			var theId = $(this).attr('id');
			var objId = theId.replace('_over', '_rechercher');
			var obj_to_open = $('div#'+objId);
			var theArrow = $('#blocs_menu>div#arrow');
			
			var the_parent = $(this).parent('div');
			//IF THERE IS AN OPENED BLOC
			if($('#blocs_menu .opened').length > 0){
				var theId2 = $('#blocs_menu>div.opened').attr('id')+'_rechercher';
				var obj_to_close = $('#'+theId2);
				if(objId != theId2){
					theArrow.fadeOut();
					obj_to_close.stop().slideToggle(500, function(){
						obj_to_open.stop().slideToggle(500);
						the_parent.removeClass('closed').addClass('opened');
						the_parent.siblings().removeClass('opened').addClass('closed');
						changeArrowPosition(objId, theArrow);
						theArrow.fadeIn();
					});
				}else{
					//SAME BLOC TO CLOSE
					obj_to_close.stop().slideToggle(500);
					the_parent.removeClass('opened');
					the_parent.siblings().removeClass('closed');
					theArrow.fadeOut();
				}
			}else{
				obj_to_open.stop().slideToggle(500);
				the_parent.addClass('opened');
				the_parent.siblings().addClass('closed');
				changeArrowPosition(objId, theArrow);
				theArrow.fadeIn();
			}
		});
	}
	
	$('#rechercher_3_submit').click(function(){
		$("#rechercher_3").submit();
	});
	/*if($('#rechercher_3 #f').val() == ''){
		$("#rechercher_3").validate({
			 rules: {
				 ref: "required"
		   }
		});
	}*/
});


function changeArrowPosition(objId, theArrow){
	if(objId.indexOf('1') != -1) theArrow.css('left', '283px');
	else if(objId.indexOf('2') != -1) theArrow.css('left', '613px');
	else theArrow.css('left', '943px');
}
