var WrapperRayante = new Class({
	wrappers :[],
	
	initialize: function(container)
	{
		this.container = $(container);
		this.parse();
		this.wrappers.each(function(wrapper, index)
			{
				wrapper.originalHeight = wrapper.getHeight();
				if(index!=0)
				{
					wrapper.setStyles({"height":"0px", "overflow":"hidden"});
				}
			});
	},
	
	parse: function()
	{
		this.container.getElements("h2").each(this.wrappea.bind(this));
	},
	
	wrappea: function(element)
	{
		this.currentWrapper = new Element("div", {"class":"wrapper"});
		this.currentWrapper.set("morph", {duration:300, transition:"Quint:out"});
		this.wrappers.push(this.currentWrapper);
		element.setStyle("cursor","pointer");
		element.addEvent("click", this.switchWrapper.bindWithEvent(this, [this.currentWrapper]));
		
		if($defined(this.currentWrapper))
			this.currentWrapper.wraps(element.getNext("ul"));	
	},
	
	switchWrapper : function(e, wrapper)
	{
		this.wrappers.each(function(thisWrapper){
			if(thisWrapper != wrapper) this.close(thisWrapper);
			else
			{
				this.open(thisWrapper);
			}
		}.bind(this));
	},
	
	open: function(wrapper)
	{
		//console.log(wrapper.originalHeight);
		wrapper.morph({"height":wrapper.originalHeight});
	},
	
	close: function(wrapper)
	{
		wrapper.morph({"height":"0px"});
	}
});

document.addEvent("domready", function(){
	
	var wrapper = new WrapperRayante($("photoGallery"));
	$$("#photoGallery ul li a").addEvent("click", function(e){
		pageTracker._trackPageview(this.get("href"));
	});
	
	/*$$("#photoGallery ul li a").addEvent("click", function(e){
		e.stop();
		var loader = new Element("div", {"id":"ajaxLoader"});
		loader.setStyle("opacity", ".5");
		loader.injectOver(this.getFirst());
		
		new Request.JSON({url:this.get("href"), onComplete: function(response){
			loader.destroy();
			$("currentPicture").set("html", "");
			$("currentPicture").set("html", response.image+"<b>"+response.hotelName+"</b>: "+response.description);
			try 
			{
				pageTracker._trackPageview(this.get("href"));
				document.inlineEdit.parseDom();
			}
			catch(exception) {
				
			}
		}.bind(this)}).send();
	});*/
	
});