window.addEvents ({
	domready: function() {
		// Amagar capes de general
		te_text = $chk($('Text'));
		if (te_text)
			$('Text').setStyle ('opacity', 0);
		if (te_text) {
			$('Text').set ('morph', {duration:1000 });
			$('Text').morph ({opacity : 1});
		}

		// Amagar capes de galeria
		var thumbs = $$("#Treballs a");
		var treballs = $$('#Apartats li.ex');
		var descripcions = $$("#Descripcions li");
		if (thumbs.length > 0) {
			descripcions.setStyle ('opacity', 0);
			treballs.setStyle ('opacity', 0);
			$('ap0').setStyle ('opacity', 1);
		}
	},
	
	load: function () {
		te_text = $chk($('Text'));

		// Funcions botons
		if (Browser.ie) {
			var botons = $$('ul#Menu li a');
			var cartells = $$('ul#Menu li a h3');
			botons.each(function(el, i) {
				el.set('morph', {link : 'cancel'});
				el.addEvents({
					'mouseenter': function() {
						cartells[i].morph({
							'opacity' : 1,
							'top' : '-65px'
						});
					},
					'mouseleave' : function() {
						cartells[i].morph({
							'opacity' : 0,
							'top' : 0
						});
					}
				});
			});
		}

		var thumbs = $$("#Treballs a");
		var treballs = $$('#Apartats li.ex');
		var descripcions = $$("#Descripcions li");
		if (thumbs.length > 0) {
			// Funcions de galeria
			var efAnar = {
				transition: Fx.Transitions.Back.easeOutExpo,
				duration: 1000
			};
			descripcions.set ('tween', efAnar);
			treballs.set ('morph', efAnar);
			tanque = null;
			thumbs.addEvents ({
				mouseenter: function(e){
					e.stop();
					num = $(this).get('rel').toInt();
					$("ap"+num).setStyle ('position', 'absolute');
					$("ap"+num).setStyle ('top', 0);
					$("ap"+num).morph ({ position: 'absolute', zIndex: 10000, opacity: 1 /*, top: 0 */ });
					$('Desc'+num).morph ({opacity:1});
					if (tanque != null) $clear (tanque);
					$("ap0").setStyles ({position: 'absolute'});
					$("ap0").tween ('left', '-' + $('ap0').getStyle ('width'));
				},
				mouseleave: function(e){
					e.stop();
					num = $(this).get('rel').toInt();
					$("ap"+num).setStyle ('position', 'absolute');
					$("ap"+num).setStyle ('top', 0);
					$("ap"+num).morph ({ position: 'absolute', zIndex: 5000, opacity: 0 /*, top: $('ap'+num).getStyle ('height') */ });
					$('Desc'+num).morph ({opacity:0});
					tanque = (function () { $("ap0").tween ('left', 0) }).delay (500);
				},
				click: function(e){
					e.stop();
					e.stopPropagation();
				}
			});
		}
		
	}
});

