function Get_Cookie( check_name ) {
	// Function lifted from techpatterns.com
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

//This function is run after a minisite section has loaded.
function after_ajax(section){
	setupFlickBook();
	
	//If we're viewing a standard page (not one I've made specially for the TRA site)
	if (section == 'demos' || section == 'demo' || section == 'screenshots' || section == 'videos' || section == 'desktops' || section == 'requirements' || section == 'press' || section == 'links')
	{
		wrapStandardPage();
	}
	
	if (section == 'desktops')
	{
		new Insertion.Top('boxbody','<div class="advice">To download these desktop backgrounds, select your monitor size from the dropdown box.</div>')
	}

	if (section == 'requirements')
	{
		switch(Get_Cookie('language')){
		case "deutsch":
			new Insertion.Bottom('boxbody',"<div class=\"advice\"><h3>Tomb Raider Geständnis</h3><p>Nein – es geht nicht um das nächste Tomb Raider Spiel…</p><p>Vor einiger Zeit hatten wir angekündigt, dass wir eine Tomb Raider Anniversary Version für PowerPC Macs herausbringen würden. Leider können wir dieses Versprechen nicht einlösen. Sollten Sie auf eine PowerPC-Version von Tomb Raider Anniversary gewartet haben, dann bitten wir um Entschuldigung.</p><p>Wir sind gewissermaßen zwischen zwei Fronten geraten: auf der einen Seite die zunehmenden Schwierigkeiten und die steigenden Kosten, die mit der Unterstützung  moderner Spiele auf PowerPC Macs verbunden sind und auf der anderen Seite die abnehmende Zahl derer, die diese Geräte benutzen. Zusammengefasst heißt das: die technische Umsetzung ist möglich aber teuer; in diesem Fall wäre sie so teuer, dass der finanzielle Aufwand nicht vertretbar ist.</p></div>");
		break;
		case "italiano":
			new Insertion.Bottom('boxbody',"<div class=\"advice\"><h3>Tomb Raider Confession</h3><p>No, non è il titolo del nuovo Tomb Raider...</p><p>Qualche tempo fa, abbiamo annunciato che avremmo portato Tomb Raider Anniversary sui mac con processore Power PC. Sfortunatamente non siamo in grado di mantenere la nostra promessa. Se stavate aspettando la versione per Power Pc di Tomb Raider Anniversary, per favore, accettate le nostre scuse.</p><p>Siamo stati bloccati dalle crescenti difficoltà e crescenti costi di far supportare i moderni giochi da processori Power PC e dal sempre minor numero di persone che possiedono questo tipo di Mac. Insomma, sarebbe tecnicamente possibile, ma costoso, così costoso che in questo caso non è finanzialmente fattible.</p></div>");
		break;
		case "francais":
			new Insertion.Bottom('boxbody',"<div class=\"advice\"><h3>Tomb Raider : La Confession</h3><p>Non, ce n'est pas le prochain épisode de Tomb Raider…</p><p>Il y a quelque temps, nous avions annoncé que nous développerions <i>Tomb Raider Anniversary</i> pour Mac PowerPC. Malheureusement, nous ne pourrons pas tenir notre promesse. Si vous attendiez la version PowerPC de <i>Tomb Raider Anniversary</i>, veuillez accepter toutes nos excuses.</p><p>Nous avons eu à faire face à des difficultés croissantes ainsi qu'à l'augmentation des coûts de développement des jeux récents sur Mac PowerPC. De l'autre côté, nous avons constaté un nombre décroissant d'utilisateurs potentiels. En résumé, même si c'est techniquement possible, cela reste coûteux et dans le cas présent, c'est tellement cher que ce n'est pas économiquement réalisable.</p></div>");
		break;
		
		case "espanol":
			new Insertion.Bottom('boxbody',"<div class=\"advice\"><h3>Confesión de Tomb Raider</h3><p>No, no es el próximo juego de Tomb Raider.</p><p>Hace algún tiempo, anunciamos que llevaríamos Tomb Raider Anniversary a los Macs PowerPC. Desgraciadamente, no podremos mantener esta promesa. Si has estado esperando la versión PowerPC de Tomb Raider Anniversary, por favor, acepta nuestras disculpas.</p><p>Nos hemos visto atrapados entre los cada vez más importantes costes y dificultades de soportar los juegos modernos en los Macs PowerPC, y el decreciente número de personas que los usan. En resumen, es técnicamente posible, pero caro; en este caso, tan caro no es financieramente asumible.</p><p>Una vez más, disculpas.</p>");
		break;
		default:
			new Insertion.Bottom('boxbody',"<div class=\"advice\"><h3>Tomb Raider Confession</h3><p>No, it's not the next Tomb Raider game…</p><p>Some time ago, we announced that we would be bringing Tomb Raider Anniversary to PowerPC Macs. Unfortunately we will not be able to keep this promise. If you have been waiting for the PowerPC version of Tomb Raider Anniversary, please accept this apology.</p><p>We have been caught between the increasing difficulty and cost of supporting modern games on PowerPC Macs, and the diminishing number of people who are using them. In summary it is technically possible, but expensive; in this case so expensive that it is not financially feasible.</p></div>");
		break;
		}

	}
	
}

//This picks out the next/prev navigation links and sets them up with nice clickable arrows that call nextPage() and prevPage()
function setupFlickBook(){
    //Find The nextnav div and replace it with a clickable 'next' arrow
	$$('.nextnav').each(function(el,i){
		el.update('<span class="nextnavlink" onclick="nextPage(\''+el.up(0).readAttribute('id')+'\')"><img src="data/games/tombraider/images/next.png"/></span>');
	});
	
	//Find The prevnav div and replace it with a clickable 'previous' arrow
	$$('.prevnav').each(function(el,i){
		el.update('<span class="prevnavlink" onclick="prevPage(\''+el.up(0).readAttribute('id')+'\')"><img src="data/games/tombraider/images/prev.png"/></span>');
	});
	
	//Find The nextnavdisabled div and replace it with a greyed-out 'next' arrow
	$$('.nextnavdisabled').each(function(el,i){
		el.update('<span class="nextnavlink" ><img src="data/games/tombraider/images/nextdisabled.png"/></span>');
	});
	
	//Find The prevnavdisabled div and replace it with a greyed-out 'previous' arrow
	$$('.prevnavdisabled').each(function(el,i){
		el.update('<span class="prevnavlink" ><img src="data/games/tombraider/images/prevdisabled.png"/></span>');
	});
	
}

//Moves along to the next page. 'pagename' is the current page.
function nextPage(pagename){
	clname = pagename;
	clnext = clname.split('_');
	clnext[1]++;
	clnextname = clnext[0]+'_'+clnext[1];
	$(clnextname).show();
	$(clname).hide();
}

//Moves back to the previous page. 'pagename' is the current page.	
function prevPage(pagename){
	clname = pagename;
	clprev = clname.split('_');
	clprev[1]--;
	clprevname = clprev[0]+'_'+clprev[1];
	$(clprevname).show();
	$(clname).hide();
}

//This takes the contents of #game_html and puts it inside a cssbox, to create the nice semi-transparent windows I've used elsewhere on the TRA site
function wrapStandardPage(){
	var title;
	$('game_html').getElementsBySelector('h1, h2').each(function(el,i){
		title = el.remove();
	});
	$('game_html').update('<div class="cssbox"><div class="cssbox_head"><h2>'+title.innerHTML+'</h2></div><div id="boxbody" class="cssbox_body">'+$('game_html').innerHTML+'</div></div>');
}