$('form.recherche-form-js').submit(function() {
    $("input.default").val('');
});

$(document).ready(function() {
	$('form.recherche-form-js input[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));
			$(this).val($(this).attr('title')).addClass('default');	
			
		}

		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').addClass('focused');
				$(this).val('').removeClass('default');
				
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused');	
				$(this).val($(this).attr('title')).addClass('default');	
				
			}
		});
	});
});


/* 
   Fonction deprecated...
   Remplacée par 'scroll_top_serach_form'
*/
function scroll_item(id, paggingTop) {
    //alert("DEPRECATED ...");
        //      On calcule la position de base de l'élément
        if(typeof(tab) == 'undefined') {
                tab = new Array;
              	current_pos = 0;
	}
        if(typeof(tab[id]) == 'undefined') {
                pos     = $('#'+id).position();
                tab[id] = pos.top;
        }
        
        //      On calcule ensuite la position du scroll
        var screenpos = window.pageYOffset;
	var footer_pos = $('#footer').position().top;
	var block_size = $('#'+id).height();

	if(id == "colonneDeRecherche") {
	    current_pos = $('#'+id).position().top;
	}

        $('#'+id).css('position', 'relative');
        $('#'+id).css('z-index', '9');
        //      Si le scroll est supérieur à la position initiale de l'élément, on décale celui-ci, sinon on le remet à sa position initiale

	if(screenpos+paggingTop > tab[id])
                $('#'+id).css('top', (screenpos-tab[id]+paggingTop)+'px');
	else 
                $('#'+id).css('top', 0+'px');

        if(screenpos+80 > footer_pos-block_size) {
  	        $('#'+id).css('top', (footer_pos-block_size-230)+'px');
		$('#'+id).css('z-index', '8');
	}
}

function scroll_top_search_form() {

    var screenpos = window.pageYOffset;
    var menu_height = 65;
    if(screenpos > menu_height){
	var padding_top = $('#header').height();
	$('#header').css('position', 'fixed');
	$('#header').css('top', '-'+menu_height+'px');
	$('#top').css('padding-top', padding_top+'px');
    }else{
	$('#header').css('position', 'relative');
	$('#header').css('top', '0px');
	$('#top').css('padding-top', '0px');
    }
}

function scroll_right_search_form(){
    var screenpos = window.pageYOffset;
    var content_height = $("#content-results").height();
    var block_height = $('#colonneDeRecherche').height();

    //alert("Content height : " + content_height + " - Height colonne : " + block_height);

    if(content_height > block_height){
	/* 
	   MAJ du positionnement de la colonne de recherche
	   dans le cas d'un scroll de la fenêtre.
	*/
	if( screenpos > 140 ){
	    var pos_init_left = $('#colonneDeRecherche').position().left;
	    $('#colonneDeRecherche').css('position', 'fixed');
	    $('#colonneDeRecherche').css('top', '65px');
	    $('#colonneDeRecherche').css('left', pos_init_left+'px');
	}else{
	    $('#colonneDeRecherche').css('position', 'relative');
	    $('#colonneDeRecherche').css('top', '0px');
	    $('#colonneDeRecherche').css('left', '0px');
	}

	/*
	  Si le scroll est maximum et que la colonne déborde sur le footer,
	  on le repositionne en relatif en le calant juste au dessus du footer.
	*/
	var block_pos_top = $('#colonneDeRecherche').position().top;
	var footer_pos_top = $('#footer').position().top;
	var content_pos_top = $("#content-results").position().top;
	
	if( (block_pos_top+block_height) >= (content_pos_top+content_height+12)){
	    $('#colonneDeRecherche').css('position', 'relative');
	    $('#colonneDeRecherche').css('left', '0px');
	    $('#colonneDeRecherche').css('top', (content_height-block_height+12)+'px');
	}
    }
}

function resize_browser_search_form() {
    $('#colonneDeRecherche').css('position', 'relative');
    $('#colonneDeRecherche').css('top', '0px');
    $('#colonneDeRecherche').css('left', '0px');
    scroll_right_search_form();
}
