function OpenFlash(flashfile, width, height) {document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='" + width + "' height='" + height + "'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='movie' value='" + flashfile + "' /><param name='loop' value='false' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='bgcolor' value='#ffffff' /><embed src='" + flashfile + "' loop='false' quality='high' wmode='transparent' bgcolor='#ffffff' width='" + width + "' height='" + height + "' name='Test' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>"); }
function OpenOmnitureFlash(VideoID,PlayerID,Width,Height,AdServer,AutoStart) {	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='" + Width + "' height='" + Height + "' id='omniturePlayer' align='middle'><param name='allowScriptAccess' value='always' /><param name='movie' value='http://www.slate.com/video/omniturePlayer.swf?actionSourcePath=http://www.slate.com/video/&adServerURL=" + AdServer + "&videoId=" + VideoID + "&videoRef=null&lineupId=null&playerTag=null&autoStart=" + AutoStart + "&pwidth=" + Width + "&pheight=" + Height + "&playerId=" + PlayerID + "&flashId=omniturePlayer' /><param name='quality' value='high' /><param name='bgcolor' value='#FFFFFF' /><embed src='http://www.slate.com/video/omniturePlayer.swf?actionSourcePath=http://www.slate.com/video/&adServerURL=" + AdServer + "&videoId=" + VideoID + "&videoRef=null&lineupId=null&playerTag=null&autoStart=" + AutoStart + "&pwidth=" + Width + "&pheight=" + Height + "&playerId=" + PlayerID + "&flashId=omniturePlayer' quality='high' bgcolor='#FFFFFF' width='" + Width + "' height='" + Height + "' name='omniturePlayer' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>"); 
}
function insertAudioPlayer(soundfile, extFile) { document.write('<object width="244" height="46" align="middle" id="audioplayer" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="sameDomain" name="allowScriptAccess"></param><param value="http://www.slate.com/apps/audioplayer.swf?soundfile='+soundfile+'&externalFile='+extFile+'" name="movie"></param><param value="high" name="quality"></param><param value="#ffffff" name="bgcolor"></param><embed width="244" height="46" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" name="audioplayer" bgcolor="#ffffff" quality="high" src="http://www.slate.com/apps/audioplayer.swf?soundfile='+soundfile+'&externalFile='+extFile+'"></embed></object>') 
}
function OpenSurroundVideo(file, width, height, filepath){if (width == null || width == "")width="320"; if (height==null || height =="")height="240";  myvideo = "<object classid='clsid:928626A3-6B98-11CF-90B4-00AA00A4011F' type='application/x-oleobject' id='Surround1'" + " codebase='" + filepath+ "apps/svj/MSSurVid.cab#Version=1,2,0,20' width='" +width + "' height='" + height + "'>" + "<param name='SurroundRect' value='0,0,320,240' /><param name='Image' value='"+file+"'></param></object>";  document.write(myvideo); 
}
function OpenWindowsMedia(file){document.write("<embed type='application/x-mplayer2' name='MediaPlayer' autostart='true'  src='" + file + "'></embed>"); 
}
function OpenQuickTime(file, width, height){document.write("<embed PLUGINSPAGE='http:/" + "/www.apple.com/quicktime/download/' src='"+ file +"' width='"+width+"' height='"+height+"'></embed>"); }

// Above are functions for activex components

function SlatePopup(div) { var win = window.open("","win","directories=no,height=400,width=550,menubar=no,resizeable=no,scrollbars=no,status=no,toolbar=no"); win.document.write("<html><head><title>Slate Popup</title><link rel=\"stylesheet\" type=\"text/css\" href=\"/css/popups.css\" /></head><body></body></html>"); win.document.body.innerHTML = div.innerHTML; win.document.close(); win.focus(); return;
}
function toolAction(action, id, tocid) {var title; var windowParam; if (id==''){var url = window.location.href; var idPos = url.indexOf("id="); if (idPos != -1){var ampPos = url.indexOf("&"); if (ampPos != -1)id = url.substring(idPos+3,ampPos); else id = url.substr(idPos+3); }}var URLParam = "?action="+action+"&id="+id; if (id=='toc')URLParam += "&tocid="+tocid; switch (action) {case 'print':title=''; windowParam = 'toolbar=no,location=no,directories=no,menubar=yes,status=no,resizable=yes,scrollbars=yes,width=640,height=480,'; window.open("/toolbar.aspx"+URLParam, title, windowParam); break; case 'email':title='Email'; windowParam = 'toolbar=no,location=no,directories=no,menubar=no,status=no,resizable=yes,scrollbars=no,width=490,height=470'; window.open("/toolbar.aspx"+URLParam, title, windowParam); break; }
}
function showHideSidebar(){if(document.all)var iWidth = document.body.clientWidth; document.all.sidebarshell.style.display = (iWidth > 913 ? '' : 'none'); document.all.sidebarshell.style.height = document.body.scrollHeight - 1; 
}
function LoadIframe(el){var n = el.name; var h = document.frames(n).document.body.scrollHeight; el.height = h; window.focus(); 
}
// Used for most read, e-mailed
function clearMostTabs() {
	for(k=1;k<=2;k++) {
		document.getElementById("most_link"+k).className="mostread_inactive";		document.getElementById("most_read_"+k).style.display="none";	
	} 
}
function selectMostTab(id) {
	clearMostTabs();	
	document.getElementById("most_link"+id).className="mostread_active";	document.getElementById("most_read_"+id).style.display="block"; 
}
// Image preload script
var myimages=new Array(); function preloadimages() {  for (i=0;i<preloadimages.arguments.length;i++)  {    myimages[i]=new Image();    myimages[i].src=preloadimages.arguments[i];  } } preloadimages("http://img.slate.com/images/redesign2008/slate_logo.gif","http://img.slate.com/images/redesign2008/flyoutnotch.gif","http://img.slate.com/images/redesign2008/left_WhiteMaroon.gif","http://img.slate.com/images/redesign2008/left_MaroonMaroon.gif","http://img.slate.com/images/redesign2008/left_MaroonWhite.gif","http://img.slate.com/images/redesign2008/middle_WhiteMaroon.gif","http://img.slate.com/images/redesign2008/middle_MaroonWhite.gif","http://img.slate.com/images/redesign2008/middle_MaroonMaroon.gif","http://img.slate.com/images/redesign2008/right_MaroonWhite.gif","http://img.slate.com/images/redesign2008/right_WhiteWhite.gif");
// Flyout menus
var ActiveMenu = null;
var closeMenu;
var recIsOpen = false;
function showMenu(menuNum) {	clearTimeout(closeMenu);	var whichMenu = parseInt(menuNum);	if (ActiveMenu != null) {	hideMenu(); 	}	if (readCookie("slateflyout") != "off") { document.getElementById("flyout_container").innerHTML = flyoutArray[whichMenu - 1]; document.getElementById("flyout_container").style.display = "block"; } 	var highlightLink = document.getElementById("menuF" + whichMenu);	highlightLink.style.color="#FF0";	ActiveMenu = whichMenu; }
function hideMenu() {
	document.getElementById("flyout_container").style.display="none"; var highlightLink = document.getElementById("menuF" + ActiveMenu); highlightLink.style.color="#FFF"; ActiveMenu = null;}
	
// Turn off flyouts
function flyoutTurnoff() { var date = new Date(); date.setTime(date.getTime()+(10000*24*60*60*1000)); document.cookie = "slateflyout=off; expires=" + date.toGMTString() + "; path=/"; window.location.reload(); }
function flyoutTurnon() { var date = new Date(); date.setTime(date.getTime()+(-1*24*60*60*1000)); document.cookie = "slateflyout=off; expires=" + date.toGMTString() + "; path=/"; window.location.reload(); }
function flyoutSwitch() { if (readCookie("slateflyout") != "off") { document.write("<div class='flyout_toggler'><a class='flyout_switch' href='javascript:flyoutTurnoff()'>Disable Flyout</a><a href='http://www.slate.com/id/2147826/'><img src='http://www.slate.com/images/redesign/disableflyout_infocircle.gif' width='13' height='13' alt='What does disabling the flyout do?' /></a></div>"); } else { document.write("<div class='flyout_toggler'><a class='flyout_switch' href='javascript:flyoutTurnon()'>Enable Flyout</a><a href='http://www.slate.com/id/2147826/'><img src='http://www.slate.com/images/redesign/disableflyout_infocircle.gif' width='13' height='13' alt='What does disabling the flyout do?' /></a></div>"); } }
function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }

