﻿//programmed deeplinks: 
//deeplink variable: dl

//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];
		}
	}
}

//get deeplink query
//valid deeplinks
deeplink_array = new Array("home", "aboutthedvd", "movieclips", "games", "downloads", "gallery", "disneymoms");
//check deeplink
if (getQueryVariable('dl')){
	if (getQueryVariable('dl') == 'nitasjourney'){
		game();
		deeplink_query = 'dl=home';
	}
	else if (getQueryVariable('dl') != undefined){
		valid = false;
		for (d=0; d<deeplink_array.length; d++){
			if (getQueryVariable('dl') == deeplink_array[d]){
				deeplink_query = "dl="+getQueryVariable('dl');
				valid = true;
			}
		}
		if (!valid){
			deeplink_query = 'dl=home';
		}
	}
	else{
		deeplink_query = 'dl=home';
	}
}
else{
	deeplink_query = 'dl=home';
}
//alert(deeplink_query);

var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

//bio includes
function pullBio(file){
	xmlHttp.open("GET", 'bios/'+file, false );
	xmlHttp.send("");
	document.write(xmlHttp.responseText);
}

// 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;
}

//popup
function popup( url, w, h, windowName, r, s ) {
	try {
		win.close();
	}catch(e){		
	}
	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 ) {
	try {
		win.close();
	}catch(e){		
	}
	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();
}

//action tag
function actionTag(page){
	var actionLoad = 'http://switch.atdmt.com/action/';
	document.action_tag.src = actionLoad + page;
}

//START HBX-------------------------------------------------------------------------------

//exit links
exitLink = new Array();
exitLink[0] = escape("Exit_brother+bear+2_moms_parent+reviews");
exitLink[1] = escape("Exit_brother+bear+2_ORDER");
exitLink[2] = escape("Exit_brother+bear+2_SYNERGY_disney+planning+kit");

//flash tracking - mlc's (corresponds with flashLinkPN array)
flashLinkMLC = new Array();
flashLinkMLC[0] = escape("/brother+bear+2/about/about;/about/dvp/brother+bear+2/about");
flashLinkMLC[1] = escape("/brother+bear+2/about/story;/about/dvp/brother+bear+2/story");
flashLinkMLC[2] = escape("/brother+bear+2/about/bonus+features;/about/dvp/brother+bear+2/bonus+features");
flashLinkMLC[3] = escape("/brother+bear+2/about/cast&crew;/about/dvp/brother+bear+2/cast&crew");
flashLinkMLC[4] = escape("/brother+bear+2/multimedia;/multimedia/dvp/brother+bear+2");
flashLinkMLC[5] = escape("/brother+bear+2/multimedia/ext+preview;/multimedia/dvp/brother+bear+2/ext+preview");
flashLinkMLC[6] = escape("/brother+bear+2/multimedia/trailers;/multimedia/dvp/brother+bear+2/trailers");
flashLinkMLC[7] = escape("/brother+bear+2/multimedia/clips;/multimedia/dvp/brother+bear+2/clips");
flashLinkMLC[8] = escape("/brother+bear+2/multimedia/clips;/multimedia/dvp/brother+bear+2/clips");
flashLinkMLC[9] = escape("/brother+bear+2/multimedia/clips;/multimedia/dvp/brother+bear+2/clips");
flashLinkMLC[10] = escape("/brother+bear+2/multimedia/clips;/multimedia/dvp/brother+bear+2/clips");
flashLinkMLC[11] = escape("/brother+bear+2/multimedia/clips;/multimedia/dvp/brother+bear+2/clips");
flashLinkMLC[12] = escape("/brother+bear+2/multimedia/clips;/multimedia/dvp/brother+bear+2/clips");
flashLinkMLC[13] = escape("/brother+bear+2/interactive+content/greeting+cards;/interactive+content/dvp/brother+bear+2/greeting+cards");
flashLinkMLC[14] = escape("/brother+bear+2/interactive+content/games;/interactive+content/dvp/brother+bear+2/games");
//flashLinkMLC[15] = escape("/brother+bear+2/interactive+content/games;/interactive+content/dvp/brother+bear+2/games");
flashLinkMLC[16] = escape("/brother+bear+2/interactive+content/games;/interactive+content/dvp/brother+bear+2/games");
flashLinkMLC[17] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[18] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[19] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[20] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[21] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[22] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[23] = escape("/brother+bear+2/downloads/activity+pages;/downloads/brother+bear+2/activity+pages");
flashLinkMLC[24] = escape("/brother+bear+2/downloads;/downloads/dvp/brother+bear+2");
flashLinkMLC[25] = escape("/brother+bear+2/downloads/screensavers;/downloads/dvp/brother+bear+2/screensavers");
flashLinkMLC[26] = escape("/brother+bear+2/downloads/screensavers;/downloads/dvp/brother+bear+2/screensavers");
flashLinkMLC[27] = escape("/brother+bear+2/downloads/screensavers;/downloads/dvp/brother+bear+2/screensavers");
flashLinkMLC[28] = escape("/brother+bear+2/downloads/icons;/downloads/dvp/brother+bear+2/icons");
flashLinkMLC[29] = escape("/brother+bear+2/downloads/wallpapers;/downloads/dvp/brother+bear+2/wallpapers");
flashLinkMLC[30] = escape("/brother+bear+2/multimedia/photo+galleries;/multimedia/dvp/brother+bear+2/photo+galleries");
flashLinkMLC[31] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[32] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[33] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[34] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[35] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[36] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[37] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");
flashLinkMLC[38] = escape("/brother+bear+2/downloads/moms;downloads/brother+bear+2/moms");

