//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 'about':
			var sec = 1;
			break;
		case 'clips':
			var sec = 2;
			break;
		case 'games':
			var sec = 3;
			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;
}


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

//disclaimer
function openDisclaimer(URL){
	//if (opener)	opener.document.location = URL;
	//else 
	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');
}

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

//Links Popup
function popLinks(){
	popup('links.html', 300, 250, 'links', 'no', 'no');
}

//Sweepetakes
function popSweeps(){
	popup('sweeps.html', 300, 250, 'sweepstakes', 'no', 'no');
}

//Order Now Link
function orderNowDVD(){
	alertTest('orderNowDVD');
	actionTag('SleepingBeautyPlatinum_buynow');
	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=1224768&langId=-1&categoryId=13694&CMP=OTL-TWDC_BVHE&att=BVHE');
}

function orderNowBluray(){
	alertTest('orderNowBluray');
	actionTag('SleepingBeautyPlatinum_buynow_BR');
	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=1224770&langId=-1&categoryId=13694&CMP=OTL-TWDC_BVHE&att=BVHE');
}


//Downloads

//Wallpaper
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
			popup('download.html?file=downloads/screensavers/SB_ss1-ss_pc_setup.zip', 300, 250, 'download', 'no', 'no');
			break;
		case 'mac': //osx
			popup('download.html?file=downloads/screensavers/SB_ss1-ss_osx.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
			popup('download.html?file=downloads/screensavers/SB_Bonus_ss2-ss_pc_setup.zip', 300, 250, 'download', 'no', 'no');
			break;
		case 'mac': //osx
			popup('download.html?file=downloads/screensavers/SB_Bonus_ss2-ss_osx.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 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'){
		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')
}

//Game and Activities
function popPumpkinKit() {
	cto.trackLink('sle_pdf1/games_activities/pumpkin_kit/080808');
	window.open('pdfs/pumpkin_carving_kit.pdf')
}

function popMasks() {
	cto.trackLink('sle_pdf2/games_activities/masks/080808');
	window.open('pdfs/online_masks.pdf')
}

function popCastleEscape() {
	popup('games/castle_escape/index.html', 728, 500, 'castle_escape', 'no', 'no')
}

function popFairyFrenzy() {
	popup('games/fairy_frenzy/index.html', 800, 597, 'fairy_frenzy', 'no', 'no')
}

//Links
function linkMinuteMaid(){
	openDisclaimer('http://www.minutemaid.com/');
	self.close();
}
