<!--
/*  Javascript
    NEWS SUBSET COMMON
	
	index ->	
			support checking
			show/hide divs
			left navigation right border
			masthead box component
			classifieds box
			cookies
			lead story resize
*/


/* ----- =support checking ----- */
/* ---------------------------- */

// detect browser support for getElementById and createElement

var canGetElem = false;
var canCreateElem = false;

if (document.getElementById) {
    canGetElem = true;
    if (document.createElement) {
        canCreateElem = true;
    }
}

var userWidth;
var docLoaded = false;
var scrollaExist = false;
var criticalRes = 925;

// resolution above which large widths are used
function doOnLoad() {
    docLoaded = true;
	// initialise scrollamatic for pages that have one
    if (currentPage.substring(0, 15) == "ninews_homepage" || currentPage == "niclassifieds_homepage" || currentPage == "ninews_multimedia") {
		// and flag that a scrollamatic exists
        scrollaExist = true;
        initScrollers();
    }
    randomPaper(); 				// masthead paper box
    rotateWeather(0); 			// weather box rotation
	setLeftnavLineLength(); 	// left nav right border length
}

function getElementsByClassName(clss, prnt, tg) {
    var elements = new Array();
    tg = tg || '*';
    prnt = prnt || document;
    var list = prnt.getElementsByTagName(tg);
    for (var i = 0; i < list.length; ++i) {
        if (list[i].className == clss) {
            elements.push(list[i]);
        }
    }
	return elements;
}

function findPosY(obj) {
    /* Find Position script by:
       Peter-Paul Koch
       http://www.quirksmode.org */
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
        }
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
    /* end Find Position script */
}


/* ---- =show / hide divs ---- */
/* --------------------------- */

/* generic function for hiding / showing divs with links
   currently used on 	-> Home Page (breaking news box)
						-> Business Section (market update tabs)					
*/

function hasParent(e, id) {
	if (!e.parentNode) return false;
	if (e.parentNode.id == id) return e.parentNode;
	return hasParent(e.parentNode, id);
}

function showBNDiv(e) { // show divs and active tab for each section
  var eNews = hasParent(e, 'showHide');
  
  if (eNews) {
    eNews.className = e.id;
	}
}


/* ---- =left navigation right border ---- */
/* --------------------------------------- */

function setLeftnavLineLength() {
    if (canGetElem&&document.getElementById("contentWrap")) {
		// find height of middle content or height of right column, whichever is taller
        tmpHeight = Math.max(document.getElementById("contentWrap").offsetHeight, document.getElementById("rightnav").offsetHeight);
		if (document.getElementById("leaderboardAd") && (userWidth > criticalRes)) {
            tmpHeight += document.getElementById("leaderboardAd").offsetHeight;
            tmpHeight += 10;
        }
        
		currentLeftNavHeight = document.getElementById("leftnavPrimary").offsetHeight;
		
        // tmpHeight += "px";
		
		// If left nav isn't already taller
		if(tmpHeight > currentLeftNavHeight) {
		    // set height of leftnav to height determined above
            document.getElementById("leftnavPrimary").style.height = tmpHeight+"px";
		}
    }
}


/* ---- =masthead box component ---- */
/* --------------------------------- */

var paperLink;
var theSelect;

function loadPaperImage(theSelect) {
	pictmp = new Image(126,178);
	pictmp.src = metaPaper[theSelect.value][2];
	document.images["paperPlace"].src = eval("pictmp" + ".src");
	paperLink=metaPaper[theSelect.value][0];
}

function papersLink(dest) {
	ptmp = document.papersDrop.papersDropSelect.options[document.papersDrop.papersDropSelect.selectedIndex];
	if (dest=="site") {
	window.location=paperLink;
	}
	if (dest=="delivery") {
	window.location=metaPaper[ptmp.value][1];
	}
}

function randomPaper() {
	var randomPaper=Math.floor(Math.random()*metaPaper.length) // no. of papers
	document.papersDrop.papersDropSelect.selectedIndex=randomPaper;
	ptmp = document.papersDrop.papersDropSelect.options[document.papersDrop.papersDropSelect.selectedIndex];
	paperLink = ptmp.value;
	loadPaperImage(ptmp);
}


/* ----- =classifieds box ---- */
/* --------------------------- */

function clearTabs() {
    if (canGetElem) {
    
        // clear all blue color tabs during div changes
    	document.getElementById("jobsActive").style.display = "none";
        document.getElementById("carsActive").style.display = "none";
    	document.getElementById("matchActive").style.display = "none";
		document.getElementById("localActive").style.display = "none";
        
    }
}

function clearDivs() {
    if (canGetElem) {
    
        // clear all divs on page refresh / load
    	document.getElementById("jobs").style.display = "none";
        document.getElementById("cars").style.display = "none";
    	document.getElementById("match").style.display = "none";
		document.getElementById("local").style.display = "none";
        
    }
}
	
function show_div(id) {
    if (canGetElem) {
    
        // show divs and active tab for each section
    	clearDivs();
        document.getElementById(id).style.display = "block";
            // turns on active div content layer
    	clearTabs();
    	document.getElementById(id + "Active").style.display = "block";
            // turns on active tab div layer

    }
}

function randomDiv() { 
   // choose random id for classified tabs.
   var whichDiv = Math.floor(Math.random()*2);   
   var div = new Array(3)
   div[0]="jobs";
   div[1]="cars";
   div[2]="match";
   // apply random id on refresh   
   show_div((div[whichDiv]));
}

	
//-->
