// JavaScript Document
// 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);
}


//Opens the correct movie
function showmovie(movieno, moviesize){
	if(movieno == 1){
		if(moviesize == 1){
			popup("movies/player.php?movie=movie1/HP_OOTP_Sizzle_PEGI_Low.mov&width=320&height=195", "movie1", 320, 195);
		} else if(moviesize == 2){
			popup("movies/player.php?movie=movie1/HP_OOTP_Sizzle_PEGI_Hi.mov&width=640&height=375", "movie2", 640, 375);
		} else if(moviesize == 3){
			popup("movies/player.php?movie=movie1/HP_OOTP_Sizzle_PEGI_HD.mov&width=1280&height=735", "movie3", 1280, 735);
		}
	} else {
		//ignore
	}
}


//Opens the main window from the landing page
function opensite(lang) {
	window.open("player.php?lang="+lang,"player","fullscreen,scrollbars,resizable,status,left=0,top=0,width="+screen.width+",height="+screen.height);
}

//Opens wallpaper windows
function openwallpaper(wallpaperid, width, height) {
	window.open("wallpaper/index.php?wp="+wallpaperid,"wallpaper","fullscreen,scrollbars,resizable,status,left=0,top=0,width="+screen.width+",height="+screen.height);
}


//Opens screenshot windows
function openscreenshot(screenshotid) {
	window.open("screenshots/index.php?ss="+screenshotid,"screenshot","fullscreen,scrollbars,resizable,status,left=0,top=0,width="+screen.width+",height="+screen.height);
}


// 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 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 );
	}
}

// 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 };
}

function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != "function"){
		window.onload = func;
	} 
	else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

// scroll the page to just below the header flash movie.
function scrollPastHeader() {
	/*if (navigator.userAgent.indexOf("MSIE 7")==-1)
	{
		//var scrollToY = 270;
		var scrollToY = 170;
	}else{
		//var scrollToY = 250;
		var scrollToY = 150;
	}*/
	
	var scrollToY = 170;
	
	var winSize = getWindowSize();
	var pageSize = getPageSize();
	if(winSize.height < 800){
		scrollPageVertical( Math.max( 0, Math.min( scrollToY, pageSize.height - winSize.height + 5 ) ) );
	}
}
