//find query attached
var pageLoc = String(document.location);
var queryPos = pageLoc.indexOf("&");
var queryString = (queryPos < 0) ? "" : pageLoc.substring(queryPos);

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}

if (getQueryVariable('subsec')){
	var section = getQueryVariable('subsec');
	switch(section){
		case 'gates-challenge':
			popGatesChallenge();
			break;
		case 'treasure-hunter':
			popTreasureHunter();
			break;
		case 'pinball':
			popPinball();
			break;
		case 'cavern-climber':
			popCavernClimber();
			break;
		case 'chunnel-racer':
			popChunnelRacer();
			break;
		default:
			break;
	}
}

//popup
function popup( url, w, h, windowName, r, s ) {
	alertTest('popup( '+ url +', '+ w +', '+ h +', '+ windowName +', '+ r +', '+ s +')');
	win = window.open(url, windowName, 'height=' +h+ ', width=' +w+ ', resizable=' +r+ ', status=no, scrollbars=' +s+ ', location=no, menubar=no, toolbar=no, left=50, top=50');
	win.focus();
}
function popupFull( url, w, h, windowName, r, s ) {
	alertTest('popupFull');
	win = window.open(url, windowName, 'height=' +h+ ', width=' +w+ ', resizable=' +r+ ', status=no, scrollbars=' +s+ ', location=no, menubar=yes, toolbar=no, left=50, top=50');
	win.focus();
}

// browser and os detect
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('safari')) browser = "safari"
else if (checkIt('msie')) browser = "msie"
else if (!checkIt('compatible')) browser = "ns"
else browser = "unknown";

if (checkIt('windows')) os = "pc"
else if (checkIt('mac')) os = "mac"
else os = "unknown";

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


//order now link
function orderNow(){
	alertTest('orderNow');
	popup('http://disneyvideos.disney.go.com/moviefinder/calltoorder.html', 380, 265, 'calltoorder', 'no', 'no');
}

//Disney Movie Rewards
function movieRewards() {
	location.href = "http://disney.go.com/disneymovierewards/";
}

//buddy icon download
function buddyIcon(icon){
    var pagePath = "" + window.location;
    var pageRoot = pagePath.substring(0,pagePath.lastIndexOf("/")-3) +"images/downloads/msn_icons/";
	var iconUrl = "aim:BuddyIcon?src="+pageRoot+icon+'.gif';
	//var iconUrl = pageRoot+icon;
	//alert(iconUrl);
	if (os == 'pc'){
		//hbxPageHit('icon+'+icon, '101+dalmatians/downloads/icons;downloads/animated+classics/101+dalmatians/icons');
		document.location = iconUrl;
	}
	else alert ('This is a PC feature only.  Please click "Download Full Set".');
}


//Games
function popGatesChallenge() {
	popup('us/games/gates_challenge/index.html', 700, 810, 'gateschallenge', 'no', 'no');
}

function popTreasureHunter() {
	popup('us/games/treasure_hunter/index.html', 640, 610, 'treasurehunter', 'no', 'no');
}

function popPinball() {
	popup('us/games/pinball/index.html', 600, 708, 'pinball', 'no', 'no');
}

function popCavernClimber() {
	popup('us/games/cavern_climber/index.html', 640, 610, 'cavern', 'no', 'no');
}

function popChunnelRacer() {
	popup('us/games/chunnel_racer/NT2_35_int.html', 700, 810, 'chunnel', 'no', 'no');
}

//Screensaver
function popScreensaver() {
	popup('us/screensaver/index.html', 550, 500, 'chunnel', 'no', 'no');
}
