$(function(){
	$("span.ville").click(function(){
		$("#ou").val($(this).html());
		$("#ou").focus();
	});
	$("span.typebien").click(function(){
		$("#quoi").val($(this).html());
		$("#quoi").focus();
	});
	$('#chercher').click(function(){
		$('#cp').val('1');
		var quoi 		= 'immobilier';
		var ou			= 'maroc';
		var transaction	= '';
		if($('#quoi').val() != ''){
			quoi = $('#quoi').val();
		}
		if($('#ou').val() != ''){
			ou = $('#ou').val();
		}
		if($('#transactionVente').is(':checked') == true || $('#transactionLocation').is(':checked') == true){
			if($('#transactionVente').is(':checked') == true){
				transaction = 'Vente';
			}
			if($('#transactionLocation').is(':checked') == true){
				transaction	= 'Location';
			}
			$('#searchForm').attr('action','http://www.maskane.com/'+transaction+'-'+str_replace(' ','+',quoi)+'-'+str_replace(' ','+',ou)+'/');
			$('#searchForm').submit();
		}else{
			jAlert("Veuillez séléctionner une transation");
		}
	});
	$("#ou").autocomplete(villes);
	$("#quoi").autocomplete(typesBiens);
	
	
	$("a.fancybox").fancybox({
		'frameWidth': 500,
		'frameHeight': 470,
		'hideOnContentClick': false 
	}); 
	// add a "rel" attrib if Opera 7+
    if(window.opera) {
        if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
            $("a.jqbookmark").attr("rel","sidebar");
        }
    }
   
    $("a.jqbookmark").click(function(event){
        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
        var url = "http://www.maskane.com/";
        var title = "Maskane - Le moteur de recherche de l'immobilier au maroc";
       
        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url, "");
        } else if( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title);
        } else if(window.opera) { // Opera 7+
            return false; // do nothing - the rel="sidebar" should do the trick
        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
            jAlert('Votre navigateur ne support pas cette action');
        }
    });
});