NavbarItems = Array(3);
NavbarItems[0] = Array(
 Array('2',1, Array(
   Array('1',1, null,'Front page','/','','',0),
   Array('1543',1, Array(
     Array('19',1, null,'Databank','/news/categoryfront.php/id/19/Databank.html','','',0),
     Array('1192',1, null,'<i>On statistics</i>','/news/categoryfront.php/id/1192/On_statistics.html','','',0)),'Statistics','/news/categoryfront.php/id/1543/Statistics.html','','',0),
   Array('1440',1, null,'Calendar','http://www.oecd.org/document/49/0,2340,en_2649_201185_32618737_1_1_1_1,00.html','','',0),
   Array('20',1, null,'Leaders','/news/categoryfront.php/id/20/Leaders.html','','',0),
   Array('1378',1, Array(
     Array('1364',1, null,'CivSoc newsletter','/news/categoryfront.php/id/1364/CivSoc_newsletter.html','','',0),
     Array('1377',1, null,'Guest articles','/news/categoryfront.php/id/1377/Guest_articles.html','','',0)),'Civil Society','/news/categoryfront.php/id/1378/Civil_Society.html','','',0),
   Array('18',1, null,'Books','/news/categoryfront.php/id/18/Books.html','','',0),
   Array('1071',1, null,'Frankie.org','/news/categoryfront.php/id/1071/Frankie.org.html','','',0),
   Array('21',1, null,'Letters','/news/categoryfront.php/id/21/Letters.html','','',0),
   Array('4',1, null,'News','/news/categoryfront.php/id/4/News.html','','',0),
   Array('1441',1, null,'News from DC','http://www.oecdwash.org/','','',0),
   Array('586',1, Array(
     Array('16',1, null,'OECD.org','/news/categoryfront.php/id/16/OECD.org.html','','',0),
     Array('15',1, null,'Forum/Ministerial ','/news/categoryfront.php/id/15/Forum_Ministerial_.html','','',0),
     Array('1356',1, null,'Ministers\' roundtables','/news/categoryfront.php/id/1356/Ministers__roundtables.html','','',0),
     Array('1400',1, null,'Speeches','/news/categoryfront.php/id/1400/Speeches.html','','',0),
     Array('1178',1, null,'Events','http://www.oecd.org/document/49/0,2340,en_2649_201185_32618737_1_1_1_1,00.html','','',0),
     Array('1262',1, null,'People','/news/categoryfront.php/id/1262/People.html','','',0)),'OECD','/news/categoryfront.php/id/586/OECD.html','','',0),
   Array('1287',1, null,'Subscribers','/news/categoryfront.php/id/1287/Subscribers.html','','',1),
   Array('1620',1, null,'Blog','http://oecdinsights.org/','','',0)),'General                                                                    ','/news/categoryfront.php/id/2/General____________________________________________________________________.html','','',0),
 Array('574',1, Array(
   Array('6',1, Array(
     Array('591',1, null,'General','/news/categoryfront.php/id/591/General.html','','',0),
     Array('1189',1, null,'Country snapshots','/news/categoryfront.php/id/1189/Country_snapshots.html','','',0)),'Economy','/news/categoryfront.php/id/6/Economy.html','','',0),
   Array('7',1, null,'Development','/news/categoryfront.php/id/7/Development.html','','',0),
   Array('11',1, Array(
     Array('1140',1, null,'Agriculture','/news/categoryfront.php/id/1140/Agriculture.html','','',0),
     Array('1142',1, null,'Energy','/news/categoryfront.php/id/1142/Energy.html','','',0),
     Array('1141',1, null,'Environment','/news/categoryfront.php/id/1141/Environment.html','','',0),
     Array('1164',1, null,'Fisheries','/news/categoryfront.php/id/1164/Fisheries.html','','',0),
     Array('1143',1, null,'Other','/news/categoryfront.php/id/1143/Other.html','','',0),
     Array('1165',1, null,'Water','/news/categoryfront.php/id/1165/Water.html','','',0)),'Environment & resources','/news/categoryfront.php/id/11/Environment___resources.html','','',0),
   Array('55',1, Array(
     Array('8',1, null,'Governance','/news/categoryfront.php/id/8/Governance.html','','',0),
     Array('60',1, null,'Taxation','/news/categoryfront.php/id/60/Taxation.html','','',0)),'Government','/news/categoryfront.php/id/55/Government.html','','',0),
   Array('10',1, null,'Science & technology','/news/categoryfront.php/id/10/Science___technology.html','','',0),
   Array('9',1, Array(
     Array('52',1, null,'Education','/news/categoryfront.php/id/52/Education.html','','',0),
     Array('592',1, null,'General','/news/categoryfront.php/id/592/General.html','','',0),
     Array('56',1, null,'Healthcare','/news/categoryfront.php/id/56/Healthcare.html','','',0),
     Array('14',1, null,'Labour','/news/categoryfront.php/id/14/Labour.html','','',0)),'Society','/news/categoryfront.php/id/9/Society.html','','',0),
   Array('12',1, null,'Trade & investment','/news/categoryfront.php/id/12/Trade___investment.html','','',0)),'Topics','/news/categoryfront.php/id/574/Topics.html','','',0),
 Array('46',1, Array(
   Array('1419',1, null,'Climate change','/news/categoryfront.php/id/1419/Climate_change.html','','',0),
   Array('1538',1, null,'Financial crisis','/news/categoryfront.php/id/1538/Financial_crisis.html','','',0),
   Array('1372',1, Array(
     Array('1605',1, null,'Middle East-North Africa','/news/categoryfront.php/id/1605/Middle_East-North_Africa.html','','',0),
     Array('1480',1, null,'Internet Seoul 2008','/news/categoryfront.php/id/1480/Internet_Seoul_2008.html','','',0),
     Array('1460',1, null,'Transport','/news/categoryfront.php/id/1460/Transport.html','','',0),
     Array('1447',1, null,'2008 Environment Spotlight','/news/categoryfront.php/id/1447/2008_Environment_Spotlight.html','','',0),
     Array('1269',1, null,'Trust in government','/news/categoryfront.php/id/1269/Trust_in_government.html','','',0)),'Spotlights','/news/categoryfront.php/id/1372/Spotlights.html','','',0)),'Hot issues','/news/categoryfront.php/id/46/Hot_issues.html','','',0),
 Array('575',1, Array(
   Array('67',1, Array(
     Array('590',1, null,'All countries','/news/categoryfront.php/id/590/All_countries.html','','',0),
     Array('69',1, null,'Australia','/news/categoryfront.php/id/69/Australia.html','','',0),
     Array('1082',1, null,'Austria','/news/categoryfront.php/id/1082/Austria.html','','',0),
     Array('1084',1, null,'Belgium','/news/categoryfront.php/id/1084/Belgium.html','','',0),
     Array('1085',1, null,'Canada','/news/categoryfront.php/id/1085/Canada.html','','',0),
     Array('1086',1, null,'Czech Republic','/news/categoryfront.php/id/1086/Czech_Republic.html','','',0),
     Array('1087',1, null,'Denmark','/news/categoryfront.php/id/1087/Denmark.html','','',0),
     Array('1088',1, null,'Finland','/news/categoryfront.php/id/1088/Finland.html','','',0),
     Array('77',1, null,'France','/news/categoryfront.php/id/77/France.html','','',0),
     Array('78',1, null,'Germany','/news/categoryfront.php/id/78/Germany.html','','',0),
     Array('79',1, null,'Greece','/news/categoryfront.php/id/79/Greece.html','','',0),
     Array('1089',1, null,'Hungary','/news/categoryfront.php/id/1089/Hungary.html','','',0),
     Array('1090',1, null,'Iceland','/news/categoryfront.php/id/1090/Iceland.html','','',0),
     Array('82',1, null,'Ireland','/news/categoryfront.php/id/82/Ireland.html','','',0),
     Array('1091',1, null,'Italy','/news/categoryfront.php/id/1091/Italy.html','','',0),
     Array('84',1, null,'Japan','/news/categoryfront.php/id/84/Japan.html','','',0),
     Array('85',1, null,'Korea','/news/categoryfront.php/id/85/Korea.html','','',0),
     Array('1092',1, null,'Luxembourg','/news/categoryfront.php/id/1092/Luxembourg.html','','',0),
     Array('87',1, null,'Mexico','/news/categoryfront.php/id/87/Mexico.html','','',0),
     Array('1093',1, null,'Netherlands','/news/categoryfront.php/id/1093/Netherlands.html','','',0),
     Array('1094',1, null,'New Zealand','/news/categoryfront.php/id/1094/New_Zealand.html','','',0),
     Array('1095',1, null,'Norway','/news/categoryfront.php/id/1095/Norway.html','','',0),
     Array('1096',1, null,'Poland','/news/categoryfront.php/id/1096/Poland.html','','',0),
     Array('1097',1, null,'Portugal','/news/categoryfront.php/id/1097/Portugal.html','','',0),
     Array('94',1, null,'Slovak Republic','/news/categoryfront.php/id/94/Slovak_Republic.html','','',0),
     Array('95',1, null,'Spain','/news/categoryfront.php/id/95/Spain.html','','',0),
     Array('96',1, null,'Sweden','/news/categoryfront.php/id/96/Sweden.html','','',0),
     Array('1098',1, null,'Switzerland','/news/categoryfront.php/id/1098/Switzerland.html','','',0),
     Array('98',1, null,'Turkey','/news/categoryfront.php/id/98/Turkey.html','','',0),
     Array('1099',1, null,'United Kingdom','/news/categoryfront.php/id/1099/United_Kingdom.html','','',0),
     Array('100',1, null,'United States','/news/categoryfront.php/id/100/United_States.html','','',0),
     Array('1263',1, null,'OECD country sites','http://www.oecd.org/countrieslist/0,3025,en_33873108_33844430_1_1_1_1_1,00.html','','',0)),'OECD','/news/categoryfront.php/id/67/OECD.html','','',0),
   Array('584',1, Array(
     Array('62',1, null,'Africa','/news/categoryfront.php/id/62/Africa.html','','',0),
     Array('63',1, null,'Asia','/news/categoryfront.php/id/63/Asia.html','','',0),
     Array('64',1, null,'Europe','/news/categoryfront.php/id/64/Europe.html','','',0),
     Array('65',1, null,'European Union','/news/categoryfront.php/id/65/European_Union.html','','',0),
     Array('66',1, null,'Middle East','/news/categoryfront.php/id/66/Middle_East.html','','',0),
     Array('68',1, null,'South America','/news/categoryfront.php/id/68/South_America.html','','',0)),'Regions','/news/categoryfront.php/id/584/Regions.html','','',0),
   Array('583',1, Array(
     Array('1083',1, null,'Brazil','/news/categoryfront.php/id/1083/Brazil.html','','',0),
     Array('1310',1, null,'Chile','/news/categoryfront.php/id/1310/Chile.html','','',0),
     Array('73',1, null,'China','/news/categoryfront.php/id/73/China.html','','',0),
     Array('1555',1, null,'Estonia','/news/categoryfront.php/id/1555/Estonia.html','','',0),
     Array('1359',1, null,'India','/news/categoryfront.php/id/1359/India.html','','',0),
     Array('1556',1, null,'Indonesia','/news/categoryfront.php/id/1556/Indonesia.html','','',0),
     Array('1416',1, null,'Israel','/news/categoryfront.php/id/1416/Israel.html','','',0),
     Array('93',1, null,'Russia','/news/categoryfront.php/id/93/Russia.html','','',0),
     Array('1412',1, null,'Slovenia','/news/categoryfront.php/id/1412/Slovenia.html','','',0),
     Array('1557',1, null,'South Africa','/news/categoryfront.php/id/1557/South_Africa.html','','',0),
     Array('1045',1, null,'Other','/news/categoryfront.php/id/1045/Other.html','','',0)),'Non-OECD','/news/categoryfront.php/id/583/Non-OECD.html','','',0),
   Array('101',1, null,'World','/news/categoryfront.php/id/101/World.html','','',0)),'Countries','/news/categoryfront.php/id/575/Countries.html','','',0),
 Array('124',1, Array(
   Array('1344',1, null,'Angel Gurría','/news/categoryfront.php/id/1344/Angel_Gurr_EDa.html','','',0)),'Writers                                                                                         ','/news/categoryfront.php/id/124/Writers_________________________________________________________________________________________.html','','',0),
 Array('1029',1, Array(
   Array('abli',1, null,'Recent articles','/news/archive_browser.php/issue/1548651600.html','','',0),
   Array('abbi',1, null,'Browse&nbsp;articles&nbsp;by&nbsp;date','/news/archive_browser.php','','',0)),'Back issues','javascript:void(0);','','',0),
 Array('1278',1, Array(
   Array('1277',1, null,'1996-99 Issues','http://www.oecdobserver.org/news/archive_browser.php/issue/849416400.html','','',0)),'','','','',0));
