// Function pour les traductions
function translate(str) {
  return TRADUIRE[str] || str;
}

// Fonction pour la newsletter
function newsletter_submit(){
	newsletter_file = "/newsletter/process?langue="+LOCALISATION.langue.code;
	try {xhr = new XMLHttpRequest();}
	catch(e){xhr = new ActiveXObject("Microsoft.XMLHTTP");}
	xhr.open("GET", newsletter_file+"&email="+document.getElementById("f_newsletter").value+"&id="+Math.random(), true);
	xhr.send(null);

	xhr.onreadystatechange = function(){
        if (xhr.readyState == 4) {
        	document.getElementById("newsletter_result").innerHTML = xhr.responseText;
        	document.getElementById("f_newsletter").value = translate("Your e-mail");
		}
	}
}

function load_slideshow_apartment(){
    $(".thumb-appartement a").click(function(){
        return false;
    });
    
    $("img.thumb").hover(
        function(){
            $(this).fadeTo("fast",0.5);
        },
        function(){
            $(this).fadeTo("fast",0.9);
        }		
    );

	var counter =  $("img.grand").length;
	$("img.grand").each(function(){
		$(this).attr('src', $(this).attr('title') + "?" + new Date().getTime()).load(function(){
            $(this).unbind('load');
			counter--;
			$(this).removeAttr('title');
			if(counter == 0){
				$("#slide-appartement-loading").fadeOut();
				$("#slide-appartement").fadeIn();
			}
		});
	});
}

function load_slideshow(){
	$(".new").not(":first").end().first().addClass("new_current");
    var counter = $(".new img").length;
    $(".new img").hide();
    $(".content-container").css({top: '380px'});
    $(".new_current").prepend('<img class="home-img-loading" src="/images/loading-animation-transparent.gif" alt="">');
    $(".new img").not(".home-img-loading").each(function(index) {
        $(this).attr('src', $(this).attr('title') + "?" + new Date().getTime()).load(function() {
            $(this).unbind('load');
            $(this).removeAttr('title');
            counter--;
            if (counter == 0){
                $(".home-img-loading").remove();
                $(".new_current img").fadeIn(2000);
                $(".new_current .content-container").show();
                $("#featured").hover(
                    function(){ $(".content-container").animate({top: '330px'}, 'fast'); },
                    function(){ $(".content-container").animate({top: '380px'}, 'fast'); }
                );           
                var timer = setInterval("go_next()", 5000);
            }
        });
    });
}
function go_next(){
	var $current = $(".new_current");
	var $current_id = eval($current.attr("id").substring(4,$current.attr("id").length));
	var $next_id = ($current_id == $(".new").size()) ? 1 : $current_id+1;

	$current
		.removeClass("new_current")
		.find("img").fadeOut(2000, 'easeInOutQuint');

	$("#new-"+$next_id)
		.addClass("new_current")
		.find("img").fadeIn(2000, 'easeInOutQuint');

    $current.find(".content-container").hide();
    $("#new-"+$next_id).find(".content-container").show();
    
    $("#arrondissement-nb div").removeClass('active');
    if(typeof(slideshow_map) !== 'undefined')  $("#arrondissement-"+slideshow_map[$next_id]+"-nb").addClass('active');
}

