/* galerie de RUpano chienjaune by heruraukoia
version: 1
date: 22/12/2011


 */
function RUgal(listXml,divDest){
	$.post(listXml, function(data){
	RUgalerieConstruct(data,divDest);
	});
}

function RUgalerieConstruct(dataXml,divCible) {
	$(divCible).html("");
	$(dataXml).find("item").each(function() {

		$(divCible).append('<div class="galeriePano" id="' + $(this).find("nomdiv").text() + '"></div>');	
		RUpano($(this).find("addrxml").text(),'#' + $(this).find("nomdiv").text());
		
	});

	var galPosition = 0;
	var largeurGallerie = 630;
	var hauteurGallerie = 470;
	var nbGallerie = $(".galeriePano", $(divCible)).length;
	
	$(".galeriePano",$(divCible))
		.wrapAll('<div class="galInner"></div>')
		.css({'margin' : '0px' , 'position' : 'relative' , 'width' : largeurGallerie , 'height' : hauteurGallerie});

	$(".galInner",$(divCible))
		.wrapAll('<div class="galcont"></div>')
		.css({'margin' : '0px' , 'position' : 'relative' , 'width' : largeurGallerie , 'height' : nbGallerie*hauteurGallerie});

	$(".galcont",$(divCible))
		.css({'margin' : '0px' , 'position' : 'relative' , 'width' : largeurGallerie , 'height' : '650px' , 'overflow' : 'hidden'})
		.append('<div class="galBandeauNav"><div class="galNav"><div class="galFleche" id="galFlecheHaut"><img src="rugalerie/bouton_ho.png"></div><div class="galFleche" id="galFlecheBas"><img src="rugalerie/bouton_bas.png"></div></div></div><div class="galCacheBas"></div>');
		
	$(".galBandeauNav",$(divCible))
	.css({'backgroundImage' : 'url("rugalerie/fond_gal.png")' , 'margin' : '0px' , 'top' : '373px' , 'position' : 'absolute' , 'width' : largeurGallerie , 'height' : '64px' , 'overflow' : 'hidden'});
	
	$(".galNav",$(divCible))
	.css({'margin' : '0px' , 'left' : '285px' , 'position' : 'relative' , 'width' : '60px' , 'height' : '64px' , 'overflow' : 'hidden'});
	
	$(".galFleche",$(divCible))
	.css({'margin' : '0px' , 'position' : 'relative' , 'width' : '60px' , 'height' : '30px' , 'overflow' : 'hidden'});
	
	$("#galFlecheHaut",$(divCible))
	.css({'position' : 'relative' , 'top' : '0px',"cursor" : "pointer"})
	.click(function () {
			$(".galInner", $(divCible)).animate({
				top : '+=470'}, 500
			);
			galPosition-=1;
			afficheGalFleche();	
	});

	$("#galFlecheBas",$(divCible))
	.css({'position' : 'relative' , 'top' : '4px',"cursor" : "pointer"})
	.click(function () {
			$(".galInner", $(divCible)).animate({
				top : '-=470'}, 500
			);
			galPosition+=1;
			afficheGalFleche();	
	});
	
	$(".galCacheBas",$(divCible))
	.css({'backgroundImage' : 'url("rugalerie/fond_gal.png")' , 'margin' : '0px' , 'top' : '437px' , 'position' : 'absolute' , 'width' : largeurGallerie , 'height' : '213px' , 'overflow' : 'hidden'});
	
	afficheGalFleche();

	function afficheGalFleche() {
		
		if (nbGallerie==1){
		$("#galFlecheHaut", $(divCible))
			.css({'visibility' : 'hidden'});

		$("#galFlecheBas", $(divCible))
			.css({'visibility' : 'hidden'});	
		}
		else {
			if (galPosition==0){
				$("#galFlecheHaut", $(divCible))
					.css({'visibility' : 'hidden'});
				$("#galFlecheBas", $(divCible))
					.css({'visibility' : 'visible'});
			}
			if (galPosition==nbGallerie-1){
				$("#galFlecheBas", $(divCible))
					.css({'visibility' : 'hidden'});
				$("#galFlecheHaut", $(divCible))
					.css({'visibility' : 'visible'});
			}
			if ((galPosition!=nbGallerie-1) && (galPosition!=0)){
				$("#galFlecheHaut", $(divCible))
					.css({'visibility' : 'visible'});
				$("#galFlecheBas", $(divCible))
					.css({'visibility' : 'visible'});
			}
		}
	}	
}
