  // functionality for interactives that appear in frames.
// in shared code file for use by pages on msn.com domain.

// detect query strings
var aQuery = getQueryParams();
var parentData = (aQuery["parentid"]) ? eval("top."+aQuery["parentid"]) : "";

if (parentData) {
	appBG = parentData.appBG[1];
	margin = parentData.copyMargin;
	iWidth = parentData.copyWidth-18-(2*margin);
	linkHover = parentData.sNavLinkHover;
	textColor = parent.getSingleStyle(parentData.sBodyFont,"color");
	headlineStyle = parentData.headlineStyle;
	sBodyFont = parentData.sBodyFont;
	headlineStyle = parentData.headlineStyle;
} else {
	appBG = (aQuery["appbg"]) ? aQuery["appbg"] : "bgcolor=FFFFFF";
	margin = (aQuery["margin"]) ? aQuery["margin"] : 0;
	iWidth = (aQuery["w"]) ? aQuery["w"] : 360;
	linkHover = "color:cc0000;";
	textColor = "color:000000;";
	headlineStyle = "";
}

if (aQuery["type"]=="v") { margin=0; }
if (aQuery["fmt"] && aQuery["fmt"].indexOf("frame") > -1) { 
	document.write("<html><body " +appBG+ " topmargin=" +margin+ " leftmargin=" +margin+ " marginheight=" +margin+ " marginwidth=" +margin+ "><STYLE type=TEXT/CSS> A { " +textColor+ " } A:hover { " +linkHover+ " } A:visited { " +textColor+ " } B { " +headlineStyle+ " } </STYLE><CENTER>");
}

function inframeSurvey(oLV) {
	oLV.appWidth = iWidth;
	oLV.columns = (aQuery["cols"]) ? aQuery["cols"] : 1;
	if (window.sBodyFont) { oLV.sBodyFont = sBodyFont; }
	if (window.headlineStyle) { oLV.headlineStyle = headlineStyle; }
	if (aQuery["brand"] == "0") { oLV.appHeader = ""; oLV.appFooter = ""; }
	if (!aQuery["parentid"]) {
		oLV.appBG = "bgcolor=#FFE" ;
		oLV.bDhtml=0;
		oLV.appHeader = "<img src=\"http://msnbcmedia.msn.com/i/msnbc/Components/ColorBoxes/Styles/ColorBoxImages(GlobalOnlyPlease)/livevote.gif\" align=absmiddle>Live Vote" ;			
		oLV.sHedStyle = "background-color:#FFCC66;color:#000000;" ;
		oLV.copyBorder = "border:1px #CCCCCC solid; ";
	}
	DisplayLV(oLV);
}

function inframeVideo(filename,iWidth) {
	// ad, promo disabled. Speed detection handled by player.
	var videoUrl = "http://www.msnbc.com/m/mw/s/msnbc/asx.asp?s=100&a=" +filename+ "&ad=&t=v&promo=&fix=.";

	if (!iWidth) { iWidth=320; }
	var iHeight = Math.round(iWidth*(240/320))+64

	var sTmp = "<table cellpadding=0 cellspacing=0 border=0 width=" +iWidth+ "><tr valign=top><td>";

	if (document.all) {
		sTmp += "<object	id=wmp width=" +iWidth+ " height=" +iHeight+ " classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' standby='Loading Microsoft Media Player compnents...' type='application/x-oleobject'><param name=URL value=" +videoUrl+ "><param name=uiMode value=\"mini\"><param name=autoStart value=1><param name=stretchToFit value=0></object>";
	} else {
		sTmp += "<embed target=_blank type=application/x-mplayer2 pluginspage=http://www.microsoft.com/windows/windowsmedia/EN/default.asp src=\"" +videoUrl+ "\" name=NSPlay width=" +iWidth+ " height=" +iHeight+ " ShowControls=1 EnableContextMenu=0 ShowAudioControls=1 ShowPositionControls=0 ShowTracker=0 ShowStatusBar=1 uiMode=\"mini\" AutoStart=1 AllowChangeDisplaySize=0 DisplaySize=0 autosize=0></embed>";
	}

	sTmp += "</td></tr>";

	if (window.parentData) {
		for (i=0;i<parentData.length;i++) {
			if (parentData[i][0] == filename) {
				sTmp += "<tr><td style='padding:0px 5px 0px 5px;'><font face=arial size=1 style=" +textColor+ ">"+parentData[i][2]+"</font></td></tr>";
			}
		}
	}
	sTmp += "</table>";
	return sTmp;
}

