var tabs = {

	offsets: { 'home': -50, 'about-tzg': 100, 'projects': 198, 'press': 297, 'vacancies': 395, 'contact': 493 },

	init: function() {

		//add handlers
		$$('#tab-menu a').each( function(elm) {

			elm.observe( 'mouseover', function(e) {
	
				if( elm.hasClassName( 'selected' ) ) return;
				
				var href = elm.getAttribute('href');
				
				//IE bug
				if( href.match( /^.*\/([a-z\-]+)$/ ) ) href = href.replace( /^.*\/([a-z\-]+)$/, '$1' );
				
				//move the cover
				$('tabcover').setStyle( { top: tabs.offsets[ href ] + 'px' } )

				//highlight the text menu equivalent
				$$( '#' + elm.parentNode.id.replace( /tab/, 'text' ) + ' a' )[0].addClassName( 'selected' );
			   
			   
			});
			
			elm.observe( 'mouseout', function(e) {
	
				if( elm.hasClassName( 'selected' ) ) return;
				
				//move the cover
				$('tabcover').setStyle( { top: '-50px' } );
				
				//highlight the text menu equivalent
				$$( '#' + elm.parentNode.id.replace( /tab/, 'text' ) + ' a' )[0].removeClassName( 'selected' );
			   
				
			});
			
			elm.observe( 'click', function(e) {
		
				e.stop();
	
				if( elm.hasClassName( 'selected' ) ) return;
				
				var speed = 0.6;
				
				//animate tabs
				new Effect.Morph( 'tabs2', { style: { left: '-24px' }, duration: speed });
				
				setTimeout( function() { location.href = elm.href }, speed * 1000 );
				
			});
			
		});

		$$('#text-menu a').each( function(elm) {
			
			elm.observe( 'click', function(e) {

				e.stop();
	
				if( elm.hasClassName( 'selected' ) ) return;
				
				var speed = 0.6;
				
				//animate tabs
				new Effect.Morph( 'tabs2', { style: { left: '-24px' }, duration: speed });
				
				setTimeout( function() { location.href = elm.href }, speed * 1000 );
				
			});
		
		});
	
	}

}

var content = {

	hidden: false,
	height: 0,

	init: function() {
	
		if( !$('content') ) return;
	
		if( !$('toggle-text') ) return;
		
		//add handlers
		$('toggle-text').observe( 'click', function(e) {
			e.stop();
			if( content.hidden ) content.show();
			else content.hide();
		});
	
	},
	
	show: function() {
	
		var speed = 0.5;
	
		$('content').show();
		$('toggle-text').setStyle( { backgroundImage: 'url(images/hide-text.png)' } );

		//IE Bug
		if( is_ie ) $('content').setStyle( { height: '20px' } );

		new Effect.Morph( 'content', { style: { height: this.height + 'px' }, duration: speed });
	
		this.hidden = false;
	
	},
	
	hide: function() {
	
		var speed = 0.5;
		this.height = $('content').getHeight();
	
		$('toggle-text').setStyle( { backgroundImage: 'url(images/show-text.png)' } );
	
		new Effect.Morph( 'content', { style: { height: '0px' }, duration: speed });
		
		//IE Bug
		if( is_ie ) setTimeout( function() { $('content').setStyle( { display: 'none', height: '0px' } ) }, speed * 800 );
	
		this.hidden = true;
	
	}

}

Event.observe( document, 'dom:loaded', function() {
	content.init();
	tabs.init();
	try { if( projects ) projects.init(); } catch(e) {}
});

Event.observe( window, 'load', function() {
	new Effect.Morph ( 'tabs2', { style: { left: '0px' }, speed: 0.4 });
});
