// Mootools related
window.addEvent('domready', function() {

	// fix the height of the div on the right to be larger than div on the left
	function fix_content_div() {
		var nav_div = $('nav_container');
		var content_div = $('content_wrapper');
		var content = $('content');
		if ( nav_div && content_div ) {
			// grab height of content
			var content_height = content.getStyle('height').toInt();			
			// grab height of nav
			var nav_div_height = nav_div.getStyle('height').toInt();
			// grab height of content
			var content_div_height = content_div.getStyle('height').toInt();

			// check to see if content_div_height < nav_div_height (make at least as big as content area)
			if ( content_height > content_div_height ) {
				content_height += 150;
				// set style of content
				content_div.tween('height', content_height+'px');
			}

			if ( content_div_height < nav_div_height ) {
				// set style of content
				content_div.tween('height', nav_div_height+'px');		
			}
		}
	}

	// print page icon
	var printpage = $('printpage');
	if ( printpage ) {
		printpage.addEvent("click", function(e) {
			e.stop();
			window.print();
		});
	}
	
	// scrolling header
	/*var scroll_img = $$('#content_header img');
	if ( scroll_img ) {
		var img_width = scroll_img.getStyle('width');
		var img_viewspace = $('content_header').getStyle('width').toInt();
			
		// make integer
		img_width = parseInt(img_width);
	
		// calculate how far left we're moving this
		var img_moveleft = img_width - img_viewspace;
		
		// start over if user moved mouse
		scroll_img.set('tween', {duration: 15000, link: 'chain'});
		scroll_img.tween('margin-left', '-'+img_moveleft+'px').tween('margin-left', '0px').tween('margin-left', '-'+img_moveleft+'px').tween('margin-left', '0px').tween('margin-left', '-'+img_moveleft+'px').tween('margin-left', '0px').tween('margin-left', '-'+img_moveleft+'px').tween('margin-left', '0px').tween('margin-left', '-'+img_moveleft+'px').tween('margin-left', '0px');
	}*/
	
	// search box fx on border
	$('search_box').addEvent('focus', function(e) {
		// Changes the element's style to .myClass defined in the CSS
		$('search_box').morph('.search_box_morph');
	});
	$('search_box').addEvent('blur', function(e) {
		// Changes the element's style to .myClass defined in the CSS
		$('search_box').morph('.search_box_normal');
	});
	
	/* CHANGE FONT SIZE AND REMEMBER WITH A COOKIE */
	var font_small = $('size_minus_btn');
	var font_big = $('size_plus_btn');
	var content_container = $('content');
	
	// READ COOKIE FONTSIZE VALUE AND SET IF VALID
	var cookie_fontsize = readCookie('fontsize');
	if ( cookie_fontsize ) {
		content_container.setStyle('font-size', cookie_fontsize);
	}
	
	// MAKE FONT SMALLER
	if ( font_small && content_container ) {
		font_small.addEvent("click", function(e) {
			e.stop();
			var font_size = content_container.getStyle('font-size');
			font_size = parseInt(font_size) - 1;
			if ( font_size > 10 ) {
				content_container.setStyle('font-size', font_size+'px');
				fix_content_div();
				createCookie('fontsize',font_size+'px',7);
			}
		});
	}
	
	// MAKE FONT BIGGER
	if ( font_big && content_container ) {
		font_big.addEvent("click", function(e) {
			e.stop();
			var font_size = content_container.getStyle('font-size');
			font_size = parseInt(font_size) + 1;
			if ( font_size < 22 ) {
				content_container.setStyle('font-size', font_size+'px');
				
				// refire the resize of the content container
				fix_content_div();
								
				createCookie('fontsize',font_size+'px',7);
			}
		});
	}
	
	fix_content_div();

});
