// JavaScript Document
function vue_standart(img){
	var image_std = $('image_std_fiche');
	if (image_std.tagName == 'IMG'){
		//on affiche la barre de chargement;
		image_std.src = '/images/smoothgallery/loading-bar-black_fiche.gif'
		new Asset.image(img.src.replace('fiche_mini', 'fiche'), {onload: function(){
			new Fx.Style(image_std, 'opacity').set(0);
			image_std.src = img.src.replace('fiche_mini', 'fiche');
			new Fx.Style(image_std, 'opacity').start(0,1);
		}});
	}else if(image_std.tagName == 'DIV'){
		//on affiche la barre de chargement;
		image_std.style.backgroundImage = 'url(/images/smoothgallery/loading-bar-black_fiche.gif)'
		new Asset.image(img.src.replace('fiche_mini', 'fiche'), {onload: function(){
			new Fx.Style(image_std, 'opacity').set(0);
			image_std.style.backgroundImage = 'url('+img.src.replace('fiche_mini', 'fiche')+')';
			new Fx.Style(image_std, 'opacity').start(0,1);
		}});
	}
}
function vue_zoom(img){	
	if($('container') != null){
			$('container').remove();
	}
	
	container = new Element('div', {
										'styles': 
										{
											'display': 'block',
											'width': '100%',
											'height': '100%',
											'padding': '0px',
											'left': '0',
											'margin': '0px',
											'position': 'fixed',
											'top': '0',
											'text-align': 'center',
											'background-image': 'url(/images/overlay.png)',
											'z-index': '5'
										}
								  }
							);
	
	if (window.ie && !window.ie7){
		container.style.position = 'absolute';
		container.style.height = document.documentElement.clientHeight;
		container.style.background = 'none';
		container.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='/images/overlay.png')";
		container.style.zIndex = '0';
		
		container2 = new Element('div', {
										'styles': 
										{
											'display': 'block',
											'width': '100%',
											'height': '100%',
											'padding': '0px',
											'left': '0',
											'margin': '0px',
											'position': 'absolute',
											'top': '0',
											'text-align': 'center',
											'z-index': '10'
										}
								  }
							);
		//pour ie6 (pour avoir les liens cliquables
		container2.setAttribute('id','container2');
		container2.injectInside(document.body);
	}
			  
	container.setAttribute('id','container');
	
	container.injectInside(document.body);
	 
	var gallery = new Element('div', {
										'styles': 
										{
											'display': 'block',
											'width': '700px',
											'height': '550px',
											'background': '#FFF',
											'padding': '0px',
											'text-align': 'left',
											'margin':'0 auto'
										}
			  						  }
			  				);
	 
	gallery.setAttribute('id','gallery');
	
	if (window.ie && !window.ie7){
		gallery.injectInside(container2);
	}else{
		gallery.injectInside(container);
	}
	
	valigncenter(gallery);
	var myFx = new Fx.Style(gallery, 'opacity').set(0);
	 
	//url recuperant les photos à afficher
	var url='/pl/liste_photos_gallerie.pl';
	new Ajax(url, {
		method: 'get',
		update: $('gallery'),
		data: 'itm='+$('itm').value+'&itm_nom='+$('nom_produit').innerHTML,
		onSuccess: function(){
	 		startGallery();
			new Fx.Style(gallery, 'opacity').start(0,1);
			//on ajoute la fermeture du slidewhow sur le clic sur l'image
			$$('.slideElement').addEvent('click', endGallery);
			//on ajoute l'indication que l'image est clicable et que le clic ferme la gallery
			$$('.slideElement').setProperties({title : 'Fermer', alt : 'Fermer'});
			$$('.slideElement').setStyles({'cursor' : 'pointer'});
			
			var bouton_fermer = new Element('a', {
													'styles': 
													{
														'position': 'absolute',
														'bottom': '0',
														'right': '30px',
														'height': '20px',
														'text-align': 'center',
														'padding': '0 10px',
														'font-size': '13px',
														'background': '#333',
														'color': '#fff',
														'cursor': 'pointer'
													}
												 }
										);
			bouton_fermer.innerHTML = 'Fermer';
			bouton_fermer.setProperties({title : 'Fermer', alt : 'Fermer'});
			bouton_fermer.injectInside($$('.carouselContainer')[0]);
			//on ajoute la fermeture du slidewhow sur le clic sur le bouton
			bouton_fermer.addEvent('click', endGallery);
			
			//on colore en rouge l'interface (ou pas :) )
			/*$$('.carouselBtn')[0].setStyles('background-color: #462a1c;');
			$$('.carousel')[0].setStyles('background-color: #462a1c;');
			$$('.slideInfoZone')[0].setStyles('background-color: #462a1c;');*/
		}
	}).request();
}
function endGallery(){
	var container = $('container');
	//effet de fondu avant la fermeture
	new Fx.Style(container, 'opacity', {onComplete : function(){
																//on detruit la galeries
																container.remove();
																if (window.ie && !window.ie7){
																	$('container2').remove();																															
																}
															   }
									   }
				 ).start(1,0);
}
function startGallery() {
	var myGallery = new gallery($('gallery'), {
		timed: true,
		defaultTransition: "fadeslideleft",
		showArrows: false,
		showCarousel: true,
		embedLinks: false,
		textPreloadingCarousel : "Chargement...",
		textShowCarousel : "Voir toutes les photos"
	});
}
function valigncenter(lmt)
{
	var page = document.documentElement;
	if(lmt && page)
	{
	    var containerHeight;
	    if (page.innerWidth)
	    {
            containerHeight = page.innerHeight;
		}
		else
		{
            containerHeight = page.clientHeight;
		}
	    var lmtHeight;
	    if (lmt.innerWidth)
	    {
            lmtHeight = lmt.innerHeight;
		}
		else
		{
            lmtHeight = lmt.offsetHeight;
		}
		var y = Math.ceil((containerHeight - lmtHeight) / 2);
		if(y < 0)
		{
			y = 0;
		}
		lmt.style.position = "relative";
		lmt.style.top = y + "px";
	}
	if (document.getElementById)
	{
		document.body.style.visibility = 'visible';
	}
}
