

nav = {
home  	      :    {title: 'home', id:'home',href:'home'},
video  	      :    {title: 'video', id:'video',href:'video'},
staff  	      :    {title: 'staff', id:'staff',href:'staff', visible: false},
boarding      :    {title: 'pet boarding', id:'boarding',href:'boarding'},
daycare       :    {title: 'doggie daycamp', id:'daycare',href:'daycare'},
grooming      :    {title: 'pet grooming', id:'grooming',href:'grooming'},
training      :    {title: 'dog training', id:'training',href:'training'},
blog 	      :    {title: 'blog', id:'blog',href:'http://kennelclub-usa.com/news',external: true},
shop 	      :    {title: 'shop', id:'shop',href:'shop'},
testimonials  :    {title: 'testimonials', id:'testimonials',href:'testimonials'},
contact  :    {title: 'contact', id:'contact',href:'contact'}
};

previousSection = 'home';

function makeRollover(id, down, over){
	$(id).mouseover(function(){
		$(this).attr("src", over);
	}).mouseout(function(){
		$(this).attr("src", down);
	});
}


function buildPage(){
	if($("form.aj").length > 0){
		jQuery.each($("form.aj"), function(){
			new setupAjaxForm('#'+$(this).attr('id'),$(this).find(':input#nextpage').attr('value'));
		});
	}
	/*
	jQuery.each(nav, function(key, val){
		n = nav[key];
		if(n.visible != false){
		//$("#nav").append("<a></a>");
		$("#nav a:last").addClass("normal").attr("id", n.id).attr("href", n.id).text(n.title);
		if(n.external == true){
			$("#nav a:last").attr("href", n.href).attr("target", "_blank");
		}
		}
	});
	*/
		//fade in nav buttons
		/*
		$("#nav a:eq(0)").fadeIn(100, function(){
			$(this).next().fadeIn(100, arguments.callee);
		});
		*/
		//set current nav from hidden field
		setCurrentNav(currentNav());
		showCurrentNav();
		

		$("#nav a").click(function(){
			setPreviousSection(currentNav());
			setNavClass($("#"+getPreviousSection()));		
		});
		$("#nav a").mouseover(function(){
			$(this).attr("class", $(this).attr("id"));
		});
		$("#nav a").mouseout(function(){
			setNavClass($(this));		
		}).mouseup(function(){
			setNavClass($(this));
		});
		dynamicPage();
}

function delayRefresh(url, time){
	timeout = setTimeout('getURL("'+url+'")', time);
}

function getURL(url){
	window.location = url;
}

function currentNav(){
	return $("input#currentSection").val();
}
	
function getPreviousSection(){
	return previousSection;
}

function setPreviousSection(nav){
	previousSection = nav;
}

function setCurrentNav(id){
	$("input#currentSection").val(id);
}
function setNavClass(navnode){
	if(currentNav() != navnode.attr("id")){
		navnode.attr("class", "normal");
	}else{
		navnode.attr("class", navnode.attr("id"));
	}
}

function growCurrent(navnode){
	//$("#content").html("<img src='/images/loading.gif' alt='loading...'/>");

	navnode.attr("class", navnode.attr("id"));
	//now grow it
	navnode.animate({
		fontSize: "2.2em"
	});
}


function dynamicPage(){

	//set class on input focus
	if($("#content input").length > 0){
		$("input[type='text'], textarea").addClass("default").focus(function(){
			$(this).attr("class", "focus");
		}).blur(function(){
			$(this).attr("class", "default");
		});
	}
	if($("#content div.box").length > 0){
		$("#content div.box").hide();
		$("#content div.box > h1").css("color", currentColor());
		$("#content div.box:eq(0)").show('fast',function(){
			$(this).next().show('fast', arguments.callee);
		});
	}
	if($("td div.panel").length > 0){
		$("td div.panel").hide();
		$("td div.panel").fadeIn('fast');
		/*
		$("tr td div.panel:eq(0)").fadeIn('fast', function(){
			$(this).closest("tr").next("td").find("div.panel").fadeIn('fast', arguments.callee);
		});
		*/
		
		$("#content div.panel h1").css("color", currentColor());
	}
	if($("div.buttonBar").length > 0){
		$("div.buttonBar span a.button").css("background", currentColor()).mouseover(function(){
				$(this).css("background", "black").css("color", currentColor());
			}).mouseout(function(){
				$(this).css("background", currentColor()).css("color", "black");
			});
		$("div.buttonBar").toggle().show("slow");

	}
	


}

function showCurrentNav(){
	growCurrent($("#"+currentNav()));
	//$("#main").css("background-color", currentColor());
	//$("#banner").css("background-color", currentColor());
	//$("#banner").css("color", currentColor());

}

function currentColor(){
	return $("#"+currentNav()).css("color");
}

