// JavaScript Document



var S = {
	
	els : [],
	activeColor: '#EFEFEF',
	inactiveColor: '#CFCFCF',
	inactiveOpacity : 0.7,
	wobbly : false,
	
	closeAll: function(){
		S.els.morph({
			'height' : 80,
			'background-color' : S.inactiveColor,
			'opacity' : S.inactiveOpacity,
			'overflow' : 'hidden'
		});
		S.els.each( function(el){
			el.getElement('.txt').setStyle('height', 50);
			el.getElement('p').setStyle('display', 'none');
		});
		S.els.addClass('inactive-gallery');
	},
	
	closeOpenElement: function(){
		var el = $$('.active-gallery')[0];
		el.morph({
			'height' : 80,
			'background-color' : S.inactiveColor,
			'opacity' : S.inactiveOpacity
		});
		el.getElement('.txt').setStyle('height', 50);
		el.getElement('p').setStyle('display', 'none');
		el.removeClass('active-gallery');
		el.addClass('inactive-gallery');
	},
			
	openElement: function(){
		if( this.hasClass('inactive-gallery') ){
			this.morph({
				'height' : this.retrieve('startHeight'),
				'background-color' : S.activeColor,
				'opacity' : 1
			});
			(function(){
			this.getElement('.txt').setStyle('height', 170);
			this.getElement('p').setStyle('display', 'block');
			}).delay(600, this);
			this.removeClass('inactive-gallery');
			this.addClass('active-gallery');
		}
	},
	
	rollover: function(){
		if( this.hasClass('inactive-gallery') ){
			this.setOpacity(1);
		}
	},
	
	rolloff: function(){
		if( this.hasClass('inactive-gallery') ){
			this.setOpacity(S.inactiveOpacity);
		}
	},
	
	init: function(){
		S.els = $$('.gallery-index-item');
		S.els.each( function(el){
			el.store('startHeight', el.getSize().y);
			el.set('morph', {duration:500});
		});
		S.els.addEvent('mouseover', S.rollover);
		S.els.addEvent('mouseout', S.rolloff);
		S.els.addEvent('click', function(){
			if(this.hasClass('active-gallery')) return;		
			S.closeOpenElement();	
			if(S.wobbly){
				S.openElement.call(this);	
			}else{
				S.openElement.delay(500, this);
			}
		});
		S.closeAll();
		S.openElement.call(S.els[0]);
		
	}
	
	
	
}



window.addEvent('domready', S.init);