﻿$(function(){
if($("#help").length>0){
    var etapeselec = window.location.hash;
	$(function(){
		i=0;
		j=0;
		$('hr').hide();
		$('#helpcontainer h3').each(function() {
			$("<div class='tophfooter'><div class='globalimagecall'><img alt='' src='http://www.xambox.fr/images/ImagesAide/System/mediaimage.png' /> Voir les images</div><div class='globalvideocall'><img alt='' src='http://www.xambox.fr/images/ImagesAide/System/mediavideo.png' /> Voir la vidéo</div></div>").insertAfter('h3:eq('+i+')');
			$("<div class='helpfooter'><div class='middlehfooter'><img class='minimize' src='http://www.xambox.fr/images/ImagesAide/System/reduire.png'/></div><div class='bottomhfooter'><div class='barcontainerhfooter'><div class='barhfooter'><div class='avancementfooter'></div></div><div class='barstepselection'></div></div><div class='prevhfooter'><img alt='' src='http://www.xambox.fr/images/ImagesAide/System/prevpage.png' /> Retour</div><div class='nexthfooter'><img alt='' src='http://www.xambox.fr/images/ImagesAide/System/nextpage.png' /> Suivant</div></div></div>").insertBefore('hr:eq('+i+')');
			$("h3").eq(i).nextUntil("hr").andSelf().wrapAll("<div class='diapo'/>");
			i=i+1;
		});
		if($(".firstpageaide").length>0){
			$(".diapo").hide();
		}
		else{
			$(".diapo").hide();
			$(".diapo").eq(0).show();
			if(j-1<0){
				$('.prevhfooter').addClass("historicback");
			}
		}
		i=i-1;
		j=0;
		$(".avancementfooter").text("Étape "+(j+1)+"/"+(i+1));
		$(".barhfooter").width(((j+1)/(i+1))*100+"%");
		locator=$(".active a").attr("href");
		if((locator=="/premiers-pas")||(locator==undefined)){
		locator="/faqxambox";
		}
		if(j+1>i){
			$('.nexthfooter').html("<a href='"+locator+"'>Formation terminée</a>");
		}
		if(j-1<0){
			if($(".firstpageaide").length==0){
				$('.prevhfooter').html("<img alt='' src='http://www.xambox.fr/images/ImagesAide/System/prevpage.png'/> Retour");
				$('.prevhfooter').addClass("historicback");
			}
		}
		for(var o=0; o <= i; o++){
		$(".barstepselection:eq("+j+")").append("<div style='width:"+((350-(2*(i+1)))/(i+1))+"px;' class='stepitem'>"+(o+1)+"</div>");
		}
		$(".stepitem:eq("+j+")").attr("id", "stepselect");
		$('.nexthfooter').click(function(){
			if(j+1<=i){
				$(".diapo").hide();
				$(".diapo").eq(j+1).fadeIn();
				j=j+1;
				$(".avancementfooter").text("Étape "+(j+1)+"/"+(i+1));
				$(".barhfooter").width(((j+1)/(i+1))*100+"%");
				window.location.hash = '#'+(j+1);
				if(j+1>i){
					$('.nexthfooter').html("<a href='"+locator+"'>Formation terminée</a>");
				}
				else{
				  $('.nexthfooter').html("Suivant <img alt='' src='http://www.xambox.fr/images/ImagesAide/System/nextpage.png'/>");
				}
				if(j-1<0){
				}
				else{
					$('.prevhfooter').html("<img alt='' src='http://www.xambox.fr/images/ImagesAide/System/prevpage.png'/> Retour");
					$('.prevhfooter').removeClass("historicback");
				}
			}
			else{
			}
			$(".barstepselection").empty();
			for(var o=0; o <= i; o++){
				$(".barstepselection:eq("+j+")").append("<div style='width:"+((350-(2*(i+1)))/(i+1))+"px;' class='stepitem'>"+(o+1)+"</div>");
			}
			$(".stepitem:eq("+j+")").attr("id", "stepselect");
		});
		$('.prevhfooter').click(function(){
			if(j-1>=0){
				$(".diapo").hide();
				$(".diapo").eq(j-1).fadeIn();
				j=j-1;
				$(".avancementfooter").text("Étape "+(j+1)+"/"+(i+1));
				$(".barhfooter").width(((j+1)/(i+1))*100+"%");
				window.location.hash = '#'+(j+1);
				if(j+1>i){
					$('.nexthfooter').html("<a href='"+locator+"'>Formation terminée</a>");
				}
				else{
					$('.nexthfooter').html("Suivant <img alt='' src='http://www.xambox.fr/images/ImagesAide/System/nextpage.png'/>");
				}
			}
			else{
				if(j-1<0){
								if($(".firstpageaide").length>0){
									$(".firstpageaide").fadeIn();
									$(".diapo").hide();
								}
								else{
									location="javascript:history.back()";
								}
				}
				else{
					$('.prevhfooter').html("<img alt='' src='http://www.xambox.fr/images/ImagesAide/System/prevpage.png'/> Retour");
				}
			}
			$(".barstepselection").empty();
			for(var o=0; o <= i; o++){
				$(".barstepselection:eq("+j+")").append("<div style='width:"+((350-(2*(i+1)))/(i+1))+"px;' class='stepitem'>"+(o+1)+"</div>");
			}
			$(".stepitem:eq("+j+")").attr("id", "stepselect");
		});
		$('.navaideback').click(function(){
			$(".firstpageaide").fadeIn();
			$(".diapo").hide();
		});
		$('.commenceraide').click(function(){
			$(".diapo").eq(0).fadeIn();
			$(".firstpageaide").hide();
			window.location.hash = '#'+(j+1);
			$(".barstepselection").empty();
			for(var o=0; o <= i; o++){
			$(".barstepselection:eq("+j+")").append("<div style='width:"+((350-(2*(i+1)))/(i+1))+"px;' class='stepitem'>"+(o+1)+"</div>");
			}
			$(".stepitem:eq("+j+")").attr("id", "stepselect");
		});
		$('.retouraide').click(function(){
			location=locator;
		});
		if(etapeselec != ''){
			etapeselec = etapeselec.substring(1);
			etapeselec = etapeselec-1;
			if($('.diapo:eq('+etapeselec+')').length>0){
				j = etapeselec;
				$(".diapo").hide();
				$(".firstpageaide").hide();
				$('.diapo:eq('+etapeselec+')').fadeIn();
				$(".avancementfooter").text("Étape "+(etapeselec+1)+"/"+(i+1));
				$(".barhfooter").width(((etapeselec+1)/(i+1))*100+"%");
				if(etapeselec+1>i){
					$('.nexthfooter').html("<a href='"+locator+"'>Formation terminée</a>");
				}
				else{
				  $('.nexthfooter').html("Suivant <img alt='' src='http://www.xambox.fr/images/ImagesAide/System/nextpage.png'/>");
				}
				if(etapeselec-1<0){
				}
				else{
					$('.prevhfooter').html("<img alt='' src='http://www.xambox.fr/images/ImagesAide/System/prevpage.png'/> Retour");
					$('.prevhfooter').removeClass("historicback");
				}
				$(".barstepselection").empty();
				for(var o=0; o <= i; o++){
					$(".barstepselection:eq("+etapeselec+")").append("<div style='width:"+((350-(2*(i+1)))/(i+1))+"px;' class='stepitem'>"+(o+1)+"</div>");
				}
				$(".stepitem:eq("+etapeselec+")").attr("id", "stepselect");
			}
		}
		$('.stepitem').live('click',function(){
			etapeselec=$('.stepitem').index(this);
			j = etapeselec;
			$(".diapo").hide();
			$(".firstpageaide").hide();
			$(".barhfooter").css("margin-top", "0px");
			$('.diapo:eq('+etapeselec+')').fadeIn();
			$(".avancementfooter").text("Étape "+(etapeselec+1)+"/"+(i+1));
			$(".barhfooter").width(((etapeselec+1)/(i+1))*100+"%");
			if(etapeselec+1>i){
				$('.nexthfooter').html("<a href='"+locator+"'>Formation terminée</a>");
			}
			else{
			  $('.nexthfooter').html("Suivant <img alt='' src='http://www.xambox.fr/images/ImagesAide/System/nextpage.png'/>");
			}
			if(etapeselec-1<0){
			}
			else{
				$('.prevhfooter').html("<img alt='' src='http://www.xambox.fr/images/ImagesAide/System/prevpage.png'/> Retour");
				$('.prevhfooter').removeClass("historicback");
			}
			$(".barstepselection").empty();
			for(var o=0; o <= i; o++){
				$(".barstepselection:eq("+etapeselec+")").append("<div style='width:"+((350-(2*(i+1)))/(i+1))+"px;' class='stepitem'>"+(o+1)+"</div>");
			}
			$(".stepitem:eq("+etapeselec+")").attr("id", "stepselect");
			window.location.hash = '#'+(j+1);
		});
	});
	
	
	$(function(){
		m=0;
		l=0;
		k=0;
		slide=0;
		var currentImg=new Array();
		var firstImg=new Array();
		firstImg[0]=0;
		$('.illustration').hide();
		$('object').hide();
		$('.diapo').each(function(){
		l=0;
		$(".diapo:eq("+k+") img[class='illustration']").wrapAll("<div class='slide'/>");
		$(".diapo:eq("+k+") object").wrap("<div class='videoslide'/>");
			imglgt = $(".slide:eq("+k+") img[class='illustration']").length;
			vidlgt = $(".videoslide:eq("+k+") object").length;
			if(imglgt > 0){
				$(".tophfooter:eq("+k+")").show();
				$(".tophfooter:eq("+k+") div[class='globalimagecall']").show();
			}
			else{
				$("<div class='slide'/>").insertBefore('hr:eq('+k+')')
				firstImg[k+1]=m;
			}
			if(vidlgt > 0){
				$(".tophfooter:eq("+k+")").show();
				$(".tophfooter:eq("+k+") div[class='globalvideocall']").show();	
			}
			else{
				$("<div class='videoslide'/>").insertBefore('hr:eq('+k+')')
			}
			m=m+imglgt;
			$('.slide:eq('+k+') img').each(function() {
				firstImg[k+1]=m;
				l++;
			});
			$("<div class='prevslide'><div></div></div><div class='nextslide'><div></div></div>").insertBefore('.slide:eq('+k+')');
			$(".prevslide:eq("+k+")").nextUntil(":not(.prevslide, .slide, div[class='nextslide'])").andSelf().wrapAll("<div class='slider'/>");
			$(".middlehfooter:eq("+k+")").append($(".slider:eq("+k+")"));
			$(".slider:eq("+k+")").append($(".videoslide:eq("+k+")"));
			k++;
		});
		
		b = 0;
		$(".diapo").each(function () {
			imglgt = $(".slide:eq(" + b + ") img[class='illustration']").length;
			vidlgt = $(".videoslide:eq(" + b + ") object").length;
			if (vidlgt > 0) {
				$(".diapo:eq(" + b + ") object").hide();
				$('.diapo:eq(" + b + ") img[class="illustration"]').hide();
				$(".videoslide:eq(" + b + ") object").show();
				$(".middlehfooter:eq(" + b + ")").height("auto");
				$(".diapo:eq(" + b + ") span[class='imagecall']").removeAttr("id", "currentillustration")
			} else {
				if (imglgt > 0) {
					currentImg[b] = firstImg[b];
					$(".diapo:eq(" + b + ") span[class='imagecall']").removeAttr("id", "currentillustration");
					$(".imagecall").eq(currentImg[b]).attr("id", "currentillustration");
					$(".diapo:eq(" + b + ") object").hide();
					$('.diapo:eq(" + b + ") img[class="illustration"]').hide();
					$(".illustration").eq(currentImg[b]).show();
					$(".middlehfooter:eq(" + b + ")").height("auto");
					if (firstImg[b] == currentImg[b]) {
						$(".diapo:eq(" + b + ") div[class='prevslide']").fadeTo(0, 0)
					}
					if ((firstImg[b + 1]) - 1 != currentImg[b]) {
						$(".diapo:eq(" + b + ") div[class='nextslide']").fadeTo(0, 1)
					}
					if ((firstImg[b + 1]) - 1 == currentImg[b]) {
						$(".diapo:eq(" + b + ") div[class='nextslide']").fadeTo(0, 0)
					}
					if (firstImg[b] != currentImg[b]) {
						$(".diapo:eq(" + b + ") div[class='prevslide']").fadeTo(0, 1)
					}
					$(".diapo:eq(" + b + ") div[class='prevslide'], div[class='nextslide']").hide()
				}
			}
			b++
		});
		
		$('div[class="prevslide"], div[class="nextslide"]').hide();
		h=0;
		$('.nextslide div').click(function(){
			slide=$('.nextslide div').index(this);
			if((firstImg[slide+1])-1>currentImg[slide]){
				currentImg[slide]++;
				$('.diapo:eq('+slide+') img[class="illustration"]').hide();
				$('.illustration').eq(currentImg[slide]).show();
				$('.diapo:eq('+slide+') span[class="imagecall"]').removeAttr('id', 'currentillustration');
				$('.imagecall').eq(currentImg[slide]).attr('id', 'currentillustration');
				if((firstImg[slide+1])-1==currentImg[slide]){
					$('.diapo:eq('+slide+') div[class="nextslide"]').fadeTo(0,0);
				}
				if(firstImg[slide]!=currentImg[slide]){
					$('.diapo:eq('+slide+') div[class="prevslide"]').fadeTo(0,1);
				}
			}
		});
		$('.prevslide div').click(function(){
			slide=$('.prevslide div').index(this);
			if(firstImg[slide]<currentImg[slide]){
				currentImg[slide]--;
				$('.diapo:eq('+slide+') img[class="illustration"]').hide();
				$('.illustration').eq(currentImg[slide]).show();
				$('.diapo:eq('+slide+') span[class="imagecall"]').removeAttr('id', 'currentillustration');
				$('.imagecall').eq(currentImg[slide]).attr('id', 'currentillustration');
				if(firstImg[slide]==currentImg[slide]){
					$('.diapo:eq('+slide+') div[class="prevslide"]').fadeTo(0,0);
				}
				if((firstImg[slide+1])-1!=currentImg[slide]){
					$('.diapo:eq('+slide+') div[class="nextslide"]').fadeTo(0,1);
				}
			}
		});
		$('.slide, div[class="prevslide"], div[class="nextslide"]').mouseover(function(){
			$('div[class="prevslide"], div[class="nextslide"]').show();
		});
		$('.slide, div[class="prevslide"], div[class="nextslide"]').mouseleave(function(){
			$('div[class="prevslide"], div[class="nextslide"]').hide();
		});
		$('.imagecall').click(function(){
		h=$('.imagecall').index(this);
		for(var slide=0; slide < firstImg.length; slide++){
			if(h<firstImg[slide]){
			   slide--;
			   break;
			}
		}
		currentImg[slide]=h;
		$('.diapo:eq('+slide+') span[class="imagecall"]').removeAttr('id', 'currentillustration');
		$(this).attr('id', 'currentillustration');
		$('.diapo:eq('+slide+') img[class="illustration"]').hide();
		$('.diapo:eq('+slide+') object').hide();
		$('.illustration').eq(currentImg[slide]).show();
		$('.middlehfooter:eq('+slide+')').height("auto");
		if(firstImg[slide]==currentImg[slide]){
			$('.diapo:eq('+slide+') div[class="prevslide"]').fadeTo(0,0);
		}
		if((firstImg[slide+1])-1!=currentImg[slide]){
			$('.diapo:eq('+slide+') div[class="nextslide"]').fadeTo(0,1);
		}
		if((firstImg[slide+1])-1==currentImg[slide]){
			$('.diapo:eq('+slide+') div[class="nextslide"]').fadeTo(0,0);
		}
		if(firstImg[slide]!=currentImg[slide]){
			$('.diapo:eq('+slide+') div[class="prevslide"]').fadeTo(0,1);
		}
		$('.diapo:eq('+slide+') div[class="prevslide"], div[class="nextslide"]').hide();
		});

		$('.globalimagecall').click(function(){
			slide=$('.globalimagecall').index(this);
			currentImg[slide]=firstImg[slide];
			$('.diapo:eq('+slide+') span[class="imagecall"]').removeAttr('id', 'currentillustration');
			$('.imagecall').eq(currentImg[slide]).attr('id', 'currentillustration');
			$('.diapo:eq('+slide+') object').hide();
			$('.diapo:eq('+slide+') img[class="illustration"]').hide();
			$('.illustration').eq(currentImg[slide]).show();
			$('.middlehfooter:eq('+slide+')').height("auto");
			if(firstImg[slide]==currentImg[slide]){
				$('.diapo:eq('+slide+') div[class="prevslide"]').fadeTo(0,0);
			}
			if((firstImg[slide+1])-1!=currentImg[slide]){
				$('.diapo:eq('+slide+') div[class="nextslide"]').fadeTo(0,1);
			}
			if((firstImg[slide+1])-1==currentImg[slide]){
				$('.diapo:eq('+slide+') div[class="nextslide"]').fadeTo(0,0);
			}
			if(firstImg[slide]!=currentImg[slide]){
				$('.diapo:eq('+slide+') div[class="prevslide"]').fadeTo(0,1);
			}
			$('.diapo:eq('+slide+') div[class="prevslide"], div[class="nextslide"]').hide();
		});

		$('.globalvideocall').click(function(){
			slide=$('.globalvideocall').index(this);
			$('.diapo:eq('+slide+') object').hide();
			$('.diapo:eq('+slide+') img[class="illustration"]').hide();
			$('.videoslide:eq('+slide+') object').show();
			$('.middlehfooter:eq('+slide+')').height("auto");
			$('.diapo:eq('+slide+') span[class="imagecall"]').removeAttr('id', 'currentillustration');
			});

		$('.minimize').click(function(){
			slide=$('.minimize').index(this);
			$('.middlehfooter:eq('+slide+')').height("0px");
			$('.diapo:eq('+slide+') span[class="imagecall"]').removeAttr('id', 'currentillustration');
		});	
	});
}

		$(function(){
			u=2;
			$('.descriptiondl').hide();
			$('#Send2Xambox').show();
			$('#selectdl').change(function(){
				var u = document.selectdl.selectdl2.selectedIndex;
				$('.descriptiondl').hide();
				$('.descriptiondl').eq(u).fadeIn();
			});
		});

		$(function(){
		wait=false;
		timer=900;
			$(".minitem").hover(function(){
				var $h=$(this).children(".minitemetadata");
				if($h.length){
					wait=setTimeout(function (){
						$h.fadeIn();
					} , timer);
				}
			},
			function(){
				clearTimeout(wait);
				$(".minitemetadata").fadeOut();
			});
		});

		$(function(){
            if(i>1){
			wait2=false;
			timer2=400;
				$(".barcontainerhfooter").hover(function(){
					$g=$(this).children(".barhfooter");
					wait2=setTimeout(function (){
						$g.animate({marginTop: '-30px'},{queue:false,duration:200});
					} , timer2);
				},
				function(){
						clearTimeout(wait2);
						$g.animate({marginTop: '0px'},{queue:false,duration:150});
				});
			}
		});	
		
});
