//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('section')){
	var section = getQueryVariable('section');
	switch(section){
		case 'home':
			var sec = 0;
			break;
		case 'virtual-puppy':
			var sec = 0;
			popWebDemo();
			break;
		case 'about':
			var sec = 1;
			break;
		case 'clips':
			var sec = 2;
			break;
		case 'games':
			var sec = 3;
			break;
		case 'doggone-escape':
			var sec = 3;
			popDogGoneEscape();
			break;
		case 'twilight-bark':
			var sec = 3;
			popTwilightBark();
			break;
		case 'downloads':
			var sec = 4;
			break;
		default:
			var sec = 0;
			break;
	}
}
else if (getQueryVariable('sec') && (getQueryVariable('sec') == 0 || getQueryVariable('sec') == 1 || getQueryVariable('sec') == 2 || getQueryVariable('sec') == 3 || getQueryVariable('sec') == 4)){
	var sec = getQueryVariable('sec');
}
else{
	var sec = 0;
}
sec = sec.toString(); //convert to string so i can compare below

//set default tracking for when deeplinks are used
switch(sec){
	case '0':
		var default_pn = 'home+page';
		var default_mlc = '101+dalmatians/information/home;information/animated+classics/101+dalmatians/home';
		break;
	case '1':
		var default_pn = 'about+the+dvd';
		var default_mlc = '101+dalmatians/about/about;about/animated+classics/101+dalmatians/about';
		break;
	case '2':
		var default_pn = 'videos+main';
		var default_mlc = '101+dalmatians/multimedia;multimedia/animated+classics/101+dalmatians';
		break;
	case '3':
		var default_pn = 'games+main';
		var default_mlc = '101+dalmatians/interactive+content/games;interactive+content/animated+classics/101+dalmatians/games';
		break;
	case '4':
		var default_pn = 'downloads+main';
		var default_mlc = '101+dalmatians/downloads;downloads/animated+classics/101+dalmatians';
		break;
	default:
		var default_pn = 'home+page';
		var default_mlc = '101+dalmatians/information/home;information/animated+classics/101+dalmatians/home';
		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;
}

function popLinks(){
	//this tracking is only for when it is coming soon
	//when the links page is done, remove this trackSection and add the hbx to the page
	trackSection('links');
	popup('comingsoon.html', 300, 250, 'cs', 'no', 'no');
	//popup('links.html', 550, 520, 'cs', 'no', 'no');
}

function popSweeps(){
	hbxExit('exit_101+dalmatians_disney+movie+rewards');
	win = window.open('http://disney.go.com/disneymovierewards/101/?BAC-101Burst');
	//popup('comingsoon.html', 300, 250, 'cs', 'no', 'no');
}

function popTrailer(){
	popup('http://www.totaleclips.com/player/splash.aspx?clipid=e35670&playerid=2&custid=3', 350, 500, 'trailer', 0, 0);
}

//order now link
function orderNow(){
	alertTest('orderNow');
	hbxExit('exit_101+dalmatians_order+dvd');
	//popup('http://disneyvideos.disney.go.com/moviefinder/calltoorder.html', 380, 265, 'calltoorder', 'no', 'no');
	window.open('http://transfer.go.com/cgi/transfer.dll?name=23303&SOURCE=23303&srvc=store&goto=http://disneyshopping.go.com/webapp/wcs/stores/servlet/DSIProductDisplay?catalogId=10002&storeId=10051&productId=1219155&langId=-1&categoryId=13690&CMP=OTL-TWDC_BVHE&att=BVHE');
	actionTag('101_Dalmatians_buynow');
}

//downloads
function wallpaper(number, width, loc){
	popup('wallpaper.html?number='+number+'&width='+width+'&loc='+loc, 900, 600, 'wallpaper', 'yes', 'yes');
	//will pop wallpaper.html with image passed dynamically - image must be images/wallpapers/WP(number)_(width).jpg
	//example: WP1_800.jpg
}

//screensaver - pass me the os (win or osx)
//screensaver('win');
function screensaver(os){
	alertTest('screensaver(\''+ os +'\')');
	switch(os){
		case undefined: //instructions
			win = popup('screensaver.html', 550, 520, 'ss', 0, 0);
			break;
		case 'pc': //windows
			hbxPageHit('ss+pc', '101+dalmatians/downloads/screensavers;downloads/animated+classics/101+dalmatians/screensavers');
			popup('download.html?file=download/101Dalmatians.zip', 300, 250, 'download', 'no', 'no');
			break;
		case 'mac': //osx
			hbxPageHit('ss+mac', '101+dalmatians/downloads/screensavers;downloads/animated+classics/101+dalmatians/screensavers');
			popup('download.html?file=download/101Dalmatians.sit', 300, 250, 'download', 'no', 'no');
			break;
		default:
			break;
	}
}
function screensaverBonus(os){
	alertTest('screensaver(\''+ os +'\')');
	switch(os){
		case undefined: //instructions
			win = popup('screensaver_bonus.html', 550, 520, 'ss', 0, 0);
			break;
		case 'pc': //windows
			hbxPageHit('ss+pc+bonus', '101+dalmatians/downloads/screensavers;downloads/animated+classics/101+dalmatians/screensavers');
			popup('download.html?file=download/101Dalmatians-Bonus.zip', 300, 250, 'download', 'no', 'no');
			break;
		case 'mac': //osx
			hbxPageHit('ss+mac+bonus', '101+dalmatians/downloads/screensavers;downloads/animated+classics/101+dalmatians/screensavers');
			popup('download.html?file=download/101Dalmatians-Bonus.sit', 300, 250, 'download', 'no', 'no');
			break;
		default:
			break;
	}
}

