//This function is run after a minisite section has loaded.
function after_ajax(section){
	//If we're viewing a standard page (not one I've made specially for the Pirates site)
	if (section == 'screenshots' || section == 'videos' || section == 'desktops' || section == 'requirements' || section == 'press' || section == 'links')
	{
		wrapStandardPage();
	}
	
	switch(section)
	{
		case 'home':
			new Insertion.Before('blackbeard','<div style="float: right; clear: right; height: 40px; width: 50px;"></div><div style="clear: right; float: right; margin-bottom: 5px; height: 30px; width: 150px;"></div><div style="clear: right; float: right; height: 50px; width: 115px;"></div><div style="clear: right; float: right; height: 35px; width: 90px;"></div><div style="clear: right; float: right; height: 20px; width: 100px;"></div><div style="clear: right; float: right; height: 30px; width: 120px;"></div><div style="clear: right; float: right; height: 50px; width: 100px;"></div><div style="clear: right; float: right; height: 35px; width: 120px;"></div>');
			break;
			
		case 'about':
			new Insertion.Before('williamkidd','<div style="float: right; clear: right; height: 40px; width: 64px;"></div><div style="clear: right; float: right; height: 20px; width: 65px;"></div><div style="clear: right; float: right; height: 30px; width: 60px;"></div><div style="clear: right; float: right; height: 20px; width: 70px;"></div><div style="clear: right; float: right; height: 20px; width: 80px;"></div><div style="clear: right; float: right; height: 30px; width: 85px;"></div><div style="clear: right; float: right; height: 27px; width: 95px;"></div><div style="clear: right; float: right; height: 100px; width: 83px;"></div>');
			break;

		case 'skills':
			new Insertion.Before('navigator','<div style="float: right; clear: right; height: 40px; width: 50px;"></div><div style="clear: right; float: right; height: 20px; width: 65px;"></div><div style="clear: right; float: right; height: 30px; width: 65px;"></div><div style="clear: right; float: right; height: 20px; width: 70px;"></div><div style="clear: right; float: right; height: 20px; width: 83px;"></div><div style="clear: right; float: right; height: 30px; width: 78px;"></div><div style="clear: right; float: right; height: 27px; width: 70px;"></div><div style="clear: right; float: right; height: 100px; width: 80px;"></div>');
			break;

		case 'nationality':
			new Insertion.Before('spanishguard','<div style="float: right; clear: right; height: 35px; width: 55px;"></div>\
			<div style="clear: right; float: right; height: 20px; width: 35px;"></div>\
			<div style="clear: right; float: right; height: 30px; width: 60px;"></div>\
			<div style="clear: right; float: right; height: 45px; width: 66px;"></div>\
			<div style="clear: right; float: right; height: 50px; width: 62px;"></div>\
			<div style="clear: right; float: right; height: 30px; width: 67px;"></div>\
			<div style="clear: right; float: right; height: 23px; width: 85px;"></div>\
			<div style="clear: right; float: right; height: 13px; width: 75px;"></div>\
			<div style="clear: right; float: right; height: 50px; width: 45px;"></div>');
			break;
			
		case 'desktops':
			new Insertion.Top('boxbody','<div class="advice">To download these desktop backgrounds, select your monitor size from the dropdown box.</div>');
			break;
		
		case 'gameplay':
		case 'legacy':	
		case 'ships':
			setupFlickBook();
			break;
					
	}
}

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

//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/pirates/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/pirates/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/pirates/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/pirates/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];
	new Effect.Appear(clnextname,{duration: 0.2, queue: 'end'});
	new Effect.Fade(clname,{duration: 0.1, queue: 'front'});
	
	//$(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];
	new Effect.Appear(clprevname,{duration: 0.2, queue: 'end'});
	new Effect.Fade(clname,{duration: 0.1, queue: 'front'});

	//$(clprevname).show();
	//$(clname).hide();
}