var pagesArray = new Array();
pagesArray[0] = new Array('home','index.aspx?ajax=true');
pagesArray[1] = new Array('our-business','our-business.aspx?ajax=true');
pagesArray[2] = new Array('projects','projects.aspx?ajax=true');
pagesArray[3] = new Array('graduate-careers','graduate-careers.aspx?ajax=true');
pagesArray[4] = new Array('placements','placements.aspx?ajax=true');
pagesArray[5] = new Array('sponsorship','sponsorship.aspx?ajax=true');
pagesArray[6] = new Array('employee-stories','employee-stories.aspx?ajax=true');
pagesArray[7] = new Array('where-do-i-fit-in','where-do-i-fit-in.aspx?ajax=true');
pagesArray[8] = new Array('apply','apply.aspx?ajax=true');
var divlist = new Array();
divlist[1]='home';
divlist[2]='our-business';
divlist[3]='projects';
divlist[4]='graduate-careers';
divlist[5]='placements';
divlist[6]='sponsorship';
divlist[7]='employee-stories';
divlist[8]='where-do-i-fit-in';
divlist[9]='apply';
var subsections = new Array();
subsections['our-business']= new Array('our-culture','our-values','global-reach');
subsections['projects']= new Array('projects-birmingham-hospital','projects-blackfriars','projects-ite-college-west','projects-wind-farm');
subsections['graduate-careers']= new Array('rewards-and-benefits','training-and-development');
subsections['placements']= new Array('placements-rewards-and-benefits');
subsections['employee-stories'] = new Array('employee-stories-grad-01', 'employee-stories-grad-02', 'employee-stories-grad-03', 'employee-stories-grad-04', 'employee-stories-grad-05', 'employee-stories-grad-06', 'employee-stories-grad-07', 'employee-stories-grad-08', 'employee-stories-grad-09', 'employee-stories-grad-10', 'employee-stories-grad-11', 'employee-stories-grad-12', 'employee-stories-grad-13');
subsections['apply']= new Array('hints-and-tips');
var imagesforindex = new Array('images/td_project_detail_blackfriars.png','images/td_project_detail_birmingham.png','images/td_project_detail_ite.png','images/td_project_detail_trimdon.png');
var foundthediv = false;
var currenturl = '';
if(location.pathname.split("/")[location.pathname.split("/").length-1].split(".")[0] == 'index' || location.pathname.split("/")[location.pathname.split("/").length-1].split(".")[0] == '') 
{
	var hash = '#home';
	currenturl = 'index.aspx';
	changeSharelink(currenturl);
}
else
{
	currenturl = location.pathname.split("/")[location.pathname.split("/").length-1].split(".")[0].toLowerCase() + '.aspx';
	changeSharelink(currenturl);
	var subsectionfound = false;
	for ( var i in subsections )
	{
		if(i!='findIndex')
			{
				for ( var j in subsections[i] )
				{
					if(subsections[i][j] == location.pathname.split("/")[location.pathname.split("/").length-1].split(".")[0].toLowerCase())
						{
							var hash = '#'+i;
							var subsection = subsections[i][j];
							subsectionfound = true;
						}
				}
			}
	}
	if(!subsectionfound) 
		{
			var hash = '#'+location.pathname.split("/")[location.pathname.split("/").length-1].split(".")[0];
			var subsection = '';
		}
	
}


