/////////////////////// Events sur le menu gauche
function navLeftEvents(){
	$('.jsClickNav > li > a').bind('click',function() {
		$('.active',$('.jsClickNav')).removeClass('active');
		$(this).parent().addClass('active');
		return false;
	});
}   

// Affiche ou hider les dtail d'un article
function setDisplayDetArticle(){
	
	$('.jsAfficheText,.jsClickTitle').bind('click',function(){
		$('.article',$(this).parents('li')).addClass('active');		
		return false;
	});
	
	$('.jsAfficheResume').bind('click',function(){
		$(this).parents('.article').removeClass('active');
		return false;
	});
	
	
	/* ------ Voir / masquer info : invite permanent */
	$('.jsVoirReponse').bind('click',function(){
		if($(this).parents('.post').attr("class").indexOf("active")!=-1){
			$(this).parents('.post').removeClass('active');
		}else{
			$(this).parents('.post').addClass('active');
		}			
		return false;		
	})
	
}

// Vider les champs 
function viderChamps(){
	var defaultInput = new Array('Ecrivez votre titre','Ecrivez le titre de votre bon plan','Ecrivez le titre de votre astuce','<p>Ecrivez votre astuce</p>');		
	for(i=0;i<defaultInput.length;i++){
		if($(this).val()==defaultInput[i]){
			$(this).val('');
		}
	}
}

/*--------------------------- FUNCTION POPIN */

/* show Popon */
function showPopinExprimezVous(currentContext){

    var urlRemerciement = '/exprimez-vous/remerciement.aspx';    
	$("#popinValidationDisplay").remove();
	$("#corps").after('<div id="popinValidationDisplay"><div id="bgPopinValidationForm"></div></div>')
	
	if (currentContext != null)
	    urlRemerciement = urlRemerciement + '?currentContext=' + currentContext;

	$.ajax({
		type:"GET",
		url: urlRemerciement,
		success:function(msg){
			$("#bgPopinValidationForm").after(msg);
			closePopin(); 
			bgPopin();		}
	});
	return false;
}


/* show Popon */
function showPopinExprimezVousWithUrl(currentContext, ReturnUrl){

    var urlRemerciement = '/exprimez-vous/remerciement.aspx';    
	$("#popinValidationDisplay").remove();
	$("#corps").after('<div id="popinValidationDisplay"><div id="bgPopinValidationForm"></div></div>')
	
	if (currentContext != null)
	    urlRemerciement = urlRemerciement + '?currentContext=' + currentContext + '&returnUrl=' + ReturnUrl;

	$.ajax({
		type:"GET",
		url: urlRemerciement,
		success:function(msg){
			$("#bgPopinValidationForm").after(msg);
			closePopin(); 
			bgPopin();		}
	});
	return false;
}

// Fermeture de popin //
function closePopin(){
	$(".jsBtClosePopin").click(function() {
		$("#popinValidationDisplay").remove();
		if ($.browser.msie && navigator.appVersion.indexOf('MSIE 6') != -1){
			$("select").show();
		}
		return false;
	});
}

// gestion taille background Popin //
$(window).resize(function() {	
	popSetWidth();// resize de la popin //
})

function popSetWidth(){
	var bodyWidth = (($("body").width() > 954) ? $("body").width() : 954);		   
	$("#popinValidationDisplay").width(bodyWidth);
	$("#bgPopinValidationForm").width(bodyWidth);
	
	if(bodyWidth >= 954){
		$("#popinValidationDisplay").width(bodyWidth);
		$("#bgPopinValidationForm").width(bodyWidth);
	}
	else{
		$("#popinValidationDisplay").width(954);
		$("#bgPopinValidationForm").width(954);	
	}
}

function bgPopin(){
	var bodyHeight = $("body").height();	
	$("#bgPopinValidationForm").height(bodyHeight);
	
	popSetWidth();	

	if ($.browser.msie && navigator.appVersion.indexOf('MSIE 6') != -1){ // IE6
		$("select").hide();
	}
}

/*--------------------------- END FUNCTION POPIN */

/* Caroussel */
function mycarousel_initCallback(carousel) {

    jQuery('.ev-carousel .bt-right').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('.ev-carousel .bt-left').bind('click', function() {
        carousel.prev();
        return false;
    });
};


$(document).ready(function(){
	// Events menu gauche	
	navLeftEvents();
	
	//display Detail Article
	setDisplayDetArticle();
	
	// Vider les inputs 
	$('.jsFocusInput').bind('focus',viderChamps);
	
	// valider form - disply popin
	//$('.jsSubmitDebat').bind('click',showPopin);
	
	$("#une_colonne.noScript").removeClass("noScript");
	if(jQuery(".ev-carousel").length){
		var startItem = 0
		if(jQuery(".ev-carousel .active").length){
			startItem = $(".ev-carousel li").index($(".ev-carousel .active")[0]);
		}
		if(jQuery(".ev-carousel .carousel-wrapper li").length > 3){
			jQuery(".ev-carousel .carousel-wrapper").jCarouselLite({
				scroll: 1,
				btnNext: ".ev-carousel .bt-right",
				btnPrev: ".ev-carousel .bt-left",
				start:startItem,
				circular:false
		
			});
		}
		else{
			jQuery(".ev-carousel .bt-left, .ev-carousel .bt-right").css("visibility","hidden");
		}
	}
});
