/*
 * LightBox Class
 * @author: 
 */
var LightBox = Class.create({ 
	initialize: function() {
		this.iterator= 0;
		this.list = null;
			
		$$(".clsZoomProduct").each(function(product,index) {
			product.observe("click",function(event) {
				event.stop();
				var element = event.element().up(".clsProduct");
				var background = new Element("div").setStyle({position:"absolute",top:"0px",width:"100%",height:$(document.body).getHeight()+"px",backgroundColor:"#FFF",opacity:0.7,zIndex:"999"});
				$(document.body).insert({bottom:background});		
				new Ajax.Request("/_ny/se/get_template/Produkt/"+event.element().up(".clsProduct").identify()+"/", {
					method:"post",
					parameters:"options[category]="+event.element().up(".clsProduct").readAttribute("data-category"),
					onComplete: function (response) {
						$(document.body).insert({top:response.responseText});
						$("idZoomProductWrapper").setStyle({top:(element.cumulativeOffset().top-200)+"px",left:(element.cumulativeOffset().left-120)+"px"});
						
						var gallery = $("idZoomProductWrapper").down(".clsGallery");
						var galleryConfig = gallery.up(".clsGalleryWrapper").down(".clsGalleryConfig");
						var galleryType = galleryConfig.down("input.clsGalleryType") ? galleryConfig.down("input.clsGalleryType").value : "";
						switch (galleryType) {
							case "autoChange" : this.currentGallery = new GalleryAutoChange(gallery,galleryConfig); break;
							case "clickChange" : this.currentGallery = new GalleryClickChange(gallery,galleryConfig); break;
							case "autoClickChange" : this.currentGallery = new GalleryAutoClickChange(gallery,galleryConfig); break;
							case "thumbChange" : this.currentGallery = new GalleryThumbChange(gallery,galleryConfig); break;
							default: this.currentGallery = new GalleryAutoChange(gallery,galleryConfig); break;
						}				
						
						$("close").observe("click",function() {
							$("idZoomProductWrapper").remove();
							background.remove();
							this.currentGallery = null;
						});
					}.bind(this)
				});
			});
		});
	}
});

$(document).observe("dom:loaded", function() {
	var lightBox = new LightBox();
});
