$(document).addEvent('domready', function(){
	
	disableBlankLinks();
	
	buttonRollovers();

});

window.addEvent('load', function(){
	
	adjustHeader();
	
});

// DETECT FOR LARGE SCREENSIZES
	function adjustHeader(){
		
		if ($('header') != null){
			var headerHeight = $('header').getStyle('height').toInt();
			
			var contentDiv;
			if ($('mainHome') != null)
				contentDiv = $('mainHome');
			else
				contentDiv = $('main');
			
			var contentHeight = contentDiv.getSize().y;
			
			var contentMarginTop;
			var contentMarginBottom;
			
			if ($(contentDiv).getElement('.content').getStyle('marginTop'))
				contentMarginTop = $(contentDiv).getElement('.content').getStyle('marginTop').toInt(); 
			else
				contentMarginTop = 0;
			
			if ($(contentDiv).getElement('.content').getStyle('marginBottom'))
				contentMarginBottom = $(contentDiv).getElement('.content').getStyle('marginBottom').toInt(); 
			else
				contentMarginBottom = 0;
			
			contentHeight += contentMarginTop +contentMarginBottom;
			
			var viewportHeight;
			// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
			if (typeof window.innerWidth != 'undefined'){
				viewportHeight = window.innerHeight;
			}
			
			// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
			else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
				viewportHeight = document.documentElement.clientHeight;
			}
			
			// older versions of IE
			else{
				viewportHeight = document.getElementsByTagName('body')[0].clientHeight;
			}
			
			var offset = viewportHeight - contentHeight;
			
			if (offset > headerHeight){
				$('header').setStyle('height', offset);
				//alert('header adjusted to ' +offset +'px');
				if (offset > 200)
					$('header').getElement('.background').setStyle('backgroundColor', '#bfceda');
			}
			else{
				//alert('offset = ' +offset+ '. header not adjusted');
			}
			
		}
	}

// DISABLE ANY BLANK LINKS
	function disableBlankLinks(){
		$(document).getElements('a[href=#]').each(function(item){
				item.addEvent('click', function(event){
					var event = new Event(event);
					event.preventDefault();
				});
			});
	}

// BUTTON ROLLOVERS
	function buttonRollovers(){
		$(document).getElements('.button').each(function(item){
			item.addEvent('mouseover', function(event){
				var event = new Event(event);
				var button = event.target;
				var src = button.getProperty('src').split('.');
				var finalSrc = src[0] +'-over.' +src[1];
				button.setProperty('src', finalSrc);
			});
		});
		$(document).getElements('.button').each(function(item){
			item.addEvent('mouseout', function(event){
				var event = new Event(event);
				var button = event.target;
				
				var src = button.getProperty('src').split('.');
				var end = src[0].substr(src[0].length-5, src[0].length); 
				if (end == '-over'){
					var finalSrc = src[0].substr(0, (src[0].length -5)) +'.'+ src[1];
					button.setProperty('src', finalSrc);
				}
			});
		});
	}
	
// DISPLAY HIDDEN PNGS FOR IE6
	function showPNGs(){
		var pngs = $(document).getElements('.pngHack, .pngHack2');
		pngs.each(function(item){
			item.setStyle('visibility', 'visible');
		});
	}
	
// OPEN POPUP WINDOW
	function openWindow(url, name, w, h){
		w += 32;
		h += 96;
		var win = window.open(url, name,
			'width=' + w + ', height=' + h + ', ' +
			'location=no, menubar=no, ' +
			'status=no, toolbar=no, scrollbars=no, resizable=no');
		win.resizeTo(w, h);
		win.focus();
	}