window.addEvent('domready', function() {
	$$('#menu-mid td').addEvents({
		'mouseenter': function() {
			var p = this.getElement('p');
			if (p) {
				this.getElement('a').className = 'l1_on';
				
				p.setStyles({ visibility: 'hidden', display: 'block', overflow: 'visible', height: 'auto', opacity: 0 });
				var height = p.getSize().y;
				p.setStyles({ height: 0, visibility: 'visible', overflow: 'hidden' });
				p.set('morph', { transition: 'expo:out' }).morph({ height: height, opacity: 0.8 });
			}
		},
		'mouseleave': function() {
			var p = this.getElement('p');
			if (p) {
				this.getElement('a').className = 'l1';
				
				p.morph({ height: 0, opacity: 0 });
			}
		}
	});
});

var ServicePhotoNav = {};
ServicePhotoNav.labels = [];
ServicePhotoNav.photos = [];
ServicePhotoNav.init = function() {
	this.photos = $('header-cont').getElements('img');
	
	this.photos[0].className = 'tip';
	this.photos[1].className = 'pointer tip';
	this.photos[2].className = 'pointer tip';
	
	this.photos[0].set('title', '&nbsp;');
	this.photos[1].set('title', '&nbsp;');
	this.photos[2].set('title', '&nbsp;');
	
	this.photos[0].set('rel', this.labels[this.photos[0].get('src').replace(/(.+\/)|(_.+)/g, '')]);
	this.photos[1].set('rel', 'click for larger view');
	this.photos[2].set('rel', 'click for larger view');
	
	new Tips('.tip', { className: 'tooltip', offsets: { x: 14, y: 20 } });
	
	for (i = 1; i <= 2; i++)
		this.photos[i].addEvent('click', function() {
			var src = this.get('src');
			this.set('src', ServicePhotoNav.photos[0].get('src').replace(/_\d+/, '_' + src.replace(/.+_/g, '')));
			ServicePhotoNav.photos[0].set('src', src.replace(/_\d+/, '_2'));
			
			ServicePhotoNav.photos[0].store('tip:text', ServicePhotoNav.labels[src.replace(/(.+\/)|(_.+)/g, '')]);
		});
};

var NewsPhotoNav = {};
NewsPhotoNav.init = function() {
	$('news').getElements('img.thumb').addEvent('click', function() {
		var tmp = this.id.split('-');
		var id = tmp[1];
		var src = this.get('src');
		this.set('src', $('large' + id).get('src').replace(/_\d+/, '_' + src.replace(/.+_/g, '')));
		$('large' + id).set('src', src.replace(/_\d+/, '_2'));
	});
};
