var Section = {
	load: function(){
		/**
		 * section is set in the app_controller::beforeFilter() 
		 * and written in the layouts home .ctp and default.ctp
		 */
		if( section == 'home' ) {
			return;
		}
		if( section == 'garysnyder' ) {
			
			document.gs_logo.src='/img/system/default/garysnyderlogo_inactive.jpg';
			document.ps_logo.src='/img/system/default/projectspacelogo_pale.jpg'; 
					
			Event.observe( "projectspace_logo","click", function(e){ window.location='/projectspace/'});
			Event.observe( "projectspace_logo","mouseover", 
				function(e){ 
					document.ps_logo.src='/img/system/default/projectspacelogo_active.jpg'; 
				});
			Event.observe( "projectspace_logo","mouseout", 
				function(e){ 
					document.ps_logo.src='/img/system/default/projectspacelogo_pale.jpg'; 
				});
		} else if(section = 'projectspace'){
			
			document.gs_logo.src='/img/system/default/garysnyderlogo_pale.jpg';
			document.ps_logo.src='/img/system/default/projectspacelogo_inactive.jpg'; 

			
			Event.observe( "garysnyder_logo","click", function(e){ window.location='/garysnyder/'});
			Event.observe( "garysnyder_logo","mouseover", 
				function(e){ 
					document.gs_logo.src='/img/system/default/garysnyderlogo_active.jpg'; 
				});
			Event.observe( "garysnyder_logo","mouseout", 
				function(e){ 
					document.gs_logo.src='/img/system/default/garysnyderlogo_pale.jpg'; 
				});
		} 
	}
}
var Layout = {
	getWindowHeight: function() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			} else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				} else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		},
		vcenter: function(div, pad) {
			if (document.getElementById) {
				var contentElement = $(div);
				
				var windowHeight = contentElement.parentNode.offsetHeight;//this.getWindowHeight();
				
				if (windowHeight > 0) {
					var contentHeight = contentElement.offsetHeight;
					var maxHeight = (windowHeight - (pad * 2));
					if( contentElement.scrollHeight > maxHeight ) {
						contentElement.style.height = maxHeight + 'px';
					} else {
						contentElement.style.height = 'auto'
					}
					if (windowHeight - contentHeight > 0) {
						var toppad = (((maxHeight/2) -(contentHeight/2)))+pad;
						var t=0;
						if (toppad > pad) {
							t = toppad ;
						} else {
							t = pad;
						}
						contentElement.style.position = 'relative';
						contentElement.style.top =  t + 'px';
					}
					else {
						contentElement.style.position = 'static';
					}
				}
			}
		}	
}
//
function detectMacXFF() {
  userAgent = navigator.userAgent.toLowerCase();
  if ( (userAgent.indexOf('mac') != -1 && ( userAgent.indexOf('firefox')!=-1 || userAgent.indexOf('opera')!=-1)) || (userAgent.indexOf('win') !=-1 && userAgent.indexOf('firefox')!=-1)  ) {
    return true;
  }	
  return false;
}
var PAD = 80;
Event.observe(window,'load', function() {
	
	
	Section.load();		
	if($('menu')) {
		Layout.vcenter('menu',PAD);
	}
	Layout.vcenter('vfloat_container', PAD);
	
	$('container').setStyle({opacity: 1});
	$('container').setStyle({MozOpacity: 1}); 	
});

Event.observe(window, 'resize', function() {
	
	Layout.vcenter('vfloat_container', PAD);
	
	if($('menu')) {
		Layout.vcenter('menu',PAD);
	}
});


