window.onerror = this.stopError;
//-------------------------------------
function stopError() {
//-------------------------------------
  return true;
}

// QUERYSTRING
//-------------------
function PageQuery(q) {
//-------------------	
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }	
}
//-------------------
function qString(key){
//-------------------
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
//-------------------
function displayItem(key){
//-------------------
	if(qString(key)=='false')
	{return null;}
	else{return(qString(key));}}
	
// HASHTABLE	
//-------------------
function Hashtable(){
//-------------------
    this.containsKey = hashtable_containsKey;
    this.get = hashtable_get;
    this.put = hashtable_put;
    this.values = hashtable_values;
    this.hashtable = new Array();
}
//-------------------
function hashtable_containsKey(key){
//-------------------
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}
//-------------------
function hashtable_get(key){
//-------------------
    return this.hashtable[key];
}
function hashtable_put(key, value){
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}
//-------------------
function hashtable_values(){
//-------------------
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            values.push(this.hashtable[i]);
    }
    return values;
}

  // SPECIAL CASES FOR UNIQUE PAGES REFERENCED IN DIFFERENT MENUS
  var spcHash  = new Hashtable();  
  spcHash.put('NEWS10',0);
 
  // VALUES REPRESENT SAXO CATEGORIES
  var accHash  = new Hashtable();  
  accHash.put('NEWS',0);
  accHash.put('SPORTS',1);  
  accHash.put('ENTERTAINMENT',2);
  accHash.put('OPINION',3);
  accHash.put('MEDIA',4);
  accHash.put('MILESTONES',5);
  accHash.put('MARKETPLACE',6);  
  accHash.put('YOURTOWN',7);  
  accHash.put('SPECTRUM',8);    
  accHash.put('FEATURES',9);  
  accHash.put('TOPICS',10);  
  accHash.put('BLOGS',11);    
 
  // VALUES FLYOUT MENUS - ID OF FLYOUT DIV
  var flyHash  = new Hashtable();  
  flyHash.put(0,'flySub0');
  flyHash.put(1,'flySub1');  
  flyHash.put(2,'flySub2');
  flyHash.put(3,'flySub3');
  flyHash.put(4,'flySub4');
  flyHash.put(5,'flySub5');
  flyHash.put(6,'flySub6');
  flyHash.put(7,'flySub7');
  flyHash.put(8,'flySub8');  
  flyHash.put(9,'flySub9'); 
  flyHash.put(10,'flySub10');   
  flyHash.put(11,'flySub11');   
  
//-------------------
function lib_bwcheck(){ 
//-------------------
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;	
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
  this.ieAll=(this.ie7 || this.ie6 || this.ie5 || this.ie4)
  this.nsAll=(this.ns4 || this.ns6)
	return this;
}
    // ACCORDION
    var libCheck = new lib_bwcheck()
    FoldNumber = 12         // 0 - 10			    
    var stayFolded = false			    
    mainOffsetY = 0
    var topLvlBg = "bluBack2";
    var openMenu = 13;	   // FoldNumber + 1
    	
    // FLYOUT
    var activeSub=0;
    var SubNum=0;    
    visibleVar="block";
		var timerID = null;
		var timerOn = false;
		var timecount = 1000;
		var what = null;
/*******************************************************************************   
*    Original: J-e-s-s-e-t-t.com
*    Modified by : Eric Bonito - Ottaway Newspapers : 02/20/2006
********************************************************************************/
function strtMenu(){   
      if (libCheck.ns4) 
      {                 // N4
	      layerRef="document.layers";
	      styleSwitch="";
				screenSize = window.innerWidth;
				what ="ns4";}
			else if(libCheck.ieAll){// IE
	      layerRef="document.all";
	      styleSwitch=".style";
				screenSize = document.body.clientWidth + 18;
				what ="ie";
		  }else if(libCheck.dom){  // N6
	      layerRef="document.getElementByID";
	      styleSwitch=".style";                        
				what="moz";		 
		  }else{                   // OLD BROWSER		  	
			return;
		  }		   
		window.status='NewstimesLIVE.com';
} 
/**********************************************************************************   
FoldoutMenu 
*   Copyright (C) 2001 <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli - DHTMLCentral.com</a>
*   Made by <a href="/dhtmlcentral/thomas_brattli.asp">Thomas Brattli</a> 
*   Modified by : Eric Bonito - Ottaway Newspapers, Inc   : 02/13/2006
***********************************************************************************/   
var px = libCheck.ns4||window.opera?"":"px";
if(navigator.userAgent.indexOf('Opera')>-1 && document.getElementById){ //Opera 5 resize fix.
	scrX= innerWidth; scrY= innerHeight;
	document.onmousemove= function(){
		if(scrX<innerWidth-10 || scrY<innerHeight-10 || scrX>innerWidth+10 || scrY>innerHeight+10){
			scrX = innerWidth;
			scrY = innerHeight;
			initFoldout();
		}
	};
}
//-------------------
function makeMenu(obj,nest){
//-------------------
	nest= (!nest)?"":'document.'+nest+'.';
	this.el= libCheck.ie4?document.all[obj]:libCheck.ns4?eval(nest+'document.'+obj):document.getElementById(obj);	
  this.css= libCheck.ns4?this.el:this.el.style;
	this.ref= libCheck.ns4?this.el.document:document;		
	this.x= (libCheck.ns4||libCheck.opera5)?this.css.left:this.el.offsetLeft;
	this.y= (libCheck.ns4||libCheck.opera5)?this.css.top:this.el.offsetTop;
	this.h= (libCheck.ie||libCheck.ns6)?this.el.offsetHeight:libCheck.ns4?this.ref.height:libCheck.opera5?this.css.pixelHeight:0;
  this.vis= b_vis;
	this.hideIt= b_hideIt;
  this.showIt= b_showIt;
  this.moveIt= b_moveIt;
	return this
}
function b_showIt(){this.css.display='inline'}
function b_hideIt(){this.css.display='none'}
function b_vis(){if(this.css.display=='none' || this.css.display=='NONE' || this.css.display=='none') return true;}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x+px; this.css.top=this.y+px}

