// CUFON TYPE REPLACEMENT 
//Cufon.replace('.sl, .promo_content .chapo, #content h1, .wrap .slide .col_right .membre a, .title, .decouvrir .bloc h5, .wrap .slide .col_right .parrains h3, .col1 h3.h3actu, #concours .slider .bloc .info h5, ',  {fontFamily: 'SFR light', hover: true});
//Cufon.replace('h3.title, .sb, .promo_content h1, #promo_content_to_slide .ads li div h4, .wrap .slide .col_right h2, .wrap .slide .col_right .plus h3, #concours .slider .bloc .info h4, .actu_slider .actus_content .bloc h4, .btn_slider_home span, #concours .slider .bloc .info h4,', {fontFamily: 'SFR Bold', hover: true});


var timers_promo = new Array();

$(document).ready(function() {
	//TIMER PROMO
	timer();
	
	//JS HOME PAGE
	$('.btn_slider_home_wrapper').each(function(){
		var top = ( $(this).height() - $(this).children('.btn_slider_home').height() ) / 2;
		$(this).children('.btn_slider_home').css('margin-top', top);
	});
	$(".btn_slider_home_wrapper").click(function(){
	     window.location=$(this).find("a").attr("href");
	     return false;
	});
        
        $("form.stopEmptySubmit").submit(stopEmptySubmit);
	
	//TOP PROMO
	init_cycle_top_promo();

	//INIT SHARE PANEL
	initShare_done();
	
	//ALERTE
	initAlerte();
	
	//POSITION SHARE PANEL
	$(".shareit a.open").click(function(){
		var scrolltop = $(document).scrollTop();
		var winheight = $(window).height();
		var sfrvodlink = getPosition($(this));
		var sfrvodcode = $(this).next(".share_panel").height();
		if ((sfrvodlink[1]+sfrvodcode)>(scrolltop+winheight)) {
                    var newposition = sfrvodcode ;
                    $(this).next(".share_panel").css({"position":"absolute","top":"-"+newposition +"px !important"});
		}
		else {
                    $(this).next(".share_panel").css({"position":"absolute","top":"20px !important"});
		}
	}); 
	
	//INIT SHARE MAIL
	$(".shareit .mail a").click(function(){
		displayPopInMailToAFriend($(this).attr("rel"));
		return false;
	});
	
	if($(".beo").length) jsli.Transformation();
	
	var hash = window.location.hash.slice(1);
	if(hash=="login") {
		$("body.front .login_ajax").click();
	} else if(hash=="password") {
		
	}
	//if($("body.front .login_ajax").length) $("body.front .login_ajax").click();
});

function verifPassConfInsc(){
    var cible1 =  $('#conf-pass-pass1');
    var cible2 =  $('#conf-pass-pass2');
    var valeur1 =  $('#edit-pass-pass1').val();
    var valeur2 =  $('#edit-pass-pass2').val();
    if (valeur1 != valeur2) { 
    	valideChampsInsc(0, cible1);
    	valideChampsInsc(0, cible2);
    } else if(valeur1=="" && valeur2!="") {
    	valideChampsInsc(0, cible1);
    	valideChampsInsc(1, cible2);
        $('#edit-pass-pass2').removeClass('error');
    } else if(valeur1!="" && valeur2=="") {
    	valideChampsInsc(1, cible1);
        $('#edit-pass-pass1').removeClass('error');
    	valideChampsInsc(0, cible2);
    } else if(valeur1=="" && valeur2=="") {
    	valideChampsInsc(0, cible1);
    	valideChampsInsc(0, cible2);
    } else {
        $('#edit-pass-pass1').removeClass('error');
        $('#edit-pass-pass2').removeClass('error');
    	valideChampsInsc(1, cible1);
    	valideChampsInsc(1, cible2);
    }
}

function verifPassInsc(){
    var cible =  $('#conf-pass-pass1');
    var taille = $('#edit-pass-pass1').val().length;
    if (taille < 6) {
        valideChampsInsc(0, cible);
    }
    else {
        valideChampsInsc(1, cible);
        $('#edit-pass-pass1').removeClass('error');
    }
    //verifPassConfInsc();
}

function verifNomArtisteInsc(){
    var cible =  $('#conf-field-profil-artiste-name-0-value');
    var taille = $('#edit-field-profil-artiste-name-0-value').val().length;
    
    if (taille==0){
	valideChampsInsc(0, cible);
    } else {
	valideChampsInsc(1, cible);
        $('#edit-field-profil-artiste-name-0-value').removeClass('error');
    }
}

