// JavaScript Document

//Shows or Hides objects
function show(id) {
	var d = document.getElementById(id);
	
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
	
	if (d) {d.style.display='block';}
}
// returns the size of the window.
function getWindowSize() {
	var w = 0, h = 0;
	if ( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		w = window.innerWidth;
		h = window.innerHeight;
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return { width : w, height : h };
}
// returns the size of the page.
function getPageSize() {
	var w = 0, h = 0;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if ( test1 > test2 ) {
		// all but Explorer Mac
		w = document.body.scrollWidth;
		h = document.body.scrollHeight;
	} else {
		// Explorer Mac;
		// would also work in Explorer 6 Strict, Mozilla and Safari
		w = document.body.offsetWidth;
		h = document.body.offsetHeight;
	}
	return { width : w, height : h };
}
// returns how much the page has been scrolled.
function getScrollOffset() {
	var x = 0, y = 0;
	if ( self.pageYOffset ) {
		// all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else if ( document.documentElement && document.documentElement.scrollTop ) {
		// Explorer 6 Strict
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	} else if ( document.body ) {
		// all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return { x : x, y : y };
}

// scroll the page vertically to the given position. 
function scrollPageVertical( p_y ) {
	moveDown( getScrollOffset().y, p_y );
}
function moveDown( p_position, p_y ) {
	var move = ( p_y - p_position) / 10;
	var point = Math.round( p_position + move );
	scrollTo( 0, point );
	//if ( Math.abs( point - p_y ) > 0 && p_position < point ) {
	if ( Math.abs( point - p_y ) > 0 && Math.abs( point - p_position ) > 0 ) {
		setTimeout( "moveDown(" + point + ", " + p_y + ")", 15 );
	}
}

// scroll the page to just below the header flash movie.
function scrollPastHeader() {
	var scrollToY = 480;
	var winSize = getWindowSize();
	var pageSize = getPageSize();
	
	scrollPageVertical( Math.max( 0, Math.min( scrollToY, pageSize.height - winSize.height + 5 ) ) );
}



// Popup Window (Centred)
function popup(url,winname,w,h,feat)
{
	if (!(isNaN(w) || isNaN(h)))
	{
		var x=parseInt((screen.width-w)/2);
		var y=parseInt((screen.height-h)/2);
		if (x<0)	x=0;
		if (y<0)	y=0;
		
		if (feat!=null && feat!="")
		{
			feat=","+feat;
		}
		else
		{
			feat="";
		}
		feat="left="+x+",top="+y+",width="+w+",height="+h+feat;
	}
	window.open(url,winname,feat);
}

function openSeniorSite() {
	window.location= "http://www.pepys.org/pepys_senior/";
}

function open_downloads() {
	window.location= "../downloads/";
}

function open_adventure(name)
{
	switch (name)
	{
		case "beingfriends":
			popup("../adventures/beingfriends/","adv"+name,640,480,"status");
			break;
			
		case "walking":
			popup("../adventures/walking/","adv"+name,640,480,"status");
			break;
			
		case "cycling":
			popup("../adventures/cycling_adventure/","adv"+name,640,480,"status");
			break;
			
		case "personalsafety":
			popup("../adventures/personal_safety/","adv"+name,610,448,"status");
			break;
			
		case "bullying":
			popup("../adventures/bullying/","adv"+name,640,480,"status");
			break;
			
		case "inacar":
			popup("../adventures/inacar/","adv"+name,640,480,"status");
			break;
			
		case "internetsafety":
			popup("../adventures/internet_safety/","adv"+name,610,448,"status");
			break;
			
		case "whathappensif":
			break;
			
	}
}

function open_game(name)
{
	switch (name)
	{
		case "game1":
			popup("../games/test_track/",name,735,435,"status");
			break;
			
		case "game2":
			popup("../games/breakout/",name,530,435,"status");
			break;
			
		case "game3":
			popup("../games/brickbybrick/",name,780,395,"status");
			break;
			
		case "game4":
			popup("../games/word_search/",name,737,435,"status");
			break;
			
		case "game5":
			popup("../games/pepys_says/",name,526,432,"status");
			break;
	}
}

function open_wallpaper_from_game(game, w, h) {
	var name = "";
	
	switch (game)
	{
		case "game2":
			name = "summer";
			break;
	}
	
	if ( name != "" && w > 0 && h > 0 ) {
		popup("../../wallpaper/view.cfm?image="+name+"_"+w+".jpg","wp"+name+""+w+"x"+h,w,h,"resizable,scrollbars,status");
	}
}
function open_wallpaper(name,w,h)
{
	popup("../wallpaper/view.cfm?image=pepys_"+name+"_"+w+"x"+h+".jpg","wp"+name+""+w+"x"+h,w,h,"resizable,scrollbars,status");
}

function open_jigsaw(name)
{
	var w, h;
	switch (name) {
		case "charge" :
		case "court" :
		case "school" :
		case "street" :
			w = 666;
			h = 272;
			break;
		case "autumn" :
		case "spring" :
		case "summer" :
		case "winter" :
			w = 270;
			h = 270;
			break;
	}
	popup("../games/jigsaw/?puzzle="+name+"&w="+w+"&h="+h,name+"_jigsaw",w,h,"status");
}

function open_colour_fill(name)
{
	popup("../games/colour_fill/?puzzle="+name,name+"_colour_fill",700,410,"status");
}

function open_ePostcard(whichCard)
{
	var action = "";
	switch (whichCard)
	{
		case "court room":
			action = "ctr";
			break;
			
		case "charge room":
			action = "chr";
			break;
			
		case "street":
			action = "str";
			break;
			
		case "school":
			action = "sch";
			break;
			
		case "autumn":
			action = "autumn";
			break;
			
		case "spring":
			action = "spring";
			break;
			
		case "summer":
			action = "summer";
			break;
			
		case "winter":
			action = "winter";
			break;
	}
	
	window.location= "ePostcard.cfm?action=" + action;
}


function showhide(id)
{
	var o=document.getElementById(id);
	if (!o)
	{
		return;
	}
	o.style.display=(o.style.display=="none") ? "" : "none";
}