// Open "recommend" link
function ToolbarRecommend(whichRec) {
	if (recIsOpen == false) {		document.getElementById(whichRec).style.display="block";		recIsOpen = true;	} else {		document.getElementById(whichRec).style.display="none";		recIsOpen = false;	}
}
function closeRec(whichRec) {
	document.getElementById(whichRec).style.display="none";	recIsOpen = false;
}

// Toolbar mouseover
function ToolbarMouseOver(whichMenu, rootpath) {
	var navImage = whichMenu + "_icon";	var navAnchor = whichMenu + "_link";	document.images[navImage].src = (rootpath + "images/toolbox_images/" + whichMenu + "_roll.gif");	document.getElementById(navAnchor).style.color = "#FF0";}
function ToolbarMouseOut(whichMenu, rootpath) {
	var navImage = whichMenu + "_icon";	var navAnchor = whichMenu + "_link";	document.images[navImage].src = (rootpath + "images/toolbox_images/" + whichMenu + ".gif");
	document.getElementById(navAnchor).style.color = "#FFF";}
	
// Multipart navigation functions
var MultipartHeadlines = new Array();	var CurrentEntry = null;
function PopulateMultipartArray(ArrayIndex, Headline, FromByline, ToByline, PubDate, thisHeadline) {	var whichElement = parseInt(ArrayIndex);		MultipartHeadlines[whichElement] = [Headline,FromByline,ToByline,PubDate];	if (thisHeadline == '1')		CurrentEntry = whichElement;} function MultipartMouseOver(whichSwap, TopBottomSwitch) {	whichElement = parseInt(whichSwap);	TopOrBottom = "multipart" + TopBottomSwitch;	if (MultipartHeadlines[whichElement][2] == 'null') {	document.getElementById(TopOrBottom).innerHTML = ("<h2>" + MultipartHeadlines[whichElement][0] + "</h2><span class='multipart_byline'>" + MultipartHeadlines[whichElement][1] + "</span><span class='multipart_date'>Posted " + MultipartHeadlines[whichElement][3] + "</span>");	} else {		document.getElementById(TopOrBottom).innerHTML = ("<h2>" + MultipartHeadlines[whichElement][0] + "</h2><span class='multipart_byline'>" + MultipartHeadlines[whichElement][1] + "<br />" + MultipartHeadlines[whichElement][2] + "</span><span class='multipart_date'>Posted " + MultipartHeadlines[whichElement][3] + "</span>");	}}
function MultipartMouseOut(TopBottomSwitch) {	TopOrBottom = "multipart" + TopBottomSwitch;	if (MultipartHeadlines[CurrentEntry][2] == 'null') {	document.getElementById(TopOrBottom).innerHTML = ("<h2>" + MultipartHeadlines[CurrentEntry][0] + "</h2><span class='multipart_byline'>" + MultipartHeadlines[CurrentEntry][1] + "</span><span class='multipart_date'>Posted " + MultipartHeadlines[CurrentEntry][3] + "</span>");	} else {		document.getElementById(TopOrBottom).innerHTML = ("<h2>" + MultipartHeadlines[CurrentEntry][0] + "</h2><span class='multipart_byline'>" + MultipartHeadlines[CurrentEntry][1] + "<br />" + MultipartHeadlines[CurrentEntry][2] + "</span><span class='multipart_date'>Posted " + MultipartHeadlines[CurrentEntry][3] + "</span>");	} }

