var spanText;
$(document).ready(function() {
	
	spanText = $('div#h1 .h1 span').text();
	$('div#h1 .h1 span').remove();
	$('div#h1 .h1').after('<span>'+spanText+'</span>');
	
	var inputValue = $('div#search-bar input').addClass('dim').val();
	$('div#search-bar input')
	.focus(function() {
		if (this.value == inputValue) {
			this.value = '';
			this.className = '';
		}
		$('div#search-bar').addClass('bgposition-top-right');
	})
	.blur(function() {
		if (this.value == '') {
			this.value = inputValue;
			this.className = 'dim';
		}
		$('div#search-bar').removeClass('bgposition-top-right');
	});
	
	// $("input#s").autocomplete( SITEURL,
	// 		{
	// 			delay:10,
	// 			minChars:2,
	// 			matchSubset:1,
	// 			matchContains:1,
	// 			cacheLength:10,
	// 			onItemSelect:selectItem,
	// 			onFindValue:findValue,
	// 			formatItem:formatItem,
	// 			width : 396,
	// 			leftAdjustment : -187,
	// 			TopAdjustment : 3
	// 		}
	// 	);
	
	$('div#inner-content form input[type!=hidden]:first').focus();
	
	$('a.open-new-window, ul#links a').click(function() {
		window.open(this.href);
		return false;
	});
	
	setTimeout(doSIFR, 250);
});

function doSIFR() {
	if(typeof sIFR == "function"){
	//if (!sIFR.UA.bHasTransparencySupport) return false;
	// This is the preferred "named argument" syntax
		sIFR.replaceElement(named({
			sSelector:"div#frame .h1, div#h1 span",
			sFlashSrc:URL+"/javascript/sIFR2/eras-medium.swf",
			sColor:"#000",
			sWmode: 'transparent'
		}));
	};
}


function findValue(li) {

	if( li == null ) return false;
	
	// if coming from an AJAX call
	if( !!li.extra ) var sValue = li.extra[0];
	
	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue
	
	return sValue;
}

function selectItem(li) {
	window.location.href = findValue(li);
}

function formatItem(row) {
	return '<strong><a href='+row[1]+'>'+row[0]+'</a></strong>';
}

