NavbarItems = Array(3);
NavbarItems[0] = Array(
 Array('1',1, Array(
   Array('2',1, null,'Home','/','','',0),
   Array('11',1, Array(
     Array('12',1, null,'Beer News','/news/categoryfront.php/id/12/Beer_News.html','','',0),
     Array('13',1, null,'Cider News','/news/categoryfront.php/id/13/Cider_News.html','','',0),
     Array('14',1, null,'Spirits News','/news/categoryfront.php/id/14/Spirits_News.html','','',0),
     Array('15',1, null,'Retailer News','/news/categoryfront.php/id/15/Retailer_News.html','','',0),
     Array('16',1, null,'Snacks & Packs News','/news/categoryfront.php/id/16/Snacks___Packs_News.html','','',0),
     Array('17',1, null,'Wine News','/news/categoryfront.php/id/17/Wine_News.html','','',0)),'Latest News','/news/categoryfront.php/id/11/Latest_News.html','','',0),
   Array('18',1, Array(
     Array('19',1, null,'Beer Features','/news/categoryfront.php/id/19/Beer_Features.html','','',0),
     Array('20',1, null,'Cider Features','/news/categoryfront.php/id/20/Cider_Features.html','','',0),
     Array('21',1, null,'Spirits Features','/news/categoryfront.php/id/21/Spirits_Features.html','','',0),
     Array('22',1, null,'Wine Features','/news/categoryfront.php/id/22/Wine_Features.html','','',0)),'Features','/news/categoryfront.php/id/18/Features.html','','',0),
   Array('23',1, Array(
     Array('24',1, null,'Graham Page','/news/categoryfront.php/id/24/Graham_Page.html','','',0),
     Array('25',1, null,'Lulie Halstead','/news/categoryfront.php/id/25/Lulie_Halstead.html','','',0),
     Array('26',1, null,'Tim Atkin','/news/categoryfront.php/id/26/Tim_Atkin.html','','',0),
     Array('27',1, null,'Peter Coulson','/news/categoryfront.php/id/27/Peter_Coulson.html','','',0),
     Array('28',1, null,'Tom Fender','/news/categoryfront.php/id/28/Tom_Fender.html','','',0),
     Array('29',1, null,'Zak Avery','/news/categoryfront.php/id/29/Zak_Avery.html','','',0),
     Array('30',1, null,'OLN Editor','/news/categoryfront.php/id/30/OLN_Editor.html','','',0),
     Array('31',1, null,'Readers\' Letters','/news/categoryfront.php/id/31/Readers__Letters.html','','',0)),'Comment','/news/categoryfront.php/id/23/Comment.html','','',0),
   Array('32',1, null,'Analysis','/news/categoryfront.php/id/32/Analysis.html','','',0),
   Array('34',1, null,'Wine Report','/news/categoryfront.php/id/34/Wine_Report.html','','',0),
   Array('35',1, null,'Spirits Report','/news/categoryfront.php/id/35/Spirits_Report.html','','',0),
   Array('36',1, Array(
     Array('59',1, null,'League Table','/news/categoryfront.php/id/59/League_Table.html','','',0)),'Beer Report','/news/categoryfront.php/id/36/Beer_Report.html','','',0),
   Array('37',1, null,'Brands Report','/news/categoryfront.php/id/37/Brands_Report.html','','',0),
   Array('38',1, null,'Independent Wine Merchants','/news/categoryfront.php/id/38/Independent_Wine_Merchants.html','','',0),
   Array('41',1, null,'Retailer Focus','/news/categoryfront.php/id/41/Retailer_Focus.html','','',0),
   Array('42',1, null,'Spittoon','/news/categoryfront.php/id/42/Spittoon.html','','',0),
   Array('43',1, null,'What\'s Your Problem?','/news/categoryfront.php/id/43/What_s_Your_Problem_.html','','',0),
   Array('44',1, Array(
     Array('177',1, null,'International Cider Challenge','/news/categoryfront.php/id/177/International_Cider_Challenge.html','','',0),
     Array('45',1, null,'Drinks Retailing Awards','http://www.drinksretailingawards.co.uk\" target=\"_blank\"','','',0),
     Array('46',1, null,'International Wine Challenge','http://www.internationalwinechallenge.com','','',0),
     Array('47',1, null,'International Spirits Challenge','http://www.internationalspiritschallenge.com','','',0),
     Array('48',1, null,'International Beer Challenge','http://www.ibc-awards.com','','',0),
     Array('49',1, null,'Responsible Drinks Retailing Awards','http://www.responsibledrinksretailing.co.uk','','',0)),'Awards & Competitions','/news/categoryfront.php/id/44/Awards___Competitions.html','','',0),
   Array('111',1, null,'Meet the Team','/news/categoryfront.php/id/111/Meet_the_Team.html','','',0),
   Array('176',1, null,'Request Media Pack','mailto:samantha.briney@offlicencenews.co.uk','','',0)),'','','','',0),
 Array('115',1, Array(
   Array('abli',1, null,'Previous&nbsp;issue','/news/archive_browser.php/issue/1327986000.html','','',0),
   Array('abbi',1, null,'Browse&nbsp;articles&nbsp;by&nbsp;date','/news/archive_browser.php','','',0)),'Article Archive','javascript:void(0);','','',0));
NavbarItems[1] = Array(
 Array('112',1, null,'About Us','/info/about_us.php','','',0),
 Array('54',1, null,'Contact Us','/info/contact_us.php','','',0),
 Array('57',1, null,'Advertise','/news/fullstory.php/aid/2964/Advertise.html','','',0),
 Array('58',1, null,'Subscribe','https://shop.william-reed.co.uk/item_more_details.php?pid=107&campid=7832','','',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>');
}

// 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="%%LINK%%" onclick="toggleNavbarItem(\'%%ID%%\');">%%TEXT%%<img src="http://offlicencenews.co.uk/pixmaps/up.gif" hspace="0" vspace="1" border="0"/></a>',
   '<a class="button" href="%%LINK%%" onclick="toggleNavbarItem(\'%%ID%%\');">%%TEXT%%<img src="http://offlicencenews.co.uk/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="%%LINK%%" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://offlicencenews.co.uk/pixmaps/up.gif" hspace="0" vspace="1" border="0"/></a>',
   '<a class="button" href="%%LINK%%" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://offlicencenews.co.uk/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';

