/*GLOBAL VARIABLES FOR ALL PAGES */
/*Work out what page we are on */
var aPage = document.URL.split('/'); 
var sPageID = aPage[aPage.length-1];

function rbtHomeInit()	{
//Change the default tagline Text and bckgorund image
	if (typeof currentTabId == 'undefined')	{
		currentTabId = '1';
			runAnim();
	}
}


function rbtInnerInit()	{
/*Amend the height of the content box and footer positioning.*/
document.getElementById('content').style.height = '790px';
document.getElementById('content-footer').style.top = '770px';
/* Now do a switch on this to work out some parameters for AJAX to use */
	switch (sPageID) {
		case 'About-RBT.aspx':
			var id = 1;
		break;
		case 'Design-and-Print.aspx':
			var id = 4;
		break;
		case 'HR-and-Payroll.aspx':
			var id = 5;
		break;
		case 'ICT.aspx':
			var id = 7;
		break;
		case 'Procurement.aspx':
			var id = 3;
		break;
		case 'Revenues-and-Benefits.aspx':
			var id = 2;
		break;
		case 'Schools.aspx':
			var id = 6;
		break;
		default:
			var id = 1;
		break;
	}
	//Now we need to amend the appearance of the cutdown strip that appears.
	//Now we make our selected tab active - but only if we're not already the selected tab
		var tabId = 'tablink'+id;
		//alert(sPageID + '\n'+ id + '\n'+ tabId + '\n'+tagLineText);

		document.getElementById(tabId).className = 'active';
		$opacity('tagline', 100,0,10);
		document.getElementById('content-mainimage-innerpage').style.background = 'url(images/cutdownimg'+id+'.jpg) top left no-repeat';
		setTimeout("$opacity('overlay', 0,25,1500)", 400);
		setTimeout("$opacity('tagline', 0,100,1000)", 1500);

}

// addLoadEvent is Simon Willison's function that aloows for convenient
// addition of multiple fuctions that are all supposed to be triggered
// on window.onload event.
// takes function name as the argument. e.g. addLoadEvent(doPopups);
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      		window.onload = func;
	} 
    else {
      		window.onload = function() {
	      		oldonload();
    	  		func();
		}
	}
}


function changeTab(id)	{
	var contentId = 'tabcontent'+id;
	var tabId = 'tablink' + id;
	//If we have a current tab defined we need to stop it being active and fade it's content down to transparent
	if (typeof currentTabId != 'undefined' && id != currentTabId)	{
		//translate the passed id into something usable.
		var currentTabContent = 'tabcontent'+currentTabId;
		var currentTabLink = 'tablink' + currentTabId;
		
		//Set up aprameters based on id being selected.
		switch (id)	{
			case 1:
				tagLineText = 'RBT | Delivering award-winning services in your area';
				learnMoreUrl = 'Home';
				break;
			case 2:	
				tagLineText = 'RBT | Delivering four-star, best-practice services';
				learnMoreUrl = 'Revenues-and-Benefits';
				break;
			case 3:	
				tagLineText = 'RBT | Tailor-made eProcurement delivering significant savings';
				learnMoreUrl = 'Procurement';
				break;
			case 4:	
				tagLineText = 'RBT | First class design and print from an award-winning team';
				learnMoreUrl = 'Design-and-Print';
				break;
			case 5:	
				tagLineText = 'RBT | Award-winning HR & Payroll services';
				learnMoreUrl = 'HR-and-Payroll';
				break;
			case 6:	
				tagLineText = 'RBT | High quality, time-saving direct serivces for schools';
				learnMoreUrl = 'Schools';
				break;
			case 7:	
				tagLineText = 'RBT | BCS Public Service Organisation of the Year 2007';
				learnMoreUrl = 'ICT';
				break;

			default:
				tagLineText = 'RBT | Delivering award-winning services in your area';
				learnMoreUrl = 'Home';
		}
		
		//Now change the opacity in the divs.
		$opacity(currentTabContent, 100, 0, 400);
		//remove the current tab's active state.
		document.getElementById(currentTabLink).className = '';
		//Now we make our selected tab active - but only if we're not already the selected tab
		document.getElementById(tabId).className = 'active';
		//Fire animations for the movie area
		setTimeout("$opacity('tagline', 100,0,400)",100);
		document.getElementById('content-mainimage-homepage').style.background = 'url(images/mainimg'+id+'.jpg) top left no-repeat';
		setTimeout("document.getElementById('learnMoreLink').innerHTML = '<a href=\"'+learnMoreUrl+'.aspx\">Learn more</a>'",500);
		//Swapout the tagline
		setTimeout("document.getElementById('tagline').innerHTML = '<h1>'+tagLineText+'</h1>'",500);
		//Fade it back in
		setTimeout("$opacity('tagline', 0,100,400)",600);
		$opacity(contentId, 0, 100, 400);
		
		//And set this tab to be the current.
		currentTabId = id;
		
	}
}

function runAnim()	{
	$opacity('overlay', 0,100,600);
	setTimeout("$opacity('overlay',100,50,1000)", 610);
	setTimeout("$opacity('tagline', 0,100,1000)", 1620);
	setTimeout("$opacity('learnMoreLink', 0,100,1000)", 1430);
}

//Add onLoadEvent to correct animationroutine dependent upon whether we're on the home page or not.
if (sPageID == '' || sPageID == 'Home.aspx')	{
	addLoadEvent(rbtHomeInit);
}
else	{
	addLoadEvent(rbtInnerInit);
}
