
	$(document).ready(function(){

	$("a[rel='box']").colorbox();
	// When a link is clicked
		$("a.tab").click(function () {
			
			
			// switch all tabs off
			$(".active").removeClass("active");
			
			// switch this tab on
			$(this).addClass("active");
			
			// slide all content up
			$(".content").slideUp();
			
			// slide this content up
			var content_show = $(this).attr("title");
			$("#"+content_show).slideDown();
		  
		});

		
			$("#qsearch").autocomplete("/get_list.php", {
		width: 420,
		matchContains: true,
		//mustMatch: true,
		minChars: 3,
		//multiple: true,
		highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});

   $(".pagination a").click(function(){ 	// on selectionne tous les liens et on définit une action quand on clique dessus
	page=($(this).attr("href")); // on recuperer l' adresse du lien
	
	$.ajax({  // ajax
		url: page, // url de la page à charger
		cache: false, // pas de mise en cache
		success:function(html){ // si la requÃªtÃ© est un succÃ¨s
			afficher(html);	    // on execute la fonction afficher(donnees)			
		},
		error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
		}
	});
	return false; // on desactive le lien
   });

$("#loading").ajaxStart(function(){
   $(this).show();
 });
$("#loading").ajaxStop(function(){
   $(this).hide();
 });

 $('#metio').weatherfeed(['MOXX0022']);
 
});

function afficher(donnees){ // pour remplacer le contenu du div contenu
	
	$("#listajax").empty(); // on vide le div
	$('html, body').animate({scrollTop:0}, 'slow');
	$("#listajax").append(donnees); // on met dans le div le résultat de la requete ajax
	
}


$().ready(function() {
	var container = $('div.container');
	// validate the form when it is submitted
	var validator = $("#form").validate({
		errorContainer: container,
		errorLabelContainer: $("ol", container),
		wrapper: 'li',
		meta: "validate",
		rules: {
			captcha: {
				required: true,
				remote: "process.php"
			}
		}
	});
});


/*$(function () {
  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
    var top = $('#carte').offset().top - parseFloat($('#carte').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        $('#carte').addClass('fixed');
      } else {
        // otherwise remove it
        $('#carte').removeClass('fixed');
      }
    });
  }  
}); */


var carte                    = "#carte";
var sidebar_top_limit       = 244;
var sidebar_top_margin      = -20;
var sidebar_slide_duration  = 800;

$(window).scroll(function() {
	offset = $(document).scrollTop() + sidebar_top_margin;	 
	if(offset < sidebar_top_limit)
	    offset = sidebar_top_limit;	 
	$(carte).animate({top:offset},{duration:sidebar_slide_duration,queue:false});	
});


$(".pagination a").click(function(){ 	// on selectionne tous les liens et on définit une action quand on clique dessus
	page=($(this).attr("href")); // on recuperer l' adresse du lien
	
	$.ajax({  // ajax
		url: page, // url de la page à charger
		cache: false, // pas de mise en cache
		success:function(html){ // si la requÃªtÃ© est un succÃ¨s
			afficher(html);	    // on execute la fonction afficher(donnees)			
		},
		error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
		}
	});
	return false; // on desactive le lien
  });

// Read a page's GET URL variables and return them as an associative array.
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