NavbarItems[1] = Array(
 Array('569',1, Array(
   Array('581',1, null,'Subscribe','/subscribe.html','','',0),
   Array('579',1, null,'About/Contact','/info/about_us.php','','',0),
   Array('1168',1, null,'Advertise','http://www.oecdobserver.org/news/fullstory.php/aid/1362/Advertise_with_us.html','','',0),
   Array('1279',1, null,'Français','http://www.observateurocde.org','','',0)),'','','','',0));
NavbarItems[2] = Array(
);
function getPageItem(itemid) {
    if (document.getElementById) {
    	return document.getElementById(itemid);
    } else if (document.all) {
        return document.all[itemid];
    } else if (document.layers) {
    	return eval('document.'+itemid);
    }
    return null;
}

function writePageItem(itemid,html) {
    var lyr = null;
    if (document.getElementById) {
    	lyr = document.getElementById(itemid);
	lyr.innerHTML = html;
    } else if (document.all) {
        lyr = document.all[itemid];
	lyr.innerHTML = html;
    } else if (document.layers) {
    	// FIXME: ns4 compat
    }
}

function renderNavbarItem(container, level, item) {
    var html = "" + NavbarTemplates[container][level][1];

    var ihtm = NavbarTemplates[container][level][4];
    if (item[3] == '') { 
       // is empty
       ihtm = NavbarTemplates[container][level][2]; 
    } else if (item[5] != '') {  
       // has image
       ihtm = NavbarTemplates[container][level][3]; 
    }
    if (item[2] && (NavbarTemplates[container][level].length > 5)) { 
        // has children
    	if (item[1]) {  
	    // is open
      	    ihtm = NavbarTemplates[container][level][5];
    	} else {  
	    // is closed
      	    ihtm = NavbarTemplates[container][level][6];
    	}
    }

    html = html.replace(/%%ITEM%%/g, ihtm);

    html = html.replace(/%%ID%%/g, item[0]);
    html = html.replace(/%%TEXT%%/g, item[3]);
    html = html.replace(/%%LINK%%/g, item[4]);
    html = html.replace(/%%IMG_URL%%/g, item[5]);
    if (item[7] && PadlockTemplate) {
      html = html.replace(/%%PADLOCK%%/g, PadlockTemplate);
    } else {
      html = html.replace(/%%PADLOCK%%/g, '');
    }
    if (item[2] && item[1]) {  
	html = html.replace(/%%SUB%%/g, renderNavbarLevel(container, level+1, item[2]));
    } else {
	html = html.replace(/%%SUB%%/g, '');
    }
    return html;
} 