var myWidth = 3000, myHeight = 0;
var changedList = new Array();
changedList['home']= false;
changedList['our-business']= false;
changedList['projects']= false;
changedList['graduate-careers']= false;
changedList['placements']= false;
changedList['sponsorship']= false;
changedList['employee-stories']= false;
changedList['where-do-i-fit-in']= false;
changedList['apply']= false;
var indexscrolling = false;
var bgChangeTimeout = 5000;
var flashvars = {};
var params = {menu:"false",wmode:"transparent"};
var attributes = {wmode:"transparent"};
function calculatewidht()
{
	var tempwidth = 0;
	var tempheight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		tempwidth = window.innerWidth;
		tempheight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		tempwidth = document.documentElement.clientWidth;
		tempheight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		tempwidth = document.body.clientWidth;
		tempheight = document.body.clientHeight;
	}
	//alert(tempwidth);
	if(tempwidth != myWidth) if(tempwidth >= 1000) {myWidth = parseInt(tempwidth);} else {myWidth =1000;};
}
calculatewidht();
$().ready(function() {
	initialize();
	$('a[href!=#]').livequery("click",function(){
		pageTracker._trackPageview($(this).attr("href"));
	});
});
$(window).bind('resize', function() {
	changediv();
});
function afterloaddone()
{
	$('#outer').codaSlider();
	if(!foundthediv)
	{
		document.getElementById("outer").style.height =	$('#'+divlist[1]).height()+'px';
	}
	resetLinkClass();
	selectedLinkClass(hash.slice(1)+'-link');
	document.getElementById("outer").style.width = '100%';//myWidth+'px';
	where();
	window.setTimeout('indexscrollbot(2)',bgChangeTimeout);
}
function initialize()
{
	document.getElementById("outer").style.width = '100%';//myWidth+'px';
	document.getElementById("outer").style.height = myHeight+'px';
	document.getElementById("outer").innerHTML = "";
	if(location.hash != "")
		{
			
			hash = location.hash.split("_");
			if(hash[1]!= undefined)
			{
				subsection = hash[1];
			}
			hash = hash[0];
		}
	var newdiv = document.createElement('div');
	var divIdName = 'wrappergeneral';
	newdiv.setAttribute('id',divIdName);
	newdiv.setAttribute('class','panel-container');
	newdiv.setAttribute('className', 'panel-container');
	document.getElementById("outer").appendChild(newdiv);
	for ( var i in pagesArray )
	{
		if(i!='findIndex') appendWrapper(pagesArray[i][0],pagesArray[i][1],i);
	}
}
Array.prototype.findIndex = function(value){
	var ctr = "";
	for (var i=0; i < this.length; i++) {
	if (this[i] == value) {
	return i;
	}
	}
	return ctr;
	};
