//common javascript methods for hp
var d = document;

var q=location.search;
var ID_TOKEN = "id=";
var SECTION_TOKEN = "section=";
var AMP_TOKEN = "&";
// ***** PARSE FOR ID TOKEN *****

var id  = q.substring(q.indexOf(ID_TOKEN) + ID_TOKEN.length);
// Check for other tokens in the query string 
if (id.indexOf(AMP_TOKEN) >= 0){
	id = id.substring(0, id.indexOf(AMP_TOKEN));
}

// ***** PARSE FOR SECTION TOKEN *****
if (q.indexOf(SECTION_TOKEN) >= 0){
	var section = q.substring(q.indexOf(SECTION_TOKEN) + SECTION_TOKEN.length);
	if (section.indexOf(AMP_TOKEN) >= 0){
		section = section.substring(0, section.indexOf(AMP_TOKEN));
	}
}

//Pop Up in a new window
/*<a href="javascript:popupWindow('http://www.wb.com','width=570, height=550, scrollbars=yes, resizable=yes, screenX=200, screenX=0, left=200, top=0');"></a>*/
function popupWindow(url,specs) {
	/* Custom Browser Attributes:
	width	number
	height	number
	* the default to these yes|no ones, is no *
	directories	yes | no (or 1 | 0)
	location	yes | no (or 1 | 0)
	menubar		yes | no (or 1 | 0)
	resizable	yes | no (or 1 | 0)
	scrollbars	yes | no (or 1 | 0)
	status		yes | no (or 1 | 0)
	toolbar		yes | no (or 1 | 0)
	*browser specific*
	screenX (NN4+)	number
	screenY (NN4+)	number
	left (IE4+)		number
	top	(IE4+)		number
	fullscreen (IE4+)	yes | no (or 1 | 0)
	*/
	window.open(url, "_blank", specs);
}


//For pop up windows going elsewhere
//get browser
var browser = navigator.appName;
//Open tout_url in mainwindow and close the popup
function gotoTOUT(tout_url, specs) {
//Pop-Up Window
//IE version
	if (browser == "Microsoft Internet Explorer"){
		var newWindow = window.open(tout_url, "hpmainwindow");
		self.close();
//Netscape (and any other browser type) version
	} else {
//If the parent window has been closed, open a new window
		if (window.opener == null){
			var newWindow = window.open(tout_url);
			self.close();
//If the parent window is still there, redirect it
		} else {
			var newWindow = window.opener.location.replace(tout_url);
			self.close();
		}
	}
}

//Newsletter Sign Up
function launchNewsletter(){
     window.open("/main/nlsignup/signup.html", "hogwarts","toolbar=0,scrollbars=0,menubar=0,resizable=0,width=450,height=200,screenX=200, screenX=50, left=200, top=50");
}

//Image Rollover
function over(imgName, img_src) {
	d[imgName].src=img_src;
}
function out(imgName, img_src) {
	d[imgName].src=img_src;
}

//Image Rollover for layers
function layerOver(layerName, imgName, img_src) {
	this.layer=document.layers?document[layerName].document[imgName].src=img_src:document[imgName].src=img_src;
	}
function layerOut(layerName, imgName, img_src) {
	this.layer=document.layers?document[layerName].document[imgName].src=img_src:document[imgName].src=img_src;
	}
	
// for the gallery
var imgNum = id;
if (id == ""){
	imgNum = "1";
}
var totalImgs = 5;

function nextBack(dir) {
	if (imgNum == totalImgs && dir > 0) {
		imgNum = 1;
	} else if (dir > 0) {
		imgNum++
	} else if (dir < 0 && imgNum != 1) {
		imgNum--
	} else {
		imgNum = totalImgs;
	}
	//resizeWindow(imgNum);
	imgNum = parseInt(imgNum - 1);
	swapImg(imgNum);
}

function swapImg(img) {
//This needs to be Fully qualified to the UK since gallery will reside there!!!!
	d.mainImg.src = "http://wwws.warnerbros.co.uk/polarexpress/images/media/photos/photo" + (parseInt(img) + 1) + ".jpg";
	imgNum = parseInt(img)+1;
}

//gallery photos
//Get the query string and validate it
var q = location.search;

var param1 = q.substring(q.indexOf("id=") + 3, q.indexOf("id=") + 4);

switch (param1) {
	case("1"):
	break;
	case("2"):
	break;
	case("3"):
	break;
	case("4"):
	break;
	case("5"):
	break;
	case("6"):
	break;
	default:
	param1 = "1";
}