function verifNomInsc(){
    var cible =  $('#conf-field-profil-lastname-0-value');
    var taille = $('#edit-field-profil-artiste-name-0-value').val().length;
    if (taille==0) valideChampsInsc(0, cible);
    else{
        valideChampsInsc(1, cible);
        $('#edit-field-profil-artiste-name-0-value').removeClass('error');
    }
}

function verifPrenomInsc(){
    var cible =  $('#conf-field-profil-firstname-0-value');
    var taille = $('#edit-field-profil-firstname-0-value').val().length;
    if (taille==0) valideChampsInsc(0, cible);
    else {
        valideChampsInsc(1, cible);
        $('#edit-field-profil-firstname-0-value').removeClass('error');
    }
}

function verifTelInsc(){
    var cible =  $('#conf-field-profil-mobile-0-value');
    var taille = $('#edit-field-profil-mobile-0-value').val().length;

    if (taille==10){
        valideChampsInsc(1, cible);
        $('#edit-field-profil-mobile-0-value').removeClass('error');
    }
    else if (taille == 0)
        valideChampsInsc(3, cible);
    else
        valideChampsInsc(0, cible);
 }

 function verifPseudoInsc() {
    var cible =  $('#conf-name');
    var taille = $('#edit-name').val().length;
    if (taille==0)
    {
        valideChampsInsc(0, cible);
    }
    else {
        valideChampsInsc(1, cible);
        $('#edit-name').removeClass('error');
    }
 }

 function verifMailInsc() {
    var cible =  $('#conf-mail');
    var test = $('#edit-mail').val();
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if(test.search(emailRegEx) == -1)
	{
		valideChampsInsc(0, cible);
	}
	else
	{
		valideChampsInsc(1, cible);
                $('#edit-mail').removeClass('error');
	} 
 }

 function valideChampsInsc(val, cible){ // val : 0 echec, 1 reussite, x autre
  if (val == 1) {
      cible.html('<img src="/sites/all/themes/sfr_jt/images/ico_ok.png" width = "14"  height = "14" />');
	  cible.show();
      cible.removeClass("error");
      cible.addClass("ok");
  } else if (val == 0) {
	  cible.html('<img src="/sites/all/themes/sfr_jt/images/ico_alert_red.png" width = "14"  height = "14" />');
	  cible.show();
	  cible.removeClass("ok");
	  cible.addClass("error");
  } else if (val == 2) {
	  cible.html('<img src="/sites/all/themes/sfr_jt/images/ico_alert_red.png" width = "14"  height = "14" /> Merci de corriger votre adresse email');
	  cible.show();
	  cible.removeClass("ok");
	  cible.addClass("error");
  } else {
	  cible.html('');
	  cible.show();
	  cible.removeClass("error");
	  cible.addClass("ok");
  }

}