//flash tracking - pn's (corresponds with flashLinkMLC array)
flashLinkPN = new Array();
flashLinkPN[0] = escape("aboutthedvd+main");
flashLinkPN[1] = escape("synopsis");
flashLinkPN[2] = escape("dvd+features");
flashLinkPN[3] = escape("cast");
flashLinkPN[4] = escape("movieclips+main");
flashLinkPN[5] = escape("ext+preview");
flashLinkPN[6] = escape("trailer+e27521");
flashLinkPN[7] = escape("clip1+e28112");
flashLinkPN[8] = escape("clip2+e28111");
flashLinkPN[9] = escape("clip3+e28108");
flashLinkPN[10] = escape("clip4+e28107");
flashLinkPN[11] = escape("bclip1+e28113");
flashLinkPN[12] = escape("bclip2+e28716");
flashLinkPN[13] = escape("games+and+activities");
flashLinkPN[14] = escape("games+main");
//flashLinkPN[15] = escape("game+nitas+journey");
flashLinkPN[16] = escape("game2+(add name)");
flashLinkPN[17] = escape("activities+main");
flashLinkPN[18] = escape("activity+pages");
flashLinkPN[19] = escape("door+hanger");
flashLinkPN[20] = escape("maze");
flashLinkPN[21] = escape("bookmark");
flashLinkPN[22] = escape("backpack+tag");
flashLinkPN[23] = escape("plus+more");
flashLinkPN[24] = escape("downloads+main");
flashLinkPN[25] = escape("screensaver+main");
flashLinkPN[26] = escape("ss+mac");
flashLinkPN[27] = escape("ss+pc");
flashLinkPN[28] = escape("icons+main");
flashLinkPN[29] = escape("wallpapers+main");
flashLinkPN[30] = escape("gallery+main");
flashLinkPN[31] = escape("disneymoms+main");
flashLinkPN[32] = escape("register");
flashLinkPN[33] = escape("mousse+recipe");
flashLinkPN[34] = escape("amulet");
flashLinkPN[35] = escape("super+sibs");
flashLinkPN[36] = escape("yes+you+can");
flashLinkPN[37] = escape("mom+minutes");
flashLinkPN[38] = escape("worldly+wise");

