// chromeAndFooter.js

var xLoc = 0;
var yLoc = 0;

document.onmousemove=getMousePosition;

if (typeof chromeDisclaimerText == "undefined") {
	var chromeDisclaimerText = "Hey Kids! You are about to go to a page that may have ads for Disney products or services.";
}

var footerComImageDiv = "gde_comScoreLogo";


if (typeof chromeLinkMap == "undefined") {

	//channel type|highlighted tab|link URL|comScore image|comScore link
	var chromeLinkMap = [

		"Activities - Apps|create|http://disney.go.com/create/apps/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Artist|create|http://disney.go.com/create/artist/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Artists|create|http://disney.go.com/create/artists/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Designer|create|http://disney.go.com/create/designer/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Director|create|http://disney.go.com/create/director/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Galleries|create|http://disney.go.com/create/galleries/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Hall of Fame|create|http://disney.go.com/create/halloffame/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Master|create|http://disney.go.com/create/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Musician|create|http://disney.go.com/create/musician/|comscore_create.gif|http://disney.go.com/create",
		"Activities - My Create|create|http://disney.go.com/create/mycreate/|comscore_create.gif|http://disney.go.com/create",
		"Activities - Writer|create|http://disney.go.com/create/writer/|comscore_create.gif|http://disney.go.com/create",
		"Characters - All|characters|http://disney.go.com/characters/all/|comscore_characters.gif|http://disney.go.com/characters",
		"Characters - Animated|characters|http://disney.go.com/characters/animated/|comscore_characters.gif|http://disney.go.com/characters",
		"Characters - Classics|characters|http://disney.go.com/characters/classics/|comscore_characters.gif|http://disney.go.com/characters",
		"Characters - Live Action|characters|http://disney.go.com/characters/liveaction/|comscore_characters.gif|http://disney.go.com/characters",
		"Characters - Master|characters|http://disney.go.com/characters/|comscore_characters.gif|http://disney.go.com/characters",
		"Characters - Music Stars|characters|http://disney.go.com/characters/musicstars/|comscore_characters.gif|http://disney.go.com/characters",
		"Games - Action|games|http://disney.go.com/games/action/|comscore_games.gif|http://disney.go.com/games",
		"Games - All|games|http://disney.go.com/games/more/|comscore_games.gif|http://disney.go.com/games",
		"Games - Arcade|games|http://disney.go.com/games/arcade/|comscore_games.gif|http://disney.go.com/games",
		"Games - Characters|games|http://disney.go.com/games/characters/|comscore_games.gif|http://disney.go.com/games",
		"Games - Master|games|http://disney.go.com/games/|comscore_games.gif|http://disney.go.com/games",
		"Games - Puzzle|games|http://disney.go.com/games/puzzle/|comscore_games.gif|http://disney.go.com/games",
		"Games - Sports|games|http://disney.go.com/games/sports/|comscore_games.gif|http://disney.go.com/games",
		"Games - Video Games|games|http://disney.go.com/games/videogames/|comscore_games.gif|http://disney.go.com/games",
		"Games - Word|games|http://.disney.go.com/games/word/|comscore_games.gif|http://disney.go.com/games",
		"My Page - Master|my_page|http://disney.go.com/mypage/|comscore_mypage.gif|http://disney.go.com/mypage",
		"Videos - Characters|videos|http://disney.go.com/videos/characters/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - Classics|videos|http://disney.go.com/videos/classics/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - Disney Channel|videos|http://disney.go.com/tv/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - Disney XD|videos|http://disney.go.com/disneyxd/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - Master|videos|http://disney.go.com/videos/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - More|videos|http://disney.go.com/videos/more/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - Movies|videos|http://disney.go.com/videos/movies/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - Music Videos|videos|http://disney.go.com/musicvideos/|comscore_videos.gif|http://disney.go.com/videos",
		"Videos - TV Shows|videos|http://disney.go.com/videos/tvshows/|comscore_videos.gif|http://disney.go.com/videos"
	];
}
		


