
jQuery(document).ready(function() {
	// Stuff to init: decal, text to images (needs timeout),
	// default search value, minheight of content
	controlDecal(true);
	replaceText();
	
		
//	$(".block_paragraph").keypress(function(e) {
//	  if (e.which == 13) {
//	      e.preventDefault(); // I think this is the keyword you look for?
//	      $(".block_paragraph").val($(".block_paragraph").val() + "<br/>"); // Handler for new p or line break etc.
//	  }
//	});
	
});





/*
	replaceText()
	Replace some text items with pretty images
	henry changed jQuery('#navigation li a') => jQuery('#subnav a')
*/
function replaceText() {
	/*
	jQuery('h3').each(function() {
		var color = getColor(jQuery(this).css('color'));
		var text = escape(jQuery(this).text());
		jQuery(this).html('<img src="fonts/h3.php?text='+text+'&color='+color+'" />');
		
	});
	*/
}

/*
	controlDecal()
	disable / enable overflows on body/html
	and decal depending on width of window
*/
function controlDecal(init) {
	if (init) {
		jQuery(window).resize(function() {
			controlDecal();
		});
	}
	var scrollelement = jQuery.browser.opera || jQuery.browser.msie ? 'html' : 'body';
	if (jQuery(window).width() > 950) {
		jQuery(scrollelement).css('overflow-x', 'hidden');
		jQuery('.decal').css('overflow', 'visible');
	} else {
		jQuery('.decal').css('overflow', 'hidden');
		jQuery(scrollelement).css('overflow-x', 'scroll');
	}
}

/*
	getColor
	gets hexvalues of color
*/
function getColor(color) {
	var pos = color.indexOf(')');
	if(pos > 0) {
		var rgb = color.substr(4,pos-4);
		color = '';
		rgb = rgb.split(', ');
		var i=0;
		while (i<=rgb.length - 1) {
			dec = parseInt(rgb[i]);
			color = color+''+toHex(dec);
			i++;
		}
		
	}
	var pos = color.indexOf('#');
	if (pos > -1) {
		var color = color.substr(1);
	}
	return color;
}

/*
	toHex
	converts decimals 0 <> 255 to hex
*/
function toHex(dec) {
	var hexCharacters = "0123456789ABCDEF"
	if (dec < 0)
	return "00"
	if (dec > 255)
	return "FF"
	var i = Math.floor(dec / 16)
	var j = dec % 16
	return hexCharacters.charAt(i) + hexCharacters.charAt(j)
}

