var textList = [
"Why are you keeping historic data in enterprise applications?",
"Are you really using production data to test?",
"Could your brand cope with a security breach of sensitive data?",
"Are you having problems finding Data Integration Professionals?",
"How much do you spend maintaining legacy applications?"
]

var defaultInterval = 5000;
var fadeRate = 1000;
var hash;

$(document).ready(function(){
	setTimeout("rollText('tagline')", 1);
	var d = new Date();
	var copyright = "&copy; " + d.getFullYear() + " Jonathan Garth Ltd.";
	$("#copyright").append(copyright);
	
	hash = window.location.hash.replace(/^#/,"");
	
	switch (hash)
	{
	case 'about':
	case 'consulting':
	case 'contact':
	case 'home':
	case 'ideas':
	case 'partners':
	case 'recruitment':
	case 'solutions':
	case 'policy':
//		loadContent(hash);
//		break;
	case 'ideas-abinitio':
	case 'ideas-about':
	case 'ideas-data':
	case 'recruitment-jobs':
	case 'recruitment-workforus':
	case 'solutions-aci':
	case 'solutions-pp':
	case 'solutions-whyus':
	case 'solutions-archive':
		loadContent(hash.split('-')[0]);
		break;
	default:
		loadContent("home");
	};
	

	$("ul#tabs a").click(function(){
		hash = $(this).attr("id");
		$("div#content").fadeOut(300, function(){
			$("div#content").html("");
			loadContent(hash);
			$("div#content").fadeIn(300);
		});
		return false;
	});
	
	$('a#policy').click(function(){
		$("div#content").fadeOut(300, function(){
			$("div#content").html("");
			loadContent("policy");
			$("div#content").fadeIn(300);
		});
		return false;
	});	
});

function loadContent(id) 
{	
		$("div#content").load(id+".html",function(response, status, xhr) {
			if (status == "error") loadContent("home");
		});
		$("div#content").removeClass();
		$("div#content").addClass(id);
		$("ul#tabs li.current").removeClass("current");
		$("ul#tabs li a#"+id).parent("li").addClass("current");
};

function rollText(elementId, interval)
{
	interval = interval != null ? interval : defaultInterval;

	$("#"+elementId).fadeOut(fadeRate, function(){
		rotateText(elementId);
		$("#"+elementId).fadeIn(fadeRate);
	});

	setTimeout("rollText('"+elementId+"',"+interval+")",interval);
}

function rotateText(rollingElementId)
{
	text = textList.shift();
	textList.push(text);

	if (text.length > 76)
	{
		text = "<span class='narrower'>" + text + "</span>";
	}

	$("#"+rollingElementId).html(text);

}