$(document).ready(function () {

    $.fn.animateHighlight = function (highlightColor, duration) {
        var highlightBg = highlightColor || "#FFFF9C";
        var animateMs = duration || 2000;
        var originalBg = this.css("background-color");

        if (!originalBg || originalBg == highlightBg)
            originalBg = "#FFFFFF"; // default to white

        jQuery(this)
            .css("backgroundColor", highlightBg)
            .animate({ backgroundColor: originalBg }, animateMs, null, function () {
                jQuery(this).css("backgroundColor", originalBg); 
            });
    };

	
	$(".filter").click(function(){ 
		$('html, body').animate({scrollTop:0}, 'slow');
		$('#left').animateHighlight();

	});
	

	
	//if submit button is clicked
	$('.subsearch').change(function () {		
		
		//Get the data from all the fields
		var scp     = $('input[name=scp]');
		var sville  = $('input[name=sville]');
		var slabel5 = $('input[name=slabel5]');
		var slabel4 = $('input[name=slabel4]');
		var slabel3 = $('input[name=slabel3]');
		var slabel2 = $('input[name=slabel2]');
		var slabel1 = $('input[name=slabel1]');
		var slabel  = $('input[name=slabel]');
		
		var type1 = $('input[name=type1]');
		var type2 = $('input[name=type2]');
		var type3 = $('input[name=type3]');
		var type4 = $('input[name=type4]');
		var type5 = $('input[name=type5]');
		var type6 = $('input[name=type6]');
		
		var ville1 = $('input[name=ville1]');
		var ville2 = $('input[name=ville2]');
		var ville3 = $('input[name=ville3]');
		var ville4 = $('input[name=ville4]');
		var ville5 = $('input[name=ville5]');

		var tarifMin = $('input[name=tarifMin]');
		var tarifMax = $('input[name=tarifMax]');
		
		var desc = $('input[name=desc]');
		//var slabel = $('input:checkbox:checked').val();	
		
		//organize the data properly
		var data = 'load=0';
	    var lbl = '';
		var typ = '';
		var vll = '';
		
		if(slabel5.is(':checked')){lbl += '"'+slabel5.val()+'",';}
		if(slabel4.is(':checked')){lbl += '"'+slabel4.val()+'",';}
		if(slabel3.is(':checked')){lbl += '"'+slabel3.val()+'",';}
		if(slabel2.is(':checked')){lbl += '"'+slabel2.val()+'",';}
		if(slabel1.is(':checked')){lbl += '"'+slabel1.val()+'",';}
		if(slabel.is(':checked')){lbl += '"'+slabel.val()+'",';}
		
		if(type1.is(':checked')){typ += '"'+type1.val()+'",';}
		if(type2.is(':checked')){typ += '"'+type2.val()+'",';}
		if(type3.is(':checked')){typ += '"'+type3.val()+'",';}
		if(type4.is(':checked')){typ += '"'+type4.val()+'",';}
		if(type5.is(':checked')){typ += '"'+type5.val()+'",';}
		if(type6.is(':checked')){typ += '"'+type6.val()+'",';}
		
		if(ville1.is(':checked')){vll += '"'+ville1.val()+'",';}
		if(ville2.is(':checked')){vll += '"'+ville2.val()+'",';}
		if(ville3.is(':checked')){vll += '"'+ville3.val()+'",';}
		if(ville4.is(':checked')){vll += '"'+ville4.val()+'",';}
		if(ville5.is(':checked')){vll += '"'+ville5.val()+'",';}

		
		if(lbl!=""){data+='&label=('+lbl.substring(0,lbl.length-1)+')';}
		if(typ!=""){data+='&type=('+typ.substring(0,typ.length-1)+')';}
		if(vll!=""){data+='&ville=('+vll.substring(0,vll.length-1)+')';}
		
		if(sville.val() !='Mot cle ...' && sville.val() !=''){data += '&desc=' + sville.val();}
		if(scp.val() !='Code postal ...' && scp.val() !=''){data += '&cp=' + scp.val();}
		
		if(tarifMin.val() !='' && tarifMin.val() !=''){data += '&tarifMin=' + tarifMin.val();}
		if(tarifMax.val() !='' && tarifMax.val() !=''){data += '&tarifMax=' + tarifMax.val();}
		
		//show the loading sign
		$('.loading').show();
		var page ="listd";
		if($.getUrlVar('page')!="undefined"){
			var page = $.getUrlVar('page');
			//alert(page);
		}
		//start the ajax
		$.ajax({
			url: "list.php?page="+page+"&load=0&srt=OUD.pos&ord=Desc",	
			type: "GET",	
			data: data,		
			cache: false,
			success:function(html){ // si la requÃªtÃ© est un succÃ¨s  
				//alert(data);
				afficher(html);	    // on execute la fonction afficher(donnees)		
				if($.getUrlVar('page')!="undefined" && $.getUrlVar('page')!="detailsd"){
				initialize();
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
			}	
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	
if($.getUrlVar('page')=="detailsd"){
$(document).ready(function() {
	// Save  the jQuery objects for later use.
	var outer		= $("#preview_outer");
	var arrow		= $("#arrow");
	var thumbs		= $("#thumbs span");

	var preview_pos;
	var preview_els	= $("#preview_inner div");
	var image_width	= preview_els.eq(0).width(); // Get width of imaages
	
	// Hook up the click event
	thumbs.click(function() {
		// Get position of current image
		preview_pos = preview_els.eq( thumbs.index( this) ).position();

		// Animate them!
		outer.stop().animate( {'scrollLeft' : preview_pos.left},	285 );
		arrow.stop().animate( {'left' : $(this).position().left },	285 );
	});

	// Reset positions on load
	arrow.css( {'left' : thumbs.eq(0).position().left } ).show();
	outer.animate( {'scrollLeft' : 0}, 0 );

	// Set initial width
	$("#preview_inner").css('width', preview_els.length * image_width);
	
	
});
}
	$(function() {
		$( "#slider-range" ).slider({
			range: true,
			min: 10,
			max: 4000,
			values: [ 10, 4000 ],
			slide: function( event, ui ) {
				$( "#tarifMin" ).val(ui.values[ 0 ]);
				$( "#tarifMax" ).val( ui.values[ 1 ]);
			}
		});
			$( "#tarifMin" ).val( $( "#slider-range" ).slider( "values", 0 ));
			$( "#tarifMax" ).val($( "#slider-range" ).slider( "values", 1 ));
			
	});
	
	
	  $(function() {
    
    $('.Tips2').tipsy({gravity: $.fn.tipsy.autoNS});
  
  });
	