function getQueryParams() {
	// COMMON function
	var sQuery = location.search.substring(1);
	var aTmp = new Array();
	if (sQuery) {
		aTmp = sQuery.split("&");
		for (var i=0;i<aTmp.length;i++) {
			var aTmp2 = aTmp[i].split("=");
			aTmp[aTmp2[0].toLowerCase()] = aTmp2[1];
		}
	} 
	return aTmp;
}

// override site-wide function to fix link
function SSOpen(nId, nSize, sFrame, sVar1, sVar2) {
	if (!nId) return;
	if (!nSize||nSize=='') nSize = 0;
	oUser=new UberSniff();
	var nW=oUser.screenWidth;
	var sOptions="resizable=no,top=0,left=0,screenx=0,screeny=0";
	var sHref = "http://www.msnbc.msn.com/id/"+nId+"/displaymode/1107/";
	if (sFrame&&sFrame!='')sHref+="framenumber/"+sFrame+"/";
	if (sVar1&&sVar1!='')sHref+="var1/"+sVar1+"/";
	if (sVar2&&sVar2!='')sHref+="var2/"+sVar2+"/";
	var bNew = true;
	if (((nSize==0)||(nSize==2))&&nW>=935) {
		sOptions+=",width=935,height=700";
		sHref+="s/2/";
	} else if (((nSize==0)||(nSize==1))&&nW>=780) {
		sOptions+=",width=780,height=534";
		sHref+="s/1/";
	} else {
		bNew = false;
	}
	if (!bNew) {
	var xwinopen=window.open(sHref,"slideshow");
	} else {
	var xwinopen=window.open(sHref,"slideshow",sOptions);
		if(oUser.nn>3||oUser.ie>3) {xwinopen.focus();}
	}
}