//END HBX---------------------------------------------------------------------------------

//hbx tracking
function trackPage(page){
	switch(page){
		case 'aboutthedvd+main':
			hitbox.Set_hbPageView(flashLinkPN[0],flashLinkMLC[0]);
			break;
		case 'synopsis':
			hitbox.Set_hbPageView(flashLinkPN[1],flashLinkMLC[1]);
			break;
		case 'dvd+features':
			hitbox.Set_hbPageView(flashLinkPN[2],flashLinkMLC[2]);
			break;
		case 'cast':
			hitbox.Set_hbPageView(flashLinkPN[3],flashLinkMLC[3]);
			break;
		case 'movieclips+main':
			hitbox.Set_hbPageView(flashLinkPN[4],flashLinkMLC[4]);
			break;
		case 'games+main':
			hitbox.Set_hbPageView(flashLinkPN[14],flashLinkMLC[14]);
			break;
		case 'downloads+main':
			hitbox.Set_hbPageView(flashLinkPN[24],flashLinkMLC[24]);
			break;
		case 'screensaver+main':
			hitbox.Set_hbPageView(flashLinkPN[25],flashLinkMLC[25]);
			break;
		case 'icons+main':
			hitbox.Set_hbPageView(flashLinkPN[28],flashLinkMLC[28]);
			break;
		case 'wallpapers+main':
			hitbox.Set_hbPageView(flashLinkPN[29],flashLinkMLC[29]);
			break;
		case 'gallery+main':
			hitbox.Set_hbPageView(flashLinkPN[30],flashLinkMLC[30]);
			break;
		case 'disneymoms+main':
			hitbox.Set_hbPageView(flashLinkPN[31],flashLinkMLC[31]);
			break;
		default:
			break;
	}
}

//cast bio
function castBio(name){
	popup('bios.html?name='+name, 550, 470, 'bio', 'no', 'no');
}

//view trailer - pass me the number
//popTrailer(2);
function popTrailer(number){
	switch(number){
		case 1: //trailer
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e27521', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[6],flashLinkMLC[6]);
			actionTag('060822_BrotherBear2_trailer');
			break;
		case 2: //bonus clip
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28113', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[11],flashLinkMLC[11]);
			break;
		case 3: //movie clip 1
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28112', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[7],flashLinkMLC[7]);
			break;
		case 4: //movie clip 2
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28111', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[8],flashLinkMLC[8]);
			break;
		case 5: //movie clip 3
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28108', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[9],flashLinkMLC[9]);
			break;
		case 6: //movie clip 4
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28107', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[10],flashLinkMLC[10]);
			break;
		case 7: //extended preview
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28370', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[5],flashLinkMLC[5]);
			actionTag('060822_BrotherBear2_sneakpreview');
			break;
		case 8: //parent review clip
			popup('http://www.totaleclips.com/player/splash.aspx?custid=3&playerid=2&clipid=e28716', 360, 480, 'trailer', 'no', 'no');
			hitbox.Set_hbPageView(flashLinkPN[12],flashLinkMLC[12]);
			break;
		default:
			break;
	}
}

//order now link
//orderNow();
function orderNow(){
	try {
		win.close();
	}catch(e){		
	}
	win = window.open('http://go-disneyshopping.com/BrotherBear2DVD');
	win.focus();
	hitbox.Set_hbLink(exitLink[1]);
	actionTag('060822_BrotherBear2_ordernow');
}

//wallpapers - pass me the number and width
//wallpaper(2, 800);
function wallpaper(number, width){
	popup('wallpaper.html?number='+number+'&width='+width, 700, 500, 'wallpaper', 'yes', 'yes');
	//will pop wallpaper.html with image passed dynamically - image must be images/wallpapers/(width)SPD2_#.jpg
	//example: 1024SPD2_1.jpg
}

//download - pass me the file
//download('download/icons.zip');
function download(file){
	popup('download_file.html?file='+file, 300, 250, 'download', 'no', 'no');//sp2 fix
	//alert(file);//test
}