function init_cycle_top_promo(){
	 if($('#slides .promo_cont').length) {
    	 $('#slides .promo_cont').eq(0).show();//AFFICHAGE DU PREMIER SLIDE
		if($('#slides .promo_cont .poster').length && !$('#promo_menu #promo_menu_cont .menu2').length) {
		    $('#promo_menu .shadow').css('margin-top','30px');
		    $('#slides .promo_cont .poster').show();
		} else {
		    $('#promo_menu .shadow').css('margin-top','1px');
		    $('#slides .promo_cont .poster').hide();
		}
		$('#slides').cycle({
		    fx: 'scrollHorz',
		    speed:  'slow',
		    timeout: 8000,
		    pauseOnPagerHover : true,
		    next:  '#slider .next',
		    prev:  '#slider .prev',
		    pager: '#slider .thumbs ul',
		    activePagerClass: 'active',
		    pagerAnchorBuilder: function(idx, slide) {
			return '#slider .thumbs ul li:eq(' + idx + ') a';
		    },
		    before : function(currSlideElement, nextSlideElement, options, forwardFlag) {
				$('#slider .promo_cont').css('z-index','');
				$('#slides').css('overflow','hidden');
				$('#promo_menu .shadow').css('margin-top','0px');
				$(currSlideElement).find('.poster').hide();
		    },
		    after : function(currSlideElement, nextSlideElement, options, forwardFlag) {
				$('#slider .promo_cont').css('z-index','');
				$('#slides').css('overflow','');
				if($(nextSlideElement).find('.poster').length && !$('#promo_menu #promo_menu_cont .menu2').length) {
				    $('#promo_menu .shadow').css('margin-top','30px');
				    $(nextSlideElement).find('.poster').show();
				}
		    }
		});
		var timer = null;
		$('#promo a.prev, #promo a.next, .thumbs').mouseenter(function() {
		    $('.thumbs').slideDown(300);
		    $('#slides').cycle('pause');
		    if (timer) {
		    	clearTimeout(timer);
		    	timer = null;
		    }
		});
		
		$('#promo .share_panel, #promo .sfr_vod_embed_code, #promo #slides, #promo .thumbs, #promo .share_mail_overlay').mouseenter(function() {
		    $('#slides').cycle('pause');
		    if (timer) {
		    	clearTimeout(timer);
		    	timer = null;
		    }
		}).mouseleave(function() {
		    timer = setTimeout(function() {
		    	$('.thumbs').slideUp(300);
		    	$('#slides').cycle('resume');
		    },1000);
		});
    }

    if($('#carrousel_concert .slide').length) {
		$('#carrousel_concert').after('<div id=\"nav\" class=\"nav1\">')
		.cycle({
		    fx:     'scrollHorz',
		    speed:  'slow',
		    timeout: 3000,
		    pager:  '#nav',
		    next:   '#carrousel .next',
		    prev:   '#carrousel .prev',
		    pauseOnPagerHover: true,
		    after : function(currSlideElement, nextSlideElement, options, forwardFlag) {
			$('#carrousel #nav').attr('class','nav'+$('#carrousel #nav a.activeSlide').html());
		    }
		});
    }
}
 
 function timer() {
	$(".promo_cont .visu .count").each(function(index) {
		var j = parseInt(10*(parseInt($(this).find("span.first").html()))+parseInt($(this).find("span.first").next("span").html()));
		var h = parseInt(10*(parseInt($(this).find("span.hour").html()))+parseInt($(this).find("span.hour").next("span").html()));
		var m = parseInt(10*(parseInt($(this).find("span.minu").html()))+parseInt($(this).find("span.minu").next("span").html()));
		var s = parseInt(10*(parseInt($(this).find("span.seco").html()))+parseInt($(this).find("span.seco").next("span").html()));
		
		var time = j*24*60*60 + h*60*60 + m*60 + s;
		timers_promo[index] = time;
		var timer = setInterval("newTimer("+index+")",1000);
	});
}

function initShare_panel(){
	if($(".shareit:not(.process)").length){
		$(".shareit .open").click(function(){
			$(this).parent().addClass("process");
			$(this).parent().toggleClass('active');
			return false
		});
		$(".shareit .close").click(function(){
			$(this).parent().parent().toggleClass('active');
			return false;	
		});
		
		//POSITION SHARE PANEL
		$(".shareit a.open").click(function(){
			var scrolltop = $(document).scrollTop();
			var winheight = $(window).height();
			var sfrvodlink = getPosition($(this));
			var sfrvodcode = $(this).next(".share_panel").height();
			if ((sfrvodlink[1]+sfrvodcode)>(scrolltop+winheight)) {
				var newposition = sfrvodcode ;
				$(this).next(".share_panel").css({"position":"absolute","top":"-"+newposition +"px !important"});
			}
			else {
				$(this).next(".share_panel").css({"position":"absolute","top":"20px !important"});
			}
		}); 
		
		//INIT SHARE MAIL
		$(".shareit .mail a").click(function(){
			displayPopInMailToAFriend($(this).attr("rel"));
			return false;
		});
		
	}
}

function initShare_done() {
	 setTimeout(function() {
		 initShare_panel();
	    },2000);
}

function initAlerte() {
	$('#alerte').cycle({
	    fx: 'scrollHorz',
	    speed:  'slow',
	    timeout: 8000
	});

}

// JS pour la taille des boites

function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}

function stopEmptySubmit(e)
{    
    var vide = false;
    $('#'+$(this).attr('id')+' .notEmpty').each(function (index, element)
    {
        if($(element).val().length<3)
        {
            vide = true;
        }
    });
    
    if(vide)
    {
        e.stopPropagation();
        return false;
    }
}

$(document).ready(function() {
	equalHeight($(".univers_artiste .box_verysmall, .univers_entrepreneurs .box_verysmall, .univers_sportifs .box_verysmall, .type_membres_list .box_verysmall"));				   
});
