window.onDomReady(function(){

	//setup site nav hover, since IE6 can't handle li:hover peudo-class
	$$('#nav-site li').each(function(el){
			el.addEvents({
				mouseenter: function(){
					if(el.getProperty('class')!='active') {
						if(!$chk('home')){
							el.addClass('homenavdown');
						}else{
							el.addClass('subnavdown');
						}
					}
				},
				mouseleave: function(){
					if(el.getProperty('class')!='active') {
						el.hasClass('subnavdown') ? el.removeClass('subnavdown') : el.removeClass('homenavdown');
					}
				}
		});
	});
	
	
	//insert button on MPAC logo that links to outer home
	$('header-top').adopt(new Element('div', {
			'styles': {
				'position': 'absolute',
				'width': '73px',
				'height': '37px',
				'top': '8px',
				'right': '8px'
			},

			'events': {
				'click': function(){location.href = 'http://www.mpac.ca';},
				'mouseover': function(){document.body.style.cursor = 'pointer';},
				'mouseout': function(){document.body.style.cursor = 'default';}
			},
			'id':'mpacbutton'
			
		})
	);		
	
	//look for random image placeholder
	if ($chk($E('img.swapimg'))) {
		var el = $E('img.swapimg');
		
		//if we're swapping images, read file with list of images/alt tags (indicated in 'rel' tag of swapimg)
		//easily editable json file, select random image from path indicated in file, set swapimg src + alt					
		var req = new Json.Remote(el.getProperty('rel'), {
				method: 'get',
				onComplete: function(jsonObj) {
					var newimg = jsonObj.images[$random(0, jsonObj.images.length-1)];
					el.setProperty('src', jsonObj.path + newimg.name);
					el.setProperty('alt', newimg.alt);
				}
			}).send();
	}
	
	if ($chk($('print'))) {
		$('print').addEvent('click', function(e){
			window.print();
		});
	}
	
	if ($chk($('textresize'))) {
		$('textresize').addEvent('click', function(e){
			var clickLoc = e.clientX - this.getLeft();
			if (clickLoc < 15) {
				$('contentwrap').setStyles({"font-size": '100%'});
			}else if (clickLoc < 30) {
				$('contentwrap').setStyles({"font-size": '115%'});
			}else {
				$('contentwrap').setStyles({"font-size": '125%'});
			}
		});
	}
	
});