function renderNavbarLevel(container, level, items) {
    var html = NavbarTemplates[container][level][0];
    var buf = '';
    for(var i=0;i< items.length; i++) {
    	buf += renderNavbarItem(container, level, items[i]);
    }
    html = html.replace(/%%ITEMS%%/g, buf);
    return html;
}

function renderLeftNavbar() {
    return renderNavbarLevel(0,0,NavbarItems[0]);
}

function renderTopNavbar() {
    return renderNavbarLevel(1,0,NavbarItems[1]);
}

function renderRightNavbar() {
    return renderNavbarLevel(2,0,NavbarItems[2]);
}

// behavior specific

function getCategoryId() {
    var loc = "";
    loc += document.location; 
    loc = loc.replace(/^.*\/categoryfront\.php\/id\//,'');
    loc = loc.replace(/[^0-9].*$/,'');
    return loc;
}

function initNavbar() {
    var id = getCategoryId();
    for(var c=0; c< NavbarItems.length; c++) {
      for(var i=0;i< NavbarItems[c].length; i++) {
    	var items = NavbarItems[c][i][2];
    	if (items) {
    	    for(var j=0;j< items.length; j++) {
	      NavbarItems[c][i][2][j][1] = 0;
	      var jtems = items[j][2];
	      if (jtems && id!="") {
	        if (items[j][0] == id) { NavbarItems[c][i][2][j][1] = 1; }
	        else for (var k=0; k< jtems.length; k++) {
		  if (jtems[k][0] == id) { NavbarItems[c][i][2][j][1] = 1; }
		}
	      }
	    }
	}
      }
    }
}

function toggleNavbarItem(id) {
    for(var c=0; c< NavbarItems.length; c++) {
      for(var i=0;i< NavbarItems[c].length; i++) {
    	var items = NavbarItems[c][i][2];
    	if (items) {
    	    for(var j=0;j< items.length; j++) {
    	      if (items[j][0]==id) {
	    	NavbarItems[c][i][2][j][1] = 1 - items[j][1];
		var navdiv = getPageItem('navbar_'+c);
		if (navdiv) {
		    writePageItem('navbar_'+c,renderNavbarLevel(c,0,NavbarItems[c]));
		}
	      }
	    }
	}
      }
    }
    return 0;
}

function displaySWF(url,ver,w,h) {
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+'" width="'+w+'" height="'+h+'"><param name="movie" value="'+url+'"><param name="quality" value="high"><embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed></object>');
}

