$(document).ready(function(){
	// superfish menu
	$("ul.sf-menu").superfish().find('ul').bgIframe({opacity:false});
	
	$('.top-forms-inner').equalHeights( { overflow: 'visible' } );

	// use Google AJAX API to set global US state, if not already set (by server-side output) and available:
	if ( globalVars.stateCode.length == 0
			&& google.loader.ClientLocation
			&& google.loader.ClientLocation.address.country_code == 'US'
			&& google.loader.ClientLocation.address.region )
	{
		globalVars.stateCode = google.loader.ClientLocation.address.region.toUpperCase();
	}

	// pre-select/set state on relevant forms/links
	if ( globalVars.stateCode.length == 2 ) {
		$('#stateCode').val(globalVars.stateCode);
		$('#find_lenders_stateCode').val(globalVars.stateCode);
		$('#rate_watch_stateCode').val(globalVars.stateCode);

		// add stateCode value to /go/rates.search.byLoanCriteriaAttributes/ links:
		$('a[href^="/go/rates.search.byLoanCriteriaAttributes/"]')
			.each(function()
			{
				this.href = this.href.replace(/stateCode=/, 'stateCode=' + globalVars.stateCode);
			}
		);
	}

	// email stuff to detract sp4mm3rs
	$('span.info-email-alias').replaceWith('<a href=' + '"mail' + 'to:' + 'info' + '@' + 'mortgages' + '.' + 'com' + '">' + 'info' + '@' + 'mortgages' + '.' + 'com' + '</a>');

	// IE crap
	if($.browser.msie)
	{
		// rounded corners with images and a bunch of markup, for IE only, of course
		$('.rounded-r15').prepend('<div class="rounded-r15-header"><div class="rounded-r15-top"><span class="rounded-r15-tl"></span><span class="rounded-r15-tr"></span></div></div>').append('<div class="rounded-r15-footer"><div class="rounded-r15-bottom"><span class="rounded-r15-bl"></span><span class="rounded-r15-br"></span></div></div>');
	}
});
