//preload images
faded_bg = new Image();
faded_bg.src = '/images/faded_bg.png';
//faded_bg_active = new Image();
//faded_bg_active.src = '/images/faded_bg_active.png';
faded_bg_hover = new Image();
faded_bg_hover.src = '/images/faded_bg_hover.png';
footer_bg = new Image();
footer_bg.src = '/images/footer_bg.png';
post_button_on = new Image();
post_button_on.src = '/images/post_button_on.png';
preview_button_on = new Image();
preview_button_on.src = '/images/preview_button_on.png';

/* Swap images */
function swap(elem, img) {
	offimg = elem; // set offimg to the image element
	offimg_src = elem.src; // set up the 'off' state image
	elem.src = '/images/'+img; // swap to the 'on' state
}
function swapback() {
	offimg.src = offimg_src; // revert back to the 'off' state
}

/* Form Highlighting - http://www.ryanbrill.com/archives/form_highlighting_redux/ */

if (navigator.userAgent.toLowerCase().indexOf('applewebkit') == -1) { // filter out Safari, as it has it's own formfield highlighting
	// preload
	left = new Image();
	left.src = '/images/left.png';
	top_left = new Image();
	top_left.src = '/images/top_left.png';
	top_right = new Image();
	top_right.src = '/images/top_right.png';
	right = new Image();
	right.src = '/images/right.png';
	bottom_left = new Image();
	bottom_left.src = '/images/bottom_left.png';
	bottom_right = new Image();
	bottom_right.src = '/images/bottom_right.png';
	
	function setBg(elem) {
		if (document.getElementById) {
			box = elem.parentNode.parentNode;
			box.style.background = 'url(/images/left.png) repeat-y left';
			box.childNodes[0].style.background = 'url(/images/top_left.png) no-repeat top left';
			box.childNodes[0].childNodes[0].style.background = 'url(/images/top_right.png) no-repeat top right';
			box.childNodes[1].style.background = 'url(/images/right.png) repeat-y right';
			box.childNodes[1].childNodes[0].style.border = '1px solid #fff';
			box.childNodes[2].style.background = 'url(/images/bottom_left.png) no-repeat bottom left';
			box.childNodes[2].childNodes[0].style.background = 'url(/images/bottom_right.png) no-repeat bottom right';
		}
	}
	function removeBg(elem) {
		if (document.getElementById) {
			box = elem.parentNode.parentNode;
			box.style.background = 'transparent';
			box.childNodes[0].style.background = 'transparent';
			box.childNodes[0].childNodes[0].style.background = 'transparent';
			box.childNodes[1].style.background = 'transparent';
			box.childNodes[1].childNodes[0].style.border = '1px solid #b2b2b2';
			box.childNodes[2].style.background = 'transparent';
			box.childNodes[2].childNodes[0].style.background = 'transparent';
		}
	}
}

/* Offsite Links - http://www.ryanbrill.com/archives/designating-offsite-links/ */

if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
	onload = function setExternal() {
		domain = 'ryanbrill.com';
		re = new RegExp('^http://(www\.)?'+domain);
		for (i=0; i<document.getElementById('content').getElementsByTagName('a').length; i++) {
			if (!document.getElementById('content').getElementsByTagName('a')[i].href.match(re)) {
				document.getElementById('content').getElementsByTagName('a')[i].className = 'offsite';
			}
		}
	}
}