//buddy icons
function buddyIcons(){
	popup('buddyicons.html', 550, 520, 'icons', 'no', 'no')
}
function buddyIconsBonus(){
	popup('buddyicons_bonus.html', 550, 520, 'icons', 'no', 'no')
}

//buddy icons
function buddyIconSet(){
	hbxPageHit('icon+full+set', '101+dalmatians/downloads/icons;downloads/animated+classics/101+dalmatians/icons');
	popup('download.html?file=download/101Dalmatians_AIM-Icons.zip', 300, 250, 'download', 'no', 'no');
}
function buddyIconSetBonus(){
	hbxPageHit('icon+full+set+bonus', '101+dalmatians/downloads/icons;downloads/animated+classics/101+dalmatians/icons');
	popup('download.html?file=download/101Dalmatians_AIM-Icons-Bonus.zip', 300, 250, 'download', 'no', 'no');
}

//buddy icon download
function buddyIcon(icon, loc){
    var pagePath = "" + window.location;
    var pageRoot = pagePath.substring(0,pagePath.lastIndexOf("/")+1) + "img/"+ loc +"/section_downloads/buddyicons/";
	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".');
}

//animated signatures
function emailSigs(){
	popup('emailsig.html', 800, 597, 'animsig', 'no', 'no')
}
function emailSigsBonus(){
	popup('emailsig_bonus.html', 800, 597, 'animsig', 'no', 'no')
}

//games
function popDogGoneEscape(){
	alertTest('popDogGoneEscape');
	popup('games/escape/index.html', 800, 600, 'escape', 'no', 'no');
}
function popTwilightBark(){
	alertTest('popTwilightBark');
	popup('games/twilight/index.html', 800, 600, 'twilight', 'no', 'no');
}
function popCharMasks(){
	alertTest('popCharMasks');
	hbxPageHit('activity+sheet1', '101+dalmatians/downloads/activities;downloads/animated+classics/101+dalmatians/activities');
	popup('http://amedia.disney.go.com/disneyvideos/animatedfilms/101dalmatians/img/us_english/section_games/101Dalmatians_Masks.pdf', 900, 600, 1, 1);
}

function popWebDemo(){
	alertTest('popWebDemo');
	popup('101Dalmatians_web_demo/index.html', 780, 637, 'demo', 'no', 'no');
}

//Disney Movie Rewards
function movieRewards() {
	hbxExit('exit_101+dalmatians_disney+movie+rewards');
	location.href = "http://disney.go.com/disneymovierewards/";
}

//You May Also Like Bar
function ymal_snowbuddies() {
	hbxExit('exit_101+dalmatians_snow+buddies');
	location.href = "http://adisney.go.com/disneyvideos/liveaction/snowbuddies/";
}

function ymal_junglebook2() {
	hbxExit('exit_101+dalmatians_jungle+book2');
	location.href = "http://disney.go.com/disneyvideos/animatedfilms/junglebook2/";
}

function ymal_enchanted() {
	hbxExit('exit_101+dalmatians_enchanted');
	location.href = "http://disney.go.com/disneyvideos/liveaction/enchanted";
}

function ymal_movieclub() {
	hbxExit('exit_101+dalmatians_disney+movie+club');
	location.href = "http://disney.videos.go.com/General/Acquisition/SignUp/Index?locale=en_US&promoCode=93203&splash=yes";
}

//You May Also Like Bar
function ymal_popup_snowbuddies() {
	hbxExit('exit_101+dalmatians_snow+buddies');
	opener.document.location = "http://adisney.go.com/disneyvideos/liveaction/snowbuddies/";
	self.close();
}

function ymal_popup_junglebook2() {
	hbxExit('exit_101+dalmatians_jungle+book2');
	opener.document.location = "http://disney.go.com/disneyvideos/animatedfilms/junglebook2/";
	self.close();
}

function ymal_popup_enchanted() {
	hbxExit('exit_101+dalmatians_enchanted');
	opener.document.location = "http://disneydvd.disney.go.com/moviefinder/products/5239103.html";
	self.close();
}

function ymal_popup_movieclub() {
	hbxExit('exit_101+dalmatians_disney+movie+club');
	opener.document.location = "http://disney.videos.go.com/General/Acquisition/SignUp/Index?locale=en_US&promoCode=93203&splash=yes";
	self.close();
}

//Widget Popup
function popWidget(){
	hbxPageHit('101+widget', '/101+dalmatians/interactive+content/blog+tools;/interactive+content/animated+classics/101+dalmatians/blog+tools');
	popup('widget.html', 304, 707, 'widget', 0, 0);
}

function twilightDXD() {
	opener.document.location = "http://disney.go.com/dxd/index.html?channel=16825&content=116851&contentPlayerID=GameContent&";
	self.close();
}

function doggoneDXD() {
	opener.document.location = "http://disney.go.com/dxd/index.html?channel=16825&content=116848&contentPlayerID=GameContent&";
	self.close();
}