

var addressInputPrompt = "Enter city, state or zip";
var popupMapActive = false;

$(document).ready(function() {
	/*
	if (($.browser.msie && $.browser.version.substr(0,1)<7)) {
		location.href = "/ie6";
	}*/
	if (typeof(toRoot) == "undefined") {
		toRoot = "";	
	}
	
	$("#locator-form, #addressline").submit(function() {
		var formValue = $("#addressline").val();
		
		if(formValue == addressInputPrompt) {
			location.href = toRoot + "store-locator";
		} else {
			if(location.href.match(/store\-locator/gi)) {
				location.hash = "#" + formValue.replace(/[^a-zA-Z 0-9]+/g,'+');
				window.location.reload(true);
			} else {
				location.href = toRoot + "store-locator/#" + formValue.replace(/[^a-zA-Z 0-9]+/g,'+');
			}
			
		}
		return false;
	});	
	
	$("#map-frame").each(function() {
		
		var hash = location.hash.split('#');
		
		if(hash.length > 1) {
			
			$(this).attr('src', 'http://hosted.where2getit.com/steaknshake/?form=locator_search&addressline=' + hash[1] + '&search=Search');
		}
	});
	
	$("#specials-popup-tabs").tabs();
	$(".specials-popup").fancybox({
		width: 800,
		height: 360,
		autoDimensions: false,
		titleShow: false,
		padding: 0,
		modal: true,
		scrolling: 'no'
	});
	
	
	
	$("#page-select").change(function() {
		window.location.href = $(this).val();
	});
	

	
	initLocator();
	
	
	$("#franchise-li a").click(function(event){
		event.preventDefault();
		_gaq.push(['_trackPageview', 'FranchiseHeader']);
		window.location = $(this).attr("href");
	})
	
	$("#footer a").click(function(event){
		if($(this).attr("href")=="http://www.steaknshakefranchise.com"){
			event.preventDefault();
			_gaq.push(['_trackPageview', 'FranchiseFooter']);
			window.location = $(this).attr("href");
		}
		
	})
	
	$("#aboutus-franchise").click(function(event){
		event.preventDefault();
		_gaq.push(['_trackPageview', 'FranchiseAboutUs']);
		window.location = $(this).attr("href");
	})	
	
	$("aboutus-biglari").click(function(event){
		event.preventDefault();
		_gaq.push(['_trackPageview', 'FranchiseAboutUs']);
		window.location = $(this).attr("href");
	})	
	
	$("#aboutus-biglari").click(function(event){
		event.preventDefault();
		_gaq.push(['_trackPageview', 'BiglariHoldings']);
		window.location = $(this).attr("href");
	});	
	
});

/**
 * ==============================================
 * Initialize store locator portion of the header
 * ==============================================
 */
function initLocator() {

	var hiConfig = {
		sensitivity: 3,
		interval: 100,
		timeout: 100,
		over: function() {
			$("#popup-map").slideDown();
			popupMapActive = true;
		},
		out: function() {
			$("#popup-map").slideUp();
			popupMapActive = false
		}
	}


	$("#addressline").focus(function() {
		var field = $(this);
		
		if(field.val() == addressInputPrompt) {
			field.val("");
			field.removeClass('input-prompt');
		}
	}).blur(function() {
		
		var field = $(this);
		
		if(field.val() == "") {
			field.val(addressInputPrompt);
			field.addClass('input-prompt');
		}
	}).blur();
	
	
	$("#store-locator-wrap").hoverIntent(hiConfig);	
	
	
	$.ajax({
		type: "GET",
		url: toRoot + "dynamic/map.php",
		success:function(html) {
			$("#popup-map-image").append(html);
			
		}
	});
}

/**
 * ==============================================
 * Cufon font replacement
 * ==============================================
 */

Cufon.replace('.cufon > ul > li > a, .cufon, #sidebar > ul > li > a:not(first-child)', {
	fontFamily: "Neutraface 2 Display Titling",
	hover: {color: '#e00000'}
});

Cufon.replace('.nav-cufon', {
	fontFamily: "Optima LT Std",
	hover: {color: '#e00000'}
});



