//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 BSM site)
	if (section == 'screenshots' || section == 'demo' || section == 'demos' || section == 'videos' || section == 'desktops' || section == 'requirements' || section == 'press' || section == 'links')
	{
		wrapStandardPage();
	}

    //Make paper bits draggable
	$$('.paper').each(function(el,i){
		new Draggable(el);
		el.setStyle({cursor: 'move'});
	});
	
	//Make paper text boxes draggable
    $$('.paperbox').each(function(el,i){
		new Draggable(el,{handle: 'cssbox_head'});
		el.select('cssbox_head').each(function(el2,i2){
			el2.setStyle({cursor: 'move'});
		});
	});
	
	//Make the 'close this window' X's active.
    $$('.closelink').each(function(el,i){
		Event.observe(el, 'click', function(event) {
			var closelink = Event.element(event);
			new Effect.Fade(closelink.up(2),{duration: 0.3});
		});
	});

	if (navigator.appVersion.indexOf('Safari') != -1) {
		//Make tradingcards draggable
		$$('.tradingcard').each(function(el,i){
			new Draggable(el,{handle: 'cardhandle'});
			el.select('cardhandle').each(function(el2,i2){
				el2.setStyle({cursor: 'move'});
			});
		});
	};	
	
	var loadFlashVid = function (x, idx) {
		var fo = new SWFObject("data/games/bsm/vids/wm_"+x+".swf", "wm_"+x, "244", "101", "8", "");
		fo.addParam("scale", "exactfit");
		fo.addParam("menu", "false");
		fo.write(x+"vid");
	}
	
	switch(section)
	{
		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 'usfleet':
			var usShips = ['fletcher','kgv','yorktown','narhal'];
			usShips.each(loadFlashVid);
			break;
			
		case 'japfleet':
			var japShips = ['yamato','fubuki','akagi','type_b'];
			japShips.each(loadFlashVid);
			break;
			
		case 'usair':
			var usAir = ['dauntless','avenger','wildcat','b17'];
			usAir.each(loadFlashVid);
			break;
			
		case 'japair':
			var japAir = ['kate','val','zero','betty'];
			japAir.each(loadFlashVid);
			break;
			
		case 'locations':
			loadmap();
			break;	
	}		
}

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

function loadmap(){
	if (GBrowserIsCompatible()){
		var map = new GMap2(document.getElementById("map"));
	    map.setCenter(new GLatLng(23.241346, -195.113281), 2);
		map.setMapType(G_HYBRID_MAP);
		map.addControl(new GSmallZoomControl());
		
		//Now add the relevant points
		var marker01 = new GMarker(new GLatLng(21.366667, -157.95),{title: 'Pearl Harbor'});		
		GEvent.addListener(marker01, "click", function() {
			new Effect.Appear('wiki01');
		});	
		map.addOverlay(marker01);
		
		var marker02 = new GMarker(new GLatLng(11.5, 123.5),{title: 'The Philippines'});		
		GEvent.addListener(marker02, "click", function() {
			new Effect.Appear('wiki02');
		});	
		map.addOverlay(marker02);
		
		var marker03 = new GMarker(new GLatLng(9.5275, 118.3975),{title: 'Palawan'});		
		GEvent.addListener(marker03, "click", function() {
			new Effect.Appear('wiki03');
		});	
		map.addOverlay(marker03);

		var marker04 = new GMarker(new GLatLng(16, 121),{title: 'Luzon'});		
		GEvent.addListener(marker04, "click", function() {
			new Effect.Appear('wiki04');
		});	
		map.addOverlay(marker04);
		
		var marker05 = new GMarker(new GLatLng(1.263539, 116.827883),{title: 'Balikpapan'});		
		GEvent.addListener(marker05, "click", function() {
			new Effect.Appear('wiki05');
		});	
		map.addOverlay(marker05);
		
		var marker06 = new GMarker(new GLatLng(-8.613056, 115.727778),{title: 'Lombok Strait'});		
		GEvent.addListener(marker06, "click", function() {
			new Effect.Appear('wiki06');
		});	
		map.addOverlay(marker06);
				
		var marker07 = new GMarker(new GLatLng(-5.266667,111.731111),{title: 'The Java Sea'});		
		GEvent.addListener(marker07, "click", function() {
			new Effect.Appear('wiki07');
		});	
		map.addOverlay(marker07);
		
		var marker08 = new GMarker(new GLatLng(-9.1,160.15),{title: 'Tulagi'});		
		GEvent.addListener(marker08, "click", function() {
			new Effect.Appear('wiki08');
		});	
		map.addOverlay(marker08);

		var marker09 = new GMarker(new GLatLng(-16.934167,155.11),{title: 'The Coral Sea'});		
		GEvent.addListener(marker09, "click", function() {
			new Effect.Appear('wiki09');
		});	
		map.addOverlay(marker09);
		
		var marker10 = new GMarker(new GLatLng(28.2,-177.35),{title: 'Midway Atoll'});		
		GEvent.addListener(marker10, "click", function() {
			new Effect.Appear('wiki10');
		});	
		map.addOverlay(marker10);
		
		Event.observe('locationsbox', 'unload', GUnload);
	}
	
}