var toid;
function toggleDiv(id) { var d = getPageItem(id); if (d) { if (d.style.visibility == 'hidden') d.style.visibility = 'visible'; else d.style.visibility = 'hidden'; } }
function showDiv(id) { var d=getPageItem(id); if (d) { d.style.visibility='visible'; } }
function hideDiv(id) { var d=getPageItem(id); if (d) { d.style.visibility='hidden'; } }

// template specific
// Array( 'main', 'item_main', 'empty_item', 'imgonly_item', 'nosub_item', 'sub_open_item', 'sub_close_item')
NavbarTemplates = Array(
 Array( 
   Array('%%ITEMS%%', 
   '%%ITEM%%%%SUB%%',
   '',
   '<div class="header navbar visual"><a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"/></a></div>',
   '<div class="header navbar">%%TEXT%%</div>'),

   Array('<ul class="navbar">%%ITEMS%%</ul>', 
   '<li class="navbar item%%PADLOCK%%">%%ITEM%%</li>%%SUB%%',
   '',
   '<a class="button" href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"/></a>',
   '<a class="button" href="%%LINK%%">%%TEXT%%</a>',
   '<a class="button" href="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://www.oecdobserver.org/pixmaps/up.gif" hspace="0" vspace="1" border="0"/></a>',
   '<a class="button" href="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://www.oecdobserver.org/pixmaps/down.gif" hspace="0" vspace="1" border="0"/></a>'),

   Array('%%ITEMS%%', 
   '<li class="navbar item sub%%PADLOCK%%">%%ITEM%%</li>',
   '',
   '<a class="button" href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"/></a>',   
   '<a class="button" href="%%LINK%%">%%TEXT%%</a>')
 ),
 Array(),
 Array( 
    Array('%%ITEMS%%', 
   '%%ITEM%%%%SUB%%',
   '',
   '<div class="header navbar visual"><a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"/></a></div>',
   '<div class="header navbar">%%TEXT%%</div>'),

   Array('<ul class="navbar">%%ITEMS%%</ul>', 
   '<li class="navbar item%%PADLOCK%%">%%ITEM%%</li>%%SUB%%',
   '',
   '<a class="button" href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"/></a>',
   '<a class="button" href="%%LINK%%">%%TEXT%%</a>',
   '<a class="button" href="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://www.oecdobserver.org/pixmaps/up.gif" hspace="0" vspace="1" border="0"/></a>',
   '<a class="button" href="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://www.oecdobserver.org/pixmaps/down.gif" hspace="0" vspace="1" border="0"/></a>'),

   Array('%%ITEMS%%', 
   '<li class="navbar item sub%%PADLOCK%%">%%ITEM%%</li>',
   '',
   '<a class="button" href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"/></a>',   
   '<a class="button" href="%%LINK%%">%%TEXT%%</a>')
 )
);

PadlockTemplate=' padlock';
