// REDIRECTS IN PLAIN JS

var browser		= navigator.appName
var ver			= navigator.appVersion
var thestart	= parseFloat(ver.indexOf("MSIE"))+1 //This finds the start of the MS version string.
var brow_ver	= parseFloat(ver.substring(thestart+4,thestart+7)) //This cuts out the bit of string we need.

if ((browser=="Microsoft Internet Explorer") && (brow_ver < 7)) //By default the min. IE ver is set to 6. Change as desired.
	{
	window.location="http://www.foreclosuregrove.com/redirect.html"; //URL to redirect to.
	}


if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion<3)
 	window.location="http://www.foreclosuregrove.com/redirect.html"; //URL to redirect to.
}

$(document).ready(function() {	
	


// REMOVES OUTLINES FROM HREFS WHEN CLICKING
if ($.browser.name == "msie") {      // if IE  
	$("a, .image_button").focus(function () {
		$(this).blur();
	});
};

// FUNCTIONS FOR ROUNDED CORNERS
$('#errorExplanation').corner();
$('#flash_notice').corner();

// FUNCTIONS FOR DEFAULT VALUE IN FORM FIELDS
swapValue = []; 
$(".swap_value").each(function(i){
	swapValue[i] = $(this).val();
	$(this).focus(function(){
		if ($(this).val() == swapValue[i]) {
			$(this).val("");
		}
		$(this).addClass("focus");
	}).blur(function(){
		if ($.trim($(this).val()) == "") {
			$(this).val(swapValue[i]);
			$(this).removeClass("focus");
		}
	});
});

// PREPEND GREEN * TO FIELD LABELS WITH CLASS REQUIRED
$('label.required').prepend('<span class="required_asterisk">*</span>');


// FUNCTION FOR FADEY NAV
$(function () {
	// IE6 doesn't handle the fade effect very well - so we'll stick with
	// the default non JavaScript version if that is the user's browser.
	if ($.browser.msie && $.browser.version < 7) return;

	$('#nav li')

		// remove the 'highlight' class from the li therefore stripping 
		// the :hover rule
		.removeClass('highlight')

		// within the context of the li element, find the a elements
		.find('a')

		// create our new span.hover and loop through anchor:
		.append('<span class="hover" />').each(function () {

		// cache a copy of the span, at the same time changing the opacity
		// to zero in preparation of the page being loaded
		var $span = $('> span.hover', this).css('opacity', 0);

		// when the user hovers in and out of the anchor
		$(this).hover(function () {

			// stop any animations currently running, and fade to opacity: 1
			$span.stop().fadeTo(500, 1);

		}, function () {
		// off hover

			// again, stop any animations currently running, and fade out
			$span.stop().fadeTo(500, 0);
		});
	});
});

// BACK TO TOP BUTTON
$('a.top').click(function() {
	$.scrollTo("body", {duration:800, axis:'y'});
	return false; 
});


// FANCY BOX FOR CONTACT FORM 
$("a#contact").fancybox({ 
	'zoomSpeedIn': 300, 
	'zoomSpeedOut': 300, 
	'overlayShow': true,
	'frameWidth': 494,
	'frameHeight': 526
}); 


// SECONDARY NAV FOR ABOUT PAGES
$('img#overview').hover(function() {
	$(this).attr('src', '/images/secondary_nav/overview_hover.png');
}, function() {
	$(this).attr('src', '/images/secondary_nav/overview.png')
});

$('img#team').hover(function() {
	$(this).attr('src', '/images/secondary_nav/team_hover.png');
}, function() {
	$(this).attr('src', '/images/secondary_nav/team.png')
});

$('img#kit').hover(function() {
	$(this).attr('src', '/images/secondary_nav/media_kit_hover.png');
}, function() {
	$(this).attr('src', '/images/secondary_nav/media_kit.png')
});


// SELECTED STATE FOR MAIN NAV
current_page = document.location.href

if (current_page.match(/features/)) {
	$('#nav a.features').addClass('features_selected').removeClass('features');
} else if (current_page.match(/about/)) {
	$('#nav a.about_us').addClass('about_us_selected').removeClass('about_us');
} else if (current_page.match(/pricing_and_signup/)) {
	$('#nav a.sign_up').addClass('sign_up_selected').removeClass('sign_up');
} else {
	$('#nav a.home').addClass('home_selected').removeClass('home');
};


// OPEN IN NEW WINDOW
$(function(){
    $('a.new_window').click(function(){
        window.open(this.href);
        return false;
	});
});


// EMBED CODE SHOW

$('#embed_paragraph a').click(function() {
	$('#embed_code').slideToggle('slow');
	return false;
});


}); // end of doc ready