//-------------------
function menu(num){
//-------------------
	if(libCheck.bw){	
		if (!stayFolded){
			for (var i=0; i<oSub.length; i++){
				if (i!=num){
					oSub[i].hideIt()					
				}
			}
			for(var i=1; i<oTop.length; i++){
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h)				
			}
		}
		if (oSub[num].vis()){				
	// CHANGE CSS OF TOP LEVEL ITEM
			document.getElementById('divTop'+num).className = topLvlBg; 
			oSub[num].showIt()
		}else{
			oSub[num].hideIt()
		}
		for(var i=1; i<oTop.length; i++){ 
			if (!oSub[i-1].vis()) oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+oSub[i-1].h+mainOffsetY) 
			else oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].h+mainOffsetY)
		}		
	}
	// UPDATE GLOBAL VAR WITH VALUE OF OPEN MENU
	openMenu = 'divSub'+num;
}
//-------------------
function initFoldout(cat){
//-------------------
  // INIT FLYOUT
  this.strtMenu();    

	libCheck.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
	if (libCheck.opera5) libCheck.ns6 = 0

	oTop = new Array()
	oSub = new Array()
	for (var i=0; i<FoldNumber; i++){
		oTop[i] = new makeMenu('divTop'+i,'sideBox')
		oSub[i] = new makeMenu('divSub'+i,'sideBox.document.divTop'+i)
		oSub[i].hideIt();		
	}	
	oTop[0].moveIt(0,0)
	for (var i=1; i<oTop.length; i++){
		oTop[i].moveIt(0, oTop[i-1].y+oTop[i-1].h+mainOffsetY)
	}	
	oCont = new makeMenu('sideBox')
	oCont.showIt()
	
	// OPEN MENU ONLOAD
	if (accHash.containsKey(cat)){		
		 // 7 DAY ARCHIVE CHECK
		 if(spcHash.containsKey(displayItem('Category')))
		 {
		   var str = document.referrer
		   if(str.match("NEWS")){
	 	 		  menu(parseInt(accHash.get('NEWS')));}	
	 	  	else {
		 		menu(parseInt(accHash.get('SPORTS')));}				
		 }
		 else
		 {
		 	 menu(parseInt(accHash.get(cat)));
		 }
	}
	else  // CLOSE ALL MENUS IF "HOME" IS SELECTED
  {
	   for (var i=0; i<FoldNumber; i++){
		    oSub[i].hideIt()
	   }	    
  }
} 
//-------------------  
function showLayer(layerName,AccName){
//-------------------
            if(libCheck.bw){        	
       		    if (what =="none"){
        			return;
        			}
	        	if (what == "moz"){
	        	    hideAll(); 	        	    
	        	    if(openMenu!=AccName){
        			   document.getElementById(layerName).style.display="block";        			
        			}
        			    stopTime();
        			}
        		else{
        		  hideAll(); 
        		  if(openMenu!=AccName){
                    eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="block"');
                  }
                  stopTime();
                  }
		    }
        	else // PAGE STILL LOADING
        	{    
        	return;
        	}
		}
//-------------------		
function hideLayer(layerName){
//-------------------
if(libCheck.bw)
 {
    if (what =="none")
    {
    	return;
    }
    else if (what == "moz"){
    	document.getElementById(layerName).style.display="none";
    }
    else
    {
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="none"');
	  }        
 }
 else 
 {    // PAGE STILL LOADING
   return;
 }
}
//-------------------
function hideAll(){
//-------------------
	          hideLayer(flyHash.get(0));
            hideLayer(flyHash.get(1));
			hideLayer(flyHash.get(2));
			hideLayer(flyHash.get(3));
			hideLayer(flyHash.get(4));
			hideLayer(flyHash.get(5));
			hideLayer(flyHash.get(6));
			hideLayer(flyHash.get(7));
			hideLayer(flyHash.get(8));
			hideLayer(flyHash.get(9));
			hideLayer(flyHash.get(10));
			hideLayer(flyHash.get(11));
}
//-------------------
function startTime() {
//-------------------
        if (timerOn == false) {
                timerID=setTimeout( "hideAll()" , timecount);
                timerOn = true;
	        }
}
//-------------------
function stopTime() {
//-------------------
        if (timerOn) {
    	        clearTimeout(timerID);
                timerID = null;
                timerOn = false;
        }
}
