

//MM pre-defined scripts
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//image preloader. to preload these and more:
function preloadSiteImages() {
	// call the existing MM_preloadImages() function to preload all of our 'on' state nav images
	MM_preloadImages('/img/nav/thepaper_on.gif','/img/nav/thedaily_on.gif','/img/nav/theforum_on.gif','/img/nav/theguide_on.gif','/img/nav/movies_on.gif','/img/nav/music_on.gif','/img/nav/eats_on.gif','/img/nav/arts_on.gif','/img/nav/classifieds_on.gif','/img/nav/madtools_on.gif');
	MM_preloadImages('/img/searchWidget/movies_on.gif','/img/searchWidget/eats_on.gif','/img/searchWidget/music_on.gif');
}

//default swaping function. this will set up the navigation and sub navigation on each page with values passed to it
function swapDefaultNav(page,sub_page) {
	if(!sub_page) { //if we are on a landing page, don't show sub nav
		//swap to blank
		swapLayers();
	} else {
		//show right subnav
		swapLayers(page);
	}
	//global variables 
	thisPage = page;
	thisSubPage = sub_page;

}

//layer swaping scripts
var cur_lyr;	// holds id of currently visible layer
function swapLayers(id) {
  if ("subnav_"+cur_lyr) hideLayer("subnav_"+cur_lyr);
  showLayer("subnav_"+id);
  cur_lyr = id;
}
//shows layer, function used in swapLayers
function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
  
  activeLayer = "subnav_"+id;
}
//hides layer, used in swapLayers
function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}
//used in showLayer and hideLayer
function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

//timer script for main navigation
/* set up initial values */
var	timerID = null
var	timerRunning = false

/* this is an onmouseover function that kills the timer when you rollover a link */
function stopClock() {
	if(timerRunning)
		clearTimeout(timerID)
		timerRunning = false
}

/* this is executed after the timer is initiated and if it's not killed. this sets the nav back to its default state */
function checkStatus() {
	if(timerRunning==true) {
		//then take it back to where it was
		//document.timerForm.timerField.value = "back to default";
		swapDefaultNav(thisPage,thisSubPage);
	}
}

/* this is the timer. 1.5 seconds currently runs before it checks the status to see where the user is */
function startClock(){
	timerID = setTimeout("checkStatus()",1000);
	timerRunning = true;
}


/* WIDGET BACKGROUND COLOR CHANGE */
/* replaced with better function
function setColor(id,color) {
	var c = document.getElementById ? document.getElementById(id) : 
	document.all ?  document.all[id] :
	document.layers ? document[id+'Outer'].document[id+'inner'] : null;
	if(document.layers) {
		c.bgColor = color;
	} else {
		c.style.backgroundColor = color;
	}
}
*/
// toggle visibility for product detail image swaping
//for sub links on the left navigation
function swapImage( targetId,numb ){
  if (document.getElementById){
  		//first shut all off. 
		for(i=1;i<=numb;i++) {
			target = document.getElementById( "prodImg"+i );
			target.style.display = "none";
			//control thumbs
			thumb = document.getElementById( "prodImg"+i+"thumb" );
			//if(thumb.src == 'img/us/products/detail_thumbassets/box.active.gif') {
				thumb.src='img/us/products/detail_thumbassets/box.inactive.gif';
			//}
		}
		//now turn on just the one selected
		target = document.getElementById( "prodImg"+targetId );
		thumb = document.getElementById( "prodImg"+targetId+"thumb" );
		//alert(thumb.src);
		//there's an ie bug here... the alert box actually fixes it, so i'm assuming it's triggering too fast
		thumb.src='img/us/products/detail_thumbassets/box.active.gif';
  			if (target.style.display == "none"){
				target.style.display = "";
  			} else {
				target.style.display = "none";
  			}

  	}
}
// end toggle visibility

// Pop-up routine
function utilPop(myPage) {
	var myWin;
	myWin = window.open(myPage, "Utility", "width=625,height=525,scrollbars=0,resizable=0");
	myWin.focus();
}