// general code for displaying surround video images
function displaySurround(filename,iWidth,iHeight,altImg) {
	// combine w/ getTeaseImg or addImg2Body
	var ua = navigator.userAgent.toLowerCase();
	var caption = "";
	if (window.parentData) {
		for (i=0;i<parentData.length;i++) {
			if (parentData[i][0] == filename) {
				var oItem = parentData[i];
				if (parentData.altPath && filename.indexOf("/") != 0 && filename.indexOf("http:") == -1) { filename = parentData.altPath + filename; }
			}
		}
	} else if (typeof filename == "object") { var oItem = filename;filename=oItem[0]; }
	if (oItem) {
		altImg=oItem[3];
		if (!iWidth) { iWidth = oItem[14]; }
		if (!iHeight) { iHeight = oItem[14]; }
		if (oItem[11] || oItem[12]) { 
			var sSep = (oItem[11] && oItem[12]) ? " / " : ""; 
			caption += "<div class=credit style=\"text-align:right;margin-bottom:5px;\">" +oItem[11]+ sSep +oItem[12]+ "</div>"; 
		}
		if (oItem[2]) { caption += "<font face=arial size=1 style=" +textColor+ ";padding:0px 5px 0px 5px;>"+oItem[2]+"</font>"; }
	}
	if (!iWidth) { iWidth=320; }
	if (!iHeight) { iHeight=240; }
	var sTmp = "<table cellpadding=0 cellspacing=0 border=0 width=" +iWidth+ "><tr valign=top><td>";

	if (ua.indexOf("mac") > 0 || ua.indexOf("win16") > 0 || ua.indexOf("aol 3.0") > 0) {
		sTmp = "<img src='" +sAltImg+ "'></br>We are sorry. It appears that you're browser isn't able to display this Surround Video feature.";
	} else if (filename.indexOf(".ips") > -1 || filename.indexOf(".ipx") > -1) {
		sTmp += "<OBJECT ID='IpixX1' WIDTH=" +iWidth+ " HEIGHT=" +iHeight;
		sTmp += "CLASSID='CLSID:11260943-421B-11D0-8EAC-0000C07D88CF'";
		sTmp += "CODEBASE='http://www.ipix.com/download/ipixx.cab#version=6,2,0,5'>";
		sTmp += "<PARAM NAME='IPXFILENAME' VALUE='" +filename+ "'>";
		sTmp += "<embed src='" +filename+ "' border=0 width=" +iWidth+ " height=" +iHeight+ " palette='FOREGROUND' type='application/x-ipix' pluginsPage='http://www.ipix.com/cgi-bin/download.cgi'>";
		sTmp += "</embed></OBJECT>";
	} else if (ua.indexOf("msie") >0) {
		sTmp += "<OBJECT ID=MySurround";
		sTmp += "            CLASSID='clsid:928626A3-6B98-11CF-90B4-00AA00A4011F' TYPE='application/x-oleobject'";
		sTmp += "            ID=Surround1";
		sTmp += "            CODEBASE='http://autos.msn.com/components/ocx/survid/MSSurVid.cab#Version=1,2,0,10'";
		sTmp += "  width=" +iWidth+ " height=" +iHeight+ ">";
		sTmp += "  <param name='Image' value='" +filename+ "'>";
		sTmp += "</OBJECT>";
	}
	else if (navigator.mimeTypes['application/x-npwrap']) {
		sTmp += "<embed type='application/x-npwrap' CLASSID='928626A3-6B98-11CF-90B4-00AA00A4011F' NPCODEBASE='http://carpoint.msn.com/components/npwrap/npwrap.cab#Version=1,0,0,15' CODEBASE='http://autos.msn.com/components/ocx/survid/MSSurVid.cab#Version=1,2,0,10' CONTROLNAME='Microsoft Surround Video Version 1.2' PLUGINSPAGE='http://www.msnbc.com/netscape_surround_plugin.asp' WIDTH=" +iWidth+ " HEIGHT=" +iHeight+ " Image='" +filename+ "'> </embed>";
	}
	sTmp += "<br clear=all>" + caption;
	return sTmp + "</td></tr></table>";
}

function setNavBrand(navName,spat) {
	// change sub-section name or spat for msnbc stories
	var bIE = (document.all && document.getElementById);
	if (navName || spat || bantop) {
		if (sectionTabs) { tabsCell = "<td nowrap=\"true\" width=\"0px\" bgcolor=\"#bbbbbb\" class=\"linkSubSectionTab\" style=\"height:22px;padding:0 0 0 15;border-right:solid 1px black;border-left:solid 1px black;\">" +sectionTabs+ "</td>"; nameWidth = 0; } else { tabsCell = ""; nameWidth = 100; }

		var navNameTable = (navName) ? "<table width=649 border=0 cellspacing=0 cellpadding=0><tr><td nowrap=true width=\"" +nameWidth+ "%\" bgcolor=#eeeeee style=\"height:22px;padding:0 15 0 15;\" class=textsubsectiontab><Name>" +navName+ "</Name></td>" +tabsCell+ "</tr></table>" : "";
	
		var bFound=0; var nTable = 0;
		if (document.getElementById) {
			var aTables = document.getElementsByTagName("TABLE");
		} else if (document.all) {
			var aTables = document.all.tags("TABLE");
		}
		for (i=0;i<aTables.length;i++) {
			if (aTables[i].width == 649 && aTables[i].innerHTML.indexOf("textsubsectiontab") > -1) { // not all sections have this
				if (navName) {
					aTables[i].childNodes[0].childNodes[0].childNodes[0].innerHTML = navName;
					if (aTables[i].childNodes[0].childNodes[0].childNodes[1]) {
						aTables[i].childNodes[0].childNodes[0].childNodes[1].innerHTML = sectionTabs;
					}
					aTables[i].insertAdjacentHTML("afterEnd", spat);
				} else {
					aTables[i].outerHTML = spat + "<br>";
				}
				bFound=1;
			}
			if (aTables[i].width == 649 && aTables[i].innerHTML.indexOf("Bantop") > -1) { nTable = i; }

		}
		if (nTable) {
			if (bantop) { 
aTables[nTable].childNodes[0].childNodes[0].childNodes[0].innerHTML = bantop;
			}

			if (!bFound && !bIE) { 
				aTables[nTable].innerHTML += navNameTable; 
			} else if (!bFound) {
				aTables[nTable].insertAdjacentHTML("afterEnd", navNameTable + spat); 
			}
		}

	}
}

