// JavaScript Document
var body = document.body,
html = document.documentElement;

var textColumnWidth = 230;
var defaultScrollSpeed = 0.3;

document.observe('dom:loaded',function() {

	if($('splash')) { 
		
		$$('splashLogo').each(function(el) { 
			el.fade();
		});

	
		$$('.innerContainer').each(function(el,count) {
			new Effect.Opacity(el, { from: 1.0, to: 0, duration: 0.4, delay: 3.2 });
		});
	
		new Effect.Move('splash', { x: 0, y: ($('splash').getHeight()*3), mode: 'relative',delay: 3.0, duration:1.5 }); 
		setTimeout("$('splash').hide();$('splashLogo').hide();",3500);
	}


	$$('.coverup-large').each(function(el) {
		$(el).observe('mouseover',function() {
			//.$$('.coverup-large').each(function(ele) {
				new Effect.Opacity(el,{from: 0, to: 0.8, duration: 0.5, queue: { scope: $(el).identify() }});
			//	});
		});
	});
	
	$$('.coverup-large').each(function(el) {
		$(el).observe('mouseout',function() {
			//.$$('.coverup-large').each(function(ele) {
				new Effect.Opacity(el,{from: 0.8, to: 0.0, duration: 0.5, queue: { scope: $(el).identify() }});
			//	});
		});
	});



	var paginationCount = 0;
	$$('#main-content-text-container-scroller .column').each(function(el) {
		paginationCount+=1;
	});
	
	$$('a.pagination-previous').each(function(butEl) {
		new Effect.Opacity(butEl,{from: 1, to: 0.5});
	});
	
								
	var footerHeight = (html.clientHeight-$('footer-container').getStyle('marginTop').replace('px',''));
	if(footerHeight > 130) {
		$('footer-container').setStyle({height:(footerHeight-17)+'px'});
	} else {
		
		$('footer-container').setStyle({height:'130px'});
	}
									   
	// Handler for menu slider
	$$('a.menu').each(function(el) {
		el.observe('click',function() {
			el.toggleClassName('current');
			if(el.hasClassName('current')) {
				el.update('Close');
				showHideMenu('show');
			} else {
				el.update('Menu');
				showHideMenu('hide');
			}
		});						   
	});	
	if(showMenu == false) {
		setTimeout("showHideMenu('hide');",1000);
	} else {
		$$('a.menu').each(function(el) {
			el.toggleClassName('current');
			el.update('Close');
	   });
	}
	
	// Handler for content pagination
	$$('a.pagination-previous').each(function(el) {
		el.observe('click',function() {
			$$('a.pagination-next').each(function(butEl) {
				if(butEl.getStyle('opacity') < 1) {
					new Effect.Opacity(butEl,{from: 0.5, to: 1});
				}
			});
			
			$$('#main-content-text-container-scroller .column').each(function(innerEl) {
				if((innerEl.getStyle('left').replace('px','')*-1) > 0) { 
					new Effect.Move(innerEl,{x:textColumnWidth,mode:'relative',duration:defaultScrollSpeed}); 
				} 
				if(innerEl.getStyle('left').replace('px','')*-1 == textColumnWidth) {
					new Effect.Opacity(el,{from: 1, to: 0.5});
				}
			});
		});
	});
	
	$$('a.pagination-next').each(function(el) {
		el.observe('click',function() {
			$$('a.pagination-previous').each(function(butEl) {
				if(butEl.getStyle('opacity') < 1) {
					new Effect.Opacity(butEl,{from: 0.5, to: 1});
				}
			});
			
			$$('#main-content-text-container-scroller .column').each(function(innerEl) {
				if((innerEl.getStyle('left').replace('px','')*-1) < ((paginationCount-1)*textColumnWidth)) { 
					new Effect.Move(innerEl,{x:-textColumnWidth,mode:'relative',duration:defaultScrollSpeed}); 
				} 
				if(innerEl.getStyle('left').replace('px','')*-1 == (paginationCount-2)*textColumnWidth) {
					new Effect.Opacity(el,{from: 1, to: 0.5});
				}
			});
		});
	});
	
	
});

Element.observe(window,'resize',function() {
	var footerHeight = (html.clientHeight-$('footer-container').getStyle('marginTop').replace('px',''));
	if(footerHeight > 130) {
		$('footer-container').setStyle({height:(footerHeight-17)+'px'});
	} else {
		
		$('footer-container').setStyle({height:'130px'});
	}
});

function showHideMenu(type) {
	if(type == 'show') {
		$('menu-container').slideDown({duration:0.3});
		new Effect.Morph('navigation-container', { style: 'height:303px;', duration: 0.3 });	
	} else {				
		$('menu-container').slideUp({duration:0.3});
		new Effect.Morph('navigation-container', { style: 'height:151px;', duration: 0.3 });
	}
}