function changediv()
{
	var tempwidth = myWidth;
	calculatewidht();
	if(tempwidth != myWidth)
	{
		tempwidth = myWidth;
		var count = 0;
		var oldwidth = parseInt($('#'+pagesArray[1][0]).css('width'));
		var oldposition = parseInt(document.getElementById("wrappergeneral").style.marginLeft);
		
		for ( var i in pagesArray )
		{
			if(i!='findIndex')
			{
				$('#'+pagesArray[i][0]).css('width',tempwidth+'px');
				count++;
			}
		}
		document.getElementById("wrappergeneral").style.width = tempwidth*count+'px';
		if(isNaN(oldposition)) oldposition=0;
		if(isNaN(oldwidth)) oldwidth=0;
		var tempvariable = parseInt(oldposition/oldwidth);
		if(isNaN(tempvariable)) tempvariable=0;
		document.getElementById("wrappergeneral").style.marginLeft = parseInt(tempwidth*tempvariable) + "px";
	}
	
}
var counterdivmade = 0;
function appendWrapper(name,link,currentdiv)
{
		var newdiv = document.createElement('div');
		var divIdName = name;
		newdiv.setAttribute('id',divIdName);
		newdiv.setAttribute('class','panel');
		newdiv.setAttribute('className', 'panel');
		newdiv.style.cssText = 'width:'+myWidth+'px;';
		document.getElementById("wrappergeneral").appendChild(newdiv);
		$("#"+divIdName).load(link,function()
			{
			counterdivmade = counterdivmade+1;
				if(divIdName == 'home')
				{
					//$('#vacancies').rssfeed('http://www22.i-grasp.com/rssjobfeed/rss.aspx?sourceagencyid=13466&category=1').ajaxStop(function() {
					$('#vacancies').rssfeed('http://www22.i-grasp.com/fe/BalfourBeattyRSS.asp').ajaxStop(function() {
			     });
				}
				if(subsection != '' && hash.replace(/#/g,'') == divIdName && typeof(subsection)!="undefined")
				{
					document.getElementById("outer").style.height = $('#'+hash.replace(/#/g,'')).height()+'px';
					changeSubsection(hash,subsection);
				}
				else
				{
					if(divlist.findIndex(hash.replace(/#/g,'')) == parseInt(currentdiv)+1)
					{
						foundthediv=true;
						currenturl = divIdName + '.aspx';
						changeSharelink(currenturl);
						document.getElementById("outer").style.height = $('#'+hash.replace(/#/g,'')).height()+'px';
					}
				}
			showPrintButton();
			if(counterdivmade == 9 ) afterloaddone();
		});
	
}
function changeSubsection(section,subsection)
{
	
	if(section == '#employee-stories')
		{

		    var value = subsection.split("-")[subsection.split("-").length - 1];

		    $("#employee-stories-content").fadeTo("slow", 0, function() {
		        $("#employee-stories-content").unload();
		        currenturl = $('.grad-' + value).attr("href");
		        changeSharelink(currenturl);
		        $("#employee-stories-content").load($('.grad-' + value).attr("href") + '?ajax=true', function() {
		            $("#outer").animate({ height: $("#employee-stories").height() }, 1000, "easeInOutExpo");
		            if ($("#video-player").length > 0) {
		                swfobject.embedSWF("movies/videos/" + $('.grad-' + value).attr("title") + ".swf", "video-player", "478", "253", "10.0.0", "movies/expressInstall.swf", flashvars, params, attributes);
		            }

		            showTweet($('.grad-' + value).attr("rel"));
		            $("#employee-stories-content").fadeTo("slow", 1);
		            showPrintButton();
		        });
		    });
			changedList['employee-stories']= true;
		}
	else
		{
			
			$(section).fadeTo("slow",0,function() {
			
				$(section).unload();
				currenturl = subsection + '.aspx';
				changeSharelink(currenturl);
				$(section).load(subsection+'.aspx?ajax=true',function() {
					if(section == '#projects')
					{
						
						swfobject.embedSWF("movies/"+subsection.split('.')[0]+'.swf', "project-detail-flash", "211", "288", "10.0.0","movies/expressInstall.swf", flashvars, params, attributes);
					}
					$("#outer").animate({ height: $(section).height() }, 1000, "easeInOutExpo");
					showPrintButton();
					$(section).fadeTo("slow",1);
					});
			
			});
			changedList[section.split('#')[1]]= true;
		}
	
}
function changePerson(value)
{
    $("#employee-stories-content").fadeTo("slow", 0, function() {
        $("#employee-stories-content").unload();
        $("#employee-stories-content").load($('.grad-' + value).attr("href") + '?ajax=true', function() {
            currenturl = $('.grad-' + value).attr("href");
            changeSharelink(currenturl);
            $("#outer").animate({ height: $("#employee-stories").height() }, 1000, "easeInOutExpo");
            if ($("#video-player").length > 0) {
                swfobject.embedSWF("movies/videos/" + $('.grad-' + value).attr("title") + ".swf", "video-player", "478", "295", "10.0.0", "movies/expressInstall.swf", flashvars, { menu: "false" }, attributes);
            }
            showTweet($('.grad-' + value).attr("rel"));
            $("#employee-stories-content").fadeTo("slow", 1);
        });
    });
	changedList['employee-stories']= true;
}
function selectedLinkClass(name)
{
	if(name == 'apply-link') { document.getElementById(name).className = 'apply applyselected'; }
	else if(name == 'employee-stories-link'){document.getElementById(name).className = 'plast selected';}
	else if(name == 'where-do-i-fit-in-link'){document.getElementById(name).className = 'last selected';}
	else {document.getElementById(name).className = 'selected';}
}
function resetLinkClass()
{
	var theid = '';
	for ( var i in divlist )
	{
		if(i!='findIndex')
		{
			theid = divlist[i] + '-link';
			document.getElementById(theid).className = '';
			if(divlist[i] == 'apply') { document.getElementById(theid).className = 'apply'; }
			//else if(i == 'home')document.getElementById(theid).className = '';
			else if(divlist[i] == 'employee-stories'){document.getElementById(theid).className = 'plast';}
			else if(divlist[i] == 'where-do-i-fit-in'){document.getElementById(theid).className = 'last';}
			
			
		}
	}
}
function moveToApply()
{
	resetLinkClass();
	selectedLinkClass('apply-link');
	currenturl = 'apply.aspx';
	changeSharelink(currenturl);
	$('.panel-container', document.getElementById('outer')).animate({ marginLeft: '-'+myWidth*8 }, 1000,  "easeInOutExpo");
	$("#outer").animate({ height: $("#apply").height() }, 1000, "easeInOutExpo");
	showPrintButton();
}
function changeDivContent(section,id,movetosection)
{
	movetosection = movetosection || "";
	if(movetosection != "")
	{
		resetLinkClass();
		selectedLinkClass(movetosection+'-link');
		$('.panel-container', document.getElementById('outer')).animate({ marginLeft: '-'+myWidth*(parseInt(divlist.findIndex(movetosection))-1) }, 1000,  "easeInOutExpo");
	}
	if(section == 'employee-stories')
	{
		var value=id;
		currenturl = $('.grad-'+value).attr("href");
		changeSharelink(currenturl);
		$("#employee-stories-content").fadeTo("slow", 0, function() {
		    $("#employee-stories-content").unload();
		    if (value != "00") {
		        $("#employee-stories-content").load($('.grad-' + value).attr("href") + '?ajax=true', function() {
		            $("#outer").animate({ height: $("#employee-stories").height() }, 1000, "easeInOutExpo");
		            if ($("#video-player").length > 0) {
		                swfobject.embedSWF("movies/videos/" + $('.grad-' + value).attr("title") + ".swf", "video-player", "478", "253", "10.0.0", "movies/expressInstall.swf", flashvars, params, attributes);
		            }
		            showTweet($('.grad-' + value).attr("rel"));
		            $("#employee-stories-content").fadeTo("slow", 1);
		            showPrintButton();
		        });
		    }
		});
		changedList['employee-stories']= true;
	}
	else
	{
		$("#"+section).fadeTo("slow",0,function() {
			currenturl = $("#"+id).attr("href");
			changeSharelink(currenturl);
			$("#"+section).unload();
			$("#"+section).load($("#"+id).attr("href")+'?ajax=true',function() {
				if(section == 'projects')
				{
					//alert($("#"+id).attr("href") + ' ' + id);
					swfobject.embedSWF("movies/"+id+'.swf', "project-detail-flash", "211", "288", "10.0.0","movies/expressInstall.swf", flashvars, params, attributes);
				}
				$("#outer").animate({ height: $("#"+section).height() }, 1000, "easeInOutExpo");
				$("#"+section).fadeTo("slow",1);
				showPrintButton();
				});
		});
		changedList[section]= true;
	}
	
}
function scrolltosection(section)
{
	if(section != "" && typeof(section)!="undefined")
	{
		resetLinkClass();
		selectedLinkClass(section+'-link');
		reloadMainDiv(section);
		$('.panel-container', document.getElementById('outer')).animate({ marginLeft: '-'+myWidth*(parseInt(divlist.findIndex(section))-1) }, 1000,  "easeInOutExpo");
	}
	showPrintButton();
}
function reloadMainDiv(section)
{
	if(changedList[section] == true)
	{
		for ( var i in pagesArray )
		{
			if(i!='findIndex')
			{
				if(pagesArray[i][0] == section)
				{
					var currentlink = pagesArray[i][1];
					
					$("#"+section).fadeTo("slow",0,function() {
						$("#"+section).unload();
						$("#"+section).load(currentlink,function() {
							$("#outer").animate({ height: $("#"+section).height() }, 1000, "easeInOutExpo");
							showPrintButton();
							$("#"+section).fadeTo("slow",1);
							});
					});
				}
			}
		}
	}
	currenturl = section + '.aspx';
	changeSharelink(currenturl);
	changedList[section]= false;
}
function showTweet(user)
{
    
//    $('.tweet').tweet({
//              join_text: "auto",
//              username: user,
//              count: 3,
//              auto_join_text_default: "", 
//              auto_join_text_ed: "",
//              auto_join_text_ing: "",
//              auto_join_text_reply: "",
//              auto_join_text_url: "",
//              loading_text: "loading tweets..."
//            });
}
function changeSharelink(newurl)
{
	if(newurl == 'home.aspx')
	{
		newurl = 'index.aspx';
		indexscrolling = true;
		window.setTimeout('indexscroll()',bgChangeTimeout);
	}
	else
	{
		indexscrolling = false;
	}
	$(".addthis_button_compact").attr("href",'http://www.addthis.com/bookmark.php?v=250&username=xa-4c4ef8ee0c027a77&url='+encodeURIComponent('http://'+location.host+'/'+newurl));
}
function printpage()
{
	if(currenturl == 'home.aspx')
	{
		currenturl = 'index.aspx';
	}
	newwindow=window.open(currenturl+'?print=true','name','height=300,width=550');
	if (window.focus) {newwindow.focus()}
	return false;

}
function showPrintButton()
{
	$(".printpage").css("visibility","visible");
}
function hoverPerson(id)
{
	//$("#grad-"+id).fadeIn(500);
	$("#grad-"+id).css("display","block");
}
function resetHovers()
{
	for (i=1;i<=9;i++)
	{
		$("#grad-0"+i).css("display","none");
	}
	$("#grad-10").css("display","none");
}
var timerIndexbg;
var timerIndexbot;
function indexscroll()
{
	if(indexscrolling == true)
	{
		var oldclass= $("#index-bg-image").attr('class');
		if(parseInt(oldclass.split('-')[2]) == 4) {var newclass = "index-bg-01";} else {var newclass = oldclass.split('-')[0] + '-' + oldclass.split('-')[1] + '-0' + (parseInt(oldclass.split('-')[2])+1);}
		objImg = new Image();
		objImg.src = imagesforindex[parseInt(newclass.split('-')[2])-1];
		objImg.onload = function() 
		{
			resetbgbuttons();
			addbgbutton(parseInt(newclass.split('-')[2]));
			$("#index-bg").fadeTo("slow",0,function() {
				$("#index-bg-image").removeClass(oldclass).addClass(newclass);	
				$("#index-bg").fadeTo("slow",1,function() {
					timerIndexbg = window.setTimeout('indexscroll()',bgChangeTimeout);
				});
			});
		};
	}
}
function indexscrollbot(param)
{
		clearTimeout(timerIndexbot);
		if(param == 2) { var oldparam = 1;} else {var oldparam = 2;}
		$("#rotate"+oldparam).fadeOut("slow",function() {
			$("#index-bot-button-01").removeClass();
			$("#index-bot-button-02").removeClass();
			$("#index-bot-button-0"+param).addClass('selected');	
			$("#rotate"+param).fadeIn("slow",function() {
				if(param == 2) { timerIndexbot = window.setTimeout('indexscrollbot(1)',bgChangeTimeout);} else {timerIndexbot = window.setTimeout('indexscrollbot(2)',bgChangeTimeout);}
				
			});
		});
}
function changeIndexbg(param)
{

		indexscrolling = false;
		clearTimeout(timerIndexbg);
		var oldclass= $("#index-bg-image").attr('class');
		newclass = oldclass.split('-')[0] + '-' + oldclass.split('-')[1] + '-0' + parseInt(param);
		objImg = new Image();
		objImg.src = imagesforindex[parseInt(param)-1];
		objImg.onload = function() 
		{
			resetbgbuttons();
			addbgbutton(parseInt(param));
			$("#index-bg").fadeTo("normal",0,function() {
				$("#index-bg-image").removeClass(oldclass).addClass(newclass);	
				indexscrolling = true;
				timerIndexbg = window.setTimeout('indexscroll()',bgChangeTimeout);
				$("#index-bg").fadeTo("normal",1,function() {
				});
			});
		};
}
function resetbgbuttons()
{
	for (i=1;i<=4;i=i+1)
	{
		$("#index-bg-button-0"+i).removeClass();
	}
}
function addbgbutton(param)
{
	$("#index-bg-button-0"+param).addClass('selected');
}
