var base = "/";function goTo(url) {
	window.location = url;
}

$(function() {
	Cufon.replace('h1');
	Cufon.replace('h1:first', { color: '-linear-gradient( 0.7=#8d1e10, 0.3=#ae2613)', textShadow: '1px 1px #2e2e2c' });
	Cufon.replace('h1.fran, #module-join-our-club h2', { textShadow: '1px 1px #787774' });
	
	$("select, input:radio").uniform();
	
	var root = $("#browsable").scrollable({circular: true}).navigator().autoscroll({ autoplay: true, interval: 7000});
	window.api = root.data("scrollable");
	$("ul.tabs").tabs("div.panes > div");
	
	var root = $("#promo-slide").scrollable({circular: true}).navigator().autoscroll({ autoplay: true, interval: 7000});
	window.api = root.data("scrollable");
	$("ul.tabs").tabs("div.panes > div");

	// For Franchisee Login
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
		$("#toggle a").toggle();
	});	
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
		$("#toggle a").toggle();
	});		
	$('.username, .password, #q, #contact_form input').focus(function() {
		if($(this).val() == $(this).attr('title')) $(this).val("");
	});
	$('.username, .password, #q, #contact_form input').blur(function() {
		if($(this).val() == "") $(this).val($(this).attr('title'));
	});
	
	// for menu pages
	$(".content").hide();
	$(".accordion a .food-menu-item").click(function(){
		$.cookie('menu_category', $(this).attr('id'), { path: '/'});
		if($(this).parent().is(".active")) {
         $(this).parent().toggleClass("active");
         $(this).parent().next(".content").slideToggle();
         return false;
		} else {
			$(".content:visible").slideUp("slow"); // close all visible divs with the class of .content
			$(".menucat.active").removeClass("active");  // remove the class active from all h1's with the class of .active
			$(this).parent().toggleClass("active");
			$(this).parent().next(".content").slideToggle();
			return false;
		}
	});		
	if($.cookie('menu_category')) $('.accordion a #'+$.cookie('menu_category')).click();
 
	// add * to required field labels
	$('label.required').append('&nbsp;<strong>*</strong>&nbsp;');
 
	// accordion functions
	if($("#stepForm").length) {
		var accordion = $("#stepForm").accordion();
		
		var current = 0;
		
		$.validator.addMethod("pageRequired", function(value, element) {
			var $element = $(element)
			function match(index) {
				return current == index && $(element).parents("#sf" + (index + 1)).length;
			}
			if (match(0) || match(1) || match(2)) {
				return !this.optional(element);
			}
			return "dependency-mismatch";
		}, $.validator.messages.required)
		
		var v = $("#cmaForm").validate({
			errorClass: "warning",
			onkeyup: false,
			onblur: false,
			submitHandler: function() {
				
			}
		});
		
		// back buttons do not need to run validation
		$("#sf2 .prevbutton").click(function(){
			accordion.accordion("activate", 0);
			current = 0;
		}); 
		$("#sf3 .prevbutton").click(function(){
			accordion.accordion("activate", 1);
			current = 1;
		});
		$("#sf4 .prevbutton").click(function(){
			accordion.accordion("activate", 2);
			current = 2;
		});  
		// these buttons all run the validation, overridden by specific targets above
		$(".open3").click(function() {
		  if (v.form()) {
			accordion.accordion("activate", 3);
			current = 3;
		  }
		});
		$(".open2").click(function() {
		  if (v.form()) {
			accordion.accordion("activate", 2);
			current = 2;
		  }
		});
		$(".open1").click(function() {
		  if (v.form()) {
			accordion.accordion("activate", 1);
			current = 1;
		  }
		});
		$(".open0").click(function() {
		  if (v.form()) {
			accordion.accordion("activate", 0);
			current = 0;
		  }
		});
		$(".open3").click(function () {
			$('.fran-qs p, .fran-qs img').hide();
			if($('input[name=radio1]:checked').val() == 2) {
				$('.results').append("<br />Chester's Supermarket!");
				$('.fran-qs .supermarket').show();
			} else if($('input[name=radio2]:checked').val() == 1 && $('input[name=radio3]:checked').val() == 1) {
				$('.results').append("<br />Chester's On the Fly!");
				$('.fran-qs .otf').show();
			} else {
				$('.results').append("<br />Chester's Chicken!");
				$('.fran-qs .chesters').show();
			}
			 $('.fran-qs').slideToggle();
		});
	}
	$("a.video").fancybox();
      
	$('.nu').click(function() {
		$(this).toggleClass('down').next().slideToggle();
		return false;
	});
});


