/**
*
* zoom
* zoom gère l'apparition des "zoom" d'image sur totutes les pages ou il est chargé
* by www.g-u-i.net
* depend on prototype 1.6.0 and scriptaculous 1.8.0
*
*/


function Zoom() {
	if (typeof Zoom.initialized == "undefined"){
		Zoom.prototype.showBigCouv = function(event){
			var couvNum = Event.element(event).readAttribute('couvnum');
			var couvZoomable;
			var divBigCouv;
			document.getElementsByClassName('couvZoomable').each(function(elmt){
				if(elmt.readAttribute('couvnum') == couvNum){
					couvZoomable = elmt;
				}
			});
			document.getElementsByClassName('couvZoom').each(function(elmt){
				if(elmt.readAttribute('couvnum') == couvNum){
					divBigCouv = elmt;
				}
			});
			if(!divBigCouv.visible()){
				divBigCouv.show();
				var backGround = divBigCouv.down('div.back');
				backGround.setStyle({opacity:0});
				var inner = divBigCouv.down('div.inner');
				inner.setStyle({opacity:0});
				var pos_Zoomable = Position.cumulativeOffset(couvZoomable);
				var x_bulle = pos_Zoomable[0] + couvZoomable.getWidth() + 15;
				var y_bulle = pos_Zoomable[1] + couvZoomable.getHeight() - divBigCouv.getHeight() + 2;
				divBigCouv.setStyle({
					top:y_bulle+"px",
					left:x_bulle+"px"
				});
				new Effect.Opacity($(backGround), {duration: 0.2, from:0, to:0.8, afterFinish:function(elmt){
						var cont = elmt.element.next('div');
						new Effect.Appear($(cont), {duration: 0.3});
					}
				});
				Effect.ScrollTo(divBigCouv);
				zoom.hideAllBigCouv(couvNum);
			}
		};
		Zoom.prototype.hideBigCouv = function(event){
			var divBigCouv = Event.element(event).up('div').up('div');
			event.stop();
			var inner = divBigCouv.down('div.inner');
			new Effect.Opacity($(inner), {duration: 0.3, from:0.8, to:0, afterFinish:function(elmt){
					var back = elmt.element.previous('div');
					new Effect.Opacity($(back), {duration: 0.2, from:1, to:0, afterFinish:function(elmt){
							elmt.element.up('div').hide();
						}
					});
				}
			});
		};
		Zoom.prototype.hideAllBigCouv = function(eccept){
			var divBigCouv;
			document.getElementsByClassName('couvZoom').each(function(elmt){
				if(elmt.readAttribute('couvnum') != eccept){
					divBigCouv = elmt;
					var inner = divBigCouv.down('div.inner');
					new Effect.Opacity($(inner), {duration: 0.3, from:0.8, to:0, afterFinish:function(elmt){
							var back = elmt.element.previous('div');
							new Effect.Opacity($(back), {duration: 0.2, from:1, to:0, afterFinish:function(elmt){
									elmt.element.up('div').hide();
								}
							});
						}
					});
				}
			});
		};
			
	}
};
function startZoom(event){
	zoom = new Zoom();
	var ar_couvZoomable = document.getElementsByClassName('couvZoomable');
	ar_couvZoomable.each(function(elmt){
		Event.observe(elmt, 'click', function(event){
			zoom.showBigCouv(event);
			event.stop();
		});
	});
	var ar_zoomCouv = document.getElementsByClassName('zoomCouv');
	ar_zoomCouv.each(function(elmt){
		Event.observe(elmt, 'click', function(event){
			zoom.showBigCouv(event);
			event.stop();
		});
	});
	document.getElementsByClassName('dezoom').each(function(elmt){
		Event.observe(elmt, 'click', function(event){
			zoom.hideBigCouv(event);
			event.stop();
		});
	});
	event.stop();
};
Event.observe(window, 'load', startZoom);