// Send a message from the chrome to Flash
function chromeMessage2DFSF(C) {
	if(C.panelID){
		var msg = {messageType:"com.disney.coretech.dfsf.messaging.ChangeChannelMessage", channelId:C.panelID};
	} else {
		var msg = {messageType:"com.disney.coretech.dfsf.messaging.NavigateToUrlMessage", url:C.url};
	}
	addDisclaimer();

	var flashObject = getFlashObject("dxdcontent");
	flashObject.sendMessage(msg);
}

// Receive a message from Flash and fire a chrome function.
function handleDFSFMessage(msg, messageType) {
	var theMessage = "";

	
	if(messageType) {
		switch(messageType) {
			case "com.disney.coretech.dfsf.messaging.JavascriptAdapterReadyMessage":
				var flashObject = getFlashObject("dxdcontent");
				flashObject.watchMessageType("com.disney.coretech.dfsf.messaging.ChannelChangedMessage");
				break;

			case "com.disney.coretech.dfsf.messaging.ChannelChangedMessage":
			
				theMessage = msg.channelCategory;
				var splitMessage = theMessage.split(" - ");
				theMessage = splitMessage[0];
				if (chromeLinkMap[theMessage]) {
					_gdeChrome.highlightChromeButton(chromeLinkMap[theMessage]);
				}

				changeFooter(msg.channelCategory);
				
				break;
			default:
				break;
		}
	}
}

// As a protective measure, preload the disclaimer background image.

var _bgImage = new Image();
_bgImage.src =  window.location.protocol+"//a.dolimg.com/en-US/dcom/media/foryou/preschool/disclaimerbg.gif";

function addDisclaimer(){
	bgURL=window.location.protocol+"//a.dolimg.com/en-US/dcom/media/foryou/preschool/disclaimerbg.gif";
	
	var oDiv=document.createElement("div");
	oDiv.id="chromeDisclaimer";
	oDiv.style.position="absolute";
	oDiv.style.top="0px";
	oDiv.style.left="0px";
	oDiv.style.visibility="hidden";
	oDiv.style.border="black 1px solid";
	oDiv.style.width="290px";
	oDiv.style.font="12px arial,helvetica,geneva,sans-serif";
	oDiv.style.fontWeight="bold";
	oDiv.style.padding="10px";
	oDiv.style.textAlign="center";
	oDiv.style.backgroundImage="url("+bgURL+")";
	oDiv.style.color="#FFFFFF";
	oDiv.style.zIndex="16002";
	oDiv.innerHTML=chromeDisclaimerText;
	document.body.appendChild(oDiv);
	oDiv.style.left=xLoc+'px';
	oDiv.style.top=yLoc+'px';
	oDiv.style.visibility='visible';
	
	waiter = function() {
	}
	
	disclaimerTimeout = setTimeout('waiter()', 3000);

}

function getMousePosition(doh){

	var xPos,yPos;

	if(document.all){
		xPos=event.clientX;
		yPos=event.clientY;
	}
	else{
		xPos=doh.pageX;
		yPos=doh.pageY;
	}

	xLoc=xPos-100;
	yLoc=yPos+10;

	return true;
}



function changeFooter(channel) {
	var lgProtocol=window.location.protocol.toString();
	var legalFooterImgPath="//"+((lgProtocol=="https:")?"s":"a")+".dolimg.com/en-US/dcom/media/footer/comscore/";
	var	comscoreImage = "comscore_disney.gif";
	var comscoreURL = "http://disney.go.com/index";

	if (channel) {
		for (var i = 0; i < chromeLinkMap.length; i++) {
			var linkParts = chromeLinkMap[i].split('|');
			if (channel == linkParts[0]) {
				comscoreImage = linkParts[3];
				comscoreURL = linkParts[4];
				break;
			}
		}
	}


	var D = document.getElementById(footerComImageDiv);
	var theLinks = D.getElementsByTagName('a');
	var theImages = theLinks[0].getElementsByTagName('img');
	theLinks[0].href = comscoreURL;
	theImages[0].src = legalFooterImgPath + comscoreImage;
}


// Utility function to get the flash object
function getFlashObject(id) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window.id;
	} else {
		return document.id;
	}
}


function chromeMessage(C) {
	output = "";
	for (items in C) {
		output += items + ": " + C[items] + "\n";
	}
	//alert(output);
}
