var numQuotes = 9;
var currentQuote = 1;
var defaultZip = 'e.g. 90210';
var defaultZipClean = 'EG 90210';

$(document).ready(function() {
	
	$('.zip').each(function() {
		if($(this).val() == '' || $(this).val() == defaultZip || $(this).val() == defaultZipClean) {
			$(this).addClass('example');
			$(this).val(defaultZip);
		}
	});
	
	$('.zip').focus(function() {
		if($(this).val() == defaultZip) {
			$(this).removeClass('example');
			$(this).val('');
		}
	});

	$('.zip').blur(function() {
		if($(this).val() == '') {
			$(this).addClass('example');
			$(this).val(defaultZip);
		}
	});

	$('#eduToolsLink').click(function() {
		swapEducationQuote($(this), $('#eduToolsContent'));
		gaTrackPageView('/listing/new/tools');
		return false;
	});


	$('#eduOptionsLink').click(function() {
		swapEducationQuote($(this), $('#eduOptionsContent'));
		gaTrackPageView('/listing/new/options');
		return false;
	});
	
	$('#eduHowLink').click(function() {
		swapEducationQuote($(this), $('#eduHowContent'));
		gaTrackPageView('/listing/new/how');
		return false;
	});

	$('#eduWhyLink').click(function() {
		swapEducationQuote($(this), $('#eduWhyContent'));
		gaTrackPageView('/listing/new/why');
		return false;
	});
	
	$('.expander').click(function() {
		if($(this).children().filter('span').html() == '[+]') {
			$(this).children().filter('span').html('[-]');
		}
		else {
			$(this).children().filter('span').html('[+]');
		}
		$($(this).attr('href')).toggleClass('hide');
		return false;
	});
	
	$('.rowExpander').click(function() {
		element = this.href.substring(this.href.search('#')+1);
		if(element == $('.expandRow.selected').attr('id')) {
			$('.expandRow.selected').css('display', 'none');
			$('.expandRow.selected').removeClass('selected');
		}
		else {
			$('.expandRow.selected').css('display', 'none');
			$('.expandRow.selected').removeClass('selected');
			$('#'+element).addClass('selected');
			$('#'+element).css('display', '');
		}
		return false;
	});

	if($('#eduHowContainer').length > 0) {
		$('#eduHowContainer').accordion({header: 'h2.barAccord', autoHeight: false}); 
	}

});

function swapEducationQuote(link, content) {
	swapEducationLinks(link, content);	
	lastQuote = currentQuote;
	if(currentQuote == numQuotes) {
		currentQuote = 1;
	}
	else {
		currentQuote++;
	}

	$('#pullQuote'+lastQuote).fadeOut(1000, function() {$('#pullQuote'+currentQuote).fadeIn(1000);});

}

function swapEducationLinks(link, content) {
	var linkObj = link;
	var contentObj = content;
	$('.eduLinks.selected').removeClass('selected');
	linkObj.addClass('selected');
	
	$('.eduContent').addClass('hide');
	contentObj.removeClass('hide');
	
	linkObj.blur();
}

$(document).ready(function(){
	var currentURL = window.location.href;
	var sharp = currentURL.indexOf('#');
	if(sharp > 1) {
		var selector = currentURL.substring(sharp);
		$(selector).trigger('click');
	}
});