//screensaver - pass me the os (win or osx)
//screensaver('win');
function screensaver(os){
	switch(os){
		case 'win': //windows
			download('download/BrotherBear2_pc.exe.zip');//sp2 fix
			hitbox.Set_hbPageView(flashLinkPN[27],flashLinkMLC[27]);
			break;
		case 'osx': //osx
			download('download/BrotherBear2_osx.sit');//sp2 fix
			hitbox.Set_hbPageView(flashLinkPN[26],flashLinkMLC[26]);
			break;
		default:
			break;
	}
}

//buddy icons
function buddyIcons(){
	popup('buddyicons.html', 550, 520, 'icons', 'no', 'no')
}

//buddy icons
function buddyIcon(icon){
    var pagePath = "" + window.location;
    var pageRoot = pagePath.substring(0,pagePath.lastIndexOf("/")+1) + "images/icons/";
	var iconUrl = "aim:BuddyIcon?src="+pageRoot+icon;
	//var iconUrl = pageRoot+icon;
	if (os == 'pc')
		document.location = iconUrl;
	else alert ('This is a PC feature only.  Please click "Download Full Set".');
}

//game
function game(){
	popup('game/index.html', 640, 600, 'game', 'no', 'no')
}

//printables
//type = 1 or 2
//1=instructions
//2=printable
//printable = activitycoloring, doorhanger, maze, bookmark, backpacktag
function printGameActivity(type, printable, number){
	switch(type){
		case 1:
			popup('instructions_'+printable+'.html', 468, 497, 'instructions', 'no', 'no');//pop instructions
			break;
		case 2:
			if ( (printable == 'doorhanger') || (printable == 'maze') ) self.close();
			//popupFull('activity.html?printable='+printable+'&number='+number, 620, 500, printable, 'yes', 'yes');//pop printable
			//popupFull('pdf/'+printable+'_'+number+'.pdf', 620, 500, printable, 'yes', 'yes');//pop printable
			
popupFull('http://amedia.disney.go.com/disneyvideos/animatedfilms/brotherbear2/pdf/'+printable+'_'+number+'.pdf', 620, 500, printable, 'yes', 'yes');//pop printable				
			break;
		default:
			break;
	}
}

//link to disney mom's registration
function disneyMomsReg(){
	openDisclaimer('https://www.interactualdvd.com/disney/discregistration/default.asp?bc=1');//pop disclaimer
	hitbox.Set_hbPageView(flashLinkPN[32],flashLinkMLC[32]);
}

//mom pdf tips
function momArticle(topic){
	//popupFull('pdf/'+topic+'.pdf', 630, 500, 'mom_pdf', 'yes', 'yes');
	popupFull('http://amedia.disney.go.com/disneyvideos/animatedfilms/brotherbear2/pdf/'+topic+'.pdf', 630, 500, 'mom_pdf', 'yes', 'yes');
	if (topic == 'mousse_recipe') hitbox.Set_hbPageView(flashLinkPN[33],flashLinkMLC[33]);
	else if (topic == 'amulet') hitbox.Set_hbPageView(flashLinkPN[34],flashLinkMLC[34]);
	else if (topic == 'super_sibs') hitbox.Set_hbPageView(flashLinkPN[35],flashLinkMLC[35]);
	else if (topic == 'yes_you_can') hitbox.Set_hbPageView(flashLinkPN[36],flashLinkMLC[36]);
	else if (topic == 'mom_minutes') hitbox.Set_hbPageView(flashLinkPN[37],flashLinkMLC[37]);
	else if (topic == 'worldly_wise') hitbox.Set_hbPageView(flashLinkPN[38],flashLinkMLC[38]);
}

//disclaimer
function openDisclaimer(URL){
	win = window.open('http://disney.go.com/disneyvideos/javascript/disclaimer/disclaimer.html?'+ URL, 'intermediate', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=370,height=210');
}