function addFavorite(sUrl,sTitle) {
	if (!sUrl) { sUrl = location.href; }
	if (!sTitle) { sTitle = document.title; }
	if (document.all) {
		window.external.AddFavorite(sUrl,sTitle);
	} else {
	    // tell them how to add a bookmark quickly (adds current page, not target page)
	    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
	}
}

function linksTopstory(aStories) {
	document.write("<div class=\"box_" +aStories.BoxStyle+ "\" style=\"width:225;\"><table width=\"225\" cellspacing=\"0\" cellpadding=\"0\" class=\"boxH_" +aStories.BoxStyle+ "\"><tr><td width=\"1%\" class=\"boxHI_" +aStories.BoxStyle+ "\">" +aStories.HeaderIcon+ "</td><td width=\"*\" nowrap=\"true\" class=\"boxHC_" +aStories.BoxStyle+ "\"><div class=\"textSmallBold\">" +aStories.appHeader.toUpperCase()+ "</div></td></tr></table><table width=\"225\" cellspacing=\"0\" cellpadding=\"0\" class=\"boxB_" +aStories.BoxStyle+ "\"><tr valign=\"top\"><td class=\"boxBI_" +aStories.BoxStyle+ "\">");
	for (i=0;i<aStories.length;i++) {
		document.write("<div class=\"textHang\" style=\"padding-bottom:3px;\"><span class=\"bulletRedSmall\">&#0149; </span><span class=\"headlineList2\"><a href=\"" +aStories[i][0]+ "\" id=\"gted\" CE=\"" +(i+1)+ "\">" +aStories[i][1]+ "</a></span></div>");
	}
	document.write("</td></tr></table></div>");
}

function linksNext(oLinks) {
	var sTmp = "<table width=\"460\" cellspacing=0 cellpadding=0 class=\"boxH_nxt\"><tr><td width=\"*\" nowrap=\"1\" class=\"boxHC_nxt\"><div class=\"textSmallBold\">" +oLinks.HeaderIcon+ "&nbsp;MORE FROM " +oLinks.appHeader.toUpperCase() + "</div></td></tr></table><table width=\"460\" cellspacing=\"0\" cellpadding=\"0\" class=\"boxB_nxt\"><tr valign=\"top\"><td><div style=\"width:100%;background-color:#ffffff;height:100%;\"><div style=\"padding:10px;width:16%;float:left;\"><a id=\"nextBtn\" onmouseover=\"SwapImage('next_links',1)\" onmouseout=\"SwapImage('next_links',0)\" href=\"" +oLinks[0][0]+ "\"><img src=\"http://media.msnbc.msn.com/i/msnbc/Components/Art/SITEWIDE/buttons/Next_arrow.gif\" border=\"0\" width=\"57\" height=\"18\" id=\"next_links\"></a></div><span id=\"nextText\" class=\"textMedBlackBold\" style=\"width:84%;padding:10px;\">"+oLinks[0][1]+"</span></div></td></tr><tr valign=\"top\"><td class=\"boxBI_nxt\">";

	for (i=0;i<oLinks.length;i++) {

		sTmp += "<div style=\"width:100%;height:16;\" id=\"" + oLinks[i][0] + "\"><div style=\"float:left;width:25;height:100%;\"></div><div class=\"textHang\"><span class=\"bulletRedSmall\">&#0149; </span><span class=\"headlineList2\"><a class=\"linkBlack\" href=\"" + oLinks[i][0] + "\" id=\"" + oLinks[i][1] + "href\">" + oLinks[i][1] + "</a></span></div></div>";

	}

	sTmp += "</td></tr></table>";
	document.write(sTmp);
}