var tapThreeIndex = 4;
var tapOneIndex = 1;
var mediaPlayerOpen = 0;
var tapThreeArray = new Array();
var todaysMediaRandomVar = Math.floor(Math.random() * 5) + 1;

function randomizeTopPromo(promoCount) {
	var whichPromo = Math.floor(Math.random() * promoCount) + 1;
	document.getElementById("toc_top_promo_1").style.display = "none";
	document.getElementById("toc_top_promo_" + whichPromo).style.display = "block";
}

function changeTapOne(showImage) {
	if (tapOneIndex != showImage) {
		document.getElementById("tap1_" + tapOneIndex).style.display = "none";
		document.getElementById("tap1_" + showImage).style.display = "block";
		// Change the appropriate navigation to maroon
		if (showImage == 1) {
			document.getElementById("tap1_control_1").className = "tap1_left_whitemaroon";
		} else if (showImage == tapOneCount) {
			document.getElementById("tap1_control_" + showImage).className = "tap1_rt_whitewhite";
			if (showImage > 2) {
				document.getElementById("tap1_control_" + (showImage - 1)).className = "tap1_mid_maroonwhite";
			}
		} else {
			document.getElementById("tap1_control_" + showImage).className = "tap1_mid_whitemaroon";
		}
		// Change others to gray
		if (showImage == 1) {
			if (tapOneIndex == tapOneCount) {
				document.getElementById("tap1_control_" + tapOneIndex).className = "tap1_rt_maroonwhite";
				if (tapOneCount > 2)
					document.getElementById("tap1_control_" + (tapOneIndex - 1)).className = "tap1_mid_mar";
			} else if ((tapOneIndex > 1) && (tapOneIndex < tapOneCount)) {
				document.getElementById("tap1_control_" + tapOneIndex).className = "tap1_mid_mar";
				if (tapOneIndex > 2) { document.getElementById("tap1_control_" + (tapOneIndex - 1)).className = "tap1_mid_mar"; }
			}
		} else if (showImage == 2) {
			document.getElementById("tap1_control_1").className = "tap1_left_maroonwhite";
			if (tapOneIndex == tapOneCount) {
				document.getElementById("tap1_control_" + tapOneIndex).className = "tap1_rt_maroonwhite";
			} else if ((tapOneIndex > 3) && (tapOneIndex < tapOneCount)) {
				document.getElementById("tap1_control_" + tapOneIndex).className = "tap1_mid_mar";
				document.getElementById("tap1_control_" + (tapOneIndex - 1)).className = "tap1_mid_mar";
			}
		} else {
			document.getElementById("tap1_control_1").className = "tap1_left_marmar";
			if ((tapOneIndex < tapOneCount) && (tapOneIndex > 1)) {
				document.getElementById("tap1_control_" + tapOneIndex).className = "tap1_mid_mar";
			} else if (tapOneIndex == tapOneCount) {
				document.getElementById("tap1_control_" + tapOneIndex).className = "tap1_rt_whitewhite";
			}
			document.getElementById("tap1_control_" + (showImage - 1)).className = "tap1_mid_maroonwhite";
		}
		tapOneIndex = showImage;
	}
}
function populateTapThree() {
	var i;
	for (i=0;i<tapThreeCount;i++) {
		tapThreeArray[i] = document.getElementById("tap3_" + (i+1)).innerHTML;
	}
}
function moveTapThree(whichWay) {
	var i;
	var j;
	if (whichWay == 'right') {
		if (tapThreeIndex == tapThreeCount) {
			j = 0;
		} else {
			j = tapThreeIndex;
		}
		for (i=1;i<5;i++) {
			document.getElementById("tap3_" + i).innerHTML = tapThreeArray[j];
			j++;
		}
		if (tapThreeIndex == tapThreeCount) {
			tapThreeIndex = 4;
		} else {
			tapThreeIndex += 4;
		}
	}
	else {
		if (tapThreeIndex == 4) {
			j = tapThreeCount - 1;
		} else {
			j = tapThreeIndex - 5;
		}
		for (i=4;i>0;i--) {
			document.getElementById("tap3_" + i).innerHTML = tapThreeArray[j];
			j--;
		}
		if (tapThreeIndex == 4) {
			tapThreeIndex = tapThreeCount;
		} else {
			tapThreeIndex -= 4;
		}
	}
}
function showDaysArticles(whichUL) {
	var ULswitcher = document.getElementById("day" + whichUL);
	var arrowSwitcher = document.getElementById("day_arrow_" + whichUL);
	if (ULswitcher.style.display == "none") {
		ULswitcher.style.display = "block";
		arrowSwitcher.src = "jsimages/daily_arrow_down.gif";
	} else {
		ULswitcher.style.display = "none";
		arrowSwitcher.src = "jsimages/daily_arrow_rt.gif";
	}
} 
function changeMediaPlayer(whichOne) {
	if (whichOne == 5)
		whichOne = 4;
	whichOne = whichOne.toString()
	if (mediaPlayerOpen != whichOne) {
		document.getElementById("toc_media_" + whichOne).style.visibility="visible";
		document.getElementById("med_" + whichOne).className="med_active";
		if (mediaPlayerOpen != 0 ) {
			document.getElementById("toc_media_" + mediaPlayerOpen).style.visibility="hidden";
			document.getElementById("med_" + mediaPlayerOpen).className="med_inactive";
		}
		mediaPlayerOpen = whichOne;
	}
}
function getTabRandom() {
	var i = "";
	var j = Math.floor(Math.random() * 4) + 1;
	switch (j) {
		case 1: i="blogroll_tab";break;
		default:i="today_tab";
	}
	return i;
}
function switchArticleContainer(whichOne) {
	document.getElementById(whichOne).className = "ab_active";
	if (whichOne == "today_tab") {
		document.getElementById("blogroll_tab").className = "ab_inactive";
		document.getElementById("blogs_container").style.display = "none";
		document.getElementById("today_in_slate").style.display = "block";
	} else {
		document.getElementById("today_tab").className = "ab_inactive";
		document.getElementById("blogs_container").style.display = "block";
		document.getElementById("today_in_slate").style.display = "none";		
	}
}
//Slate Search
  var search_input_cleared = false;
  var hidden_search_element_ids = {'slate':['slate_search_input','pageid','search_radio1','search_radio2'], 
  'ask':['ask_search_input','ask_submit_button.x','ask_submit_button.y','ask_submit_button','qsrc','ask_o','ask_l']};
  function clearSearchInput() { 
    if (!search_input_cleared) { document.getElementById('search_input').value = ''; }
    search_input_cleared = true;
  }
  function submitSearch() {
    var form = document.getElementById('slate_search');
    var active = 'slate';
    var inactive = 'ask';
    if (document.getElementById('search_radio2').checked) { active = 'ask'; inactive = 'slate'; }
    form.action = search_actions[active];
    document.getElementById(active+'_search_input').value = document.getElementById('search_input').value;
    for (var eid in hidden_search_element_ids[inactive]) {
      form.removeChild(document.getElementById(hidden_search_element_ids[inactive][eid]));
    }
    form.submit();
    return false;
  }
//End Slate Search
