NavbarItems = Array(3);
NavbarItems[0] = Array(
 Array('1',1, Array(
   Array('300',1, null,'<br>HOME','http://www.forres-gazette.co.uk/','','',0)),'','','','',0),
 Array('3',1, Array(
   Array('44',1, null,'Local News','http://www.forres-gazette.co.uk/news/categoryfront.php/id/44/Local_News.html','','',0),
   Array('45',1, null,'Regional News','http://www.forres-gazette.co.uk/news/categorypool.php/id/1','','',0)),'NEWS','http://www.forres-gazette.co.uk/news/categoryfront.php/id/3/NEWS.html','','',0),
 Array('11',1, Array(
   Array('47',1, Array(
     Array('69',1, null,'Cycling','http://www.forres-gazette.co.uk/news/categoryfront.php/id/69/Cycling.html','','',0),
     Array('57',1, null,'Football','http://www.forres-gazette.co.uk/news/categoryfront.php/id/57/Football.html','','',0)),'Local Sport','http://www.forres-gazette.co.uk/news/categoryfront.php/id/47/Local_Sport.html','','',0),
   Array('48',1, null,'Regional Sport','http://www.forres-gazette.co.uk/news/categorypool.php/id/2','','',0),
   Array('281',1, null,'Turf Talking','http://www.forres-gazette.co.uk/news/categoryfront.php/id/281/Turf_Talking.html','','',0)),'SPORT','http://www.forres-gazette.co.uk/news/categoryfront.php/id/11/SPORT.html','','',0),
 Array('12',1, Array(
   Array('271',1, null,'Councillor\'s Corner','http://www.forres-gazette.co.uk/news/categoryfront.php/id/271/Councillor_s_Corner.html','','',0),
   Array('244',1, null,'Dear Diary','http://www.forres-gazette.co.uk/news/categoryfront.php/id/244/Dear_Diary.html','','',0),
   Array('42',1, null,'Leader','http://www.forres-gazette.co.uk/news/categoryfront.php/id/42/Leader.html','','',0),
   Array('43',1, null,'Letters','http://www.forres-gazette.co.uk/news/categoryfront.php/id/43/Letters.html','','',0),
   Array('123',1, null,'The Big Vote','http://www.forres-gazette.co.uk/news/categoryfront.php/id/123/The_Big_Vote.html','','',0),
   Array('272',1, null,'A Week in Parliament','http://www.forres-gazette.co.uk/news/categoryfront.php/id/272/A_Week_in_Parliament.html','','',0)),'OPINION','http://www.forres-gazette.co.uk/news/categoryfront.php/id/12/OPINION.html','','',0),
 Array('13',1, Array(
   Array('38',1, null,'Church View','http://www.forres-gazette.co.uk/news/categoryfront.php/id/38/Church_View.html','','',0),
   Array('296',1, null,'Featured Articles','http://www.forres-gazette.co.uk/news/categoryfront.php/id/296/Featured_Articles.html','','',0),
   Array('295',1, null,'Moray Sky At Night','http://www.forres-gazette.co.uk/news/categoryfront.php/id/295/Moray_Sky_At_Night.html','','',0),
   Array('117',1, null,'Orra Beel','http://www.forres-gazette.co.uk/news/categoryfront.php/id/117/Orra_Beel.html','','',0),
   Array('115',1, null,'People and Places','http://www.forres-gazette.co.uk/news/categoryfront.php/id/115/People_and_Places.html','','',0),
   Array('40',1, null,'The Way We Were','http://www.forres-gazette.co.uk/news/categoryfront.php/id/40/The_Way_We_Were.html','','',0),
   Array('163',1, null,'Weather Watch','http://www.forres-gazette.co.uk/news/categoryfront.php/id/163/Weather_Watch.html','','',0)),'FEATURES','http://www.forres-gazette.co.uk/news/categoryfront.php/id/13/FEATURES.html','','',0),
 Array('126',1, Array(
   Array('39',1, null,'Looking Back','http://www.forres-gazette.co.uk/news/categoryfront.php/id/39/Looking_Back.html','','',0),
   Array('127',1, null,'Seeking The Past','http://www.forres-gazette.co.uk/news/categoryfront.php/id/127/Seeking_The_Past.html','','',0),
   Array('130',1, null,'Times Gone By','http://www.forres-gazette.co.uk/news/categoryfront.php/id/130/Times_Gone_By.html','','',0)),'FORRES ROOTS','http://www.forres-gazette.co.uk/news/categoryfront.php/id/126/FORRES_ROOTS.html','','',0),
 Array('258',1, Array(
   Array('253',1, null,'Historical Photo Archive','http://3276.e-printphoto.co.uk/spp/index.cfm?z=z&y=y&action=cat&refine=1&c_id=56121','','',0),
   Array('135',1, Array(
     Array('136',1, null,'Burghead Headland Trust','http://website.lineone.net/~cathm19/','','',0),
     Array('157',1, null,'Falconer Museum','http://www.falconermuseum.co.uk/','','',0),
     Array('264',1, null,'Findhorn Heritage Centre & Icehouse','http://www.findhorn-heritage.co.uk/','','',0),
     Array('221',1, null,'Highland Museum Services','http://www.spanglefish.com/HighlandMuseumServices/','','',0),
     Array('259',1, null,'Homecoming Scotland','http://www.homecomingscotland.com/','','',0),
     Array('266',1, null,'Moray Burial Ground Research Group','http://www.mbgrg.org/','','',0),
     Array('184',1, null,'Moray Family History','http://www.moray.gov.uk/LocalHeritage/Assets/html_pages/tracing_roots.html','','',0)),'Links','','','',0)),'','','','',0),
 Array('14',1, Array(
   Array('36',1, Array(
     Array('95',1, null,'A, B, C','http://www.forres-gazette.co.uk/news/categoryfront.php/id/95/A,_B,_C.html','','',0),
     Array('96',1, null,'D, E, F','http://www.forres-gazette.co.uk/news/categoryfront.php/id/96/D,_E,_F.html','','',0),
     Array('97',1, null,'G, H, I, J','http://www.forres-gazette.co.uk/news/categoryfront.php/id/97/G,_H,_I,_J.html','','',0),
     Array('98',1, null,'K, L, M','http://www.forres-gazette.co.uk/news/categoryfront.php/id/98/K,_L,_M.html','','',0),
     Array('99',1, null,'Mc, Mac','http://www.forres-gazette.co.uk/news/categoryfront.php/id/99/Mc,_Mac.html','','',0),
     Array('100',1, null,'N, O, P, Q','http://www.forres-gazette.co.uk/news/categoryfront.php/id/100/N,_O,_P,_Q.html','','',0),
     Array('101',1, null,'R, S, T, U','http://www.forres-gazette.co.uk/news/categoryfront.php/id/101/R,_S,_T,_U.html','','',0),
     Array('102',1, null,'V, W, X, Y, Z','http://www.forres-gazette.co.uk/news/categoryfront.php/id/102/V,_W,_X,_Y,_Z.html','','',0)),'Graduations','http://www.forres-gazette.co.uk/news/categoryfront.php/id/36/Graduations.html','','',0),
   Array('37',1, Array(
     Array('87',1, null,'A, B, C','http://www.forres-gazette.co.uk/news/categoryfront.php/id/87/A,_B,_C.html','','',0),
     Array('88',1, null,'D, E, F','http://www.forres-gazette.co.uk/news/categoryfront.php/id/88/D,_E,_F.html','','',0),
     Array('89',1, null,'G, H, I, J','http://www.forres-gazette.co.uk/news/categoryfront.php/id/89/G,_H,_I,_J.html','','',0),
     Array('90',1, null,'K, L, M','http://www.forres-gazette.co.uk/news/categoryfront.php/id/90/K,_L,_M.html','','',0),
     Array('91',1, null,'Mc, Mac','http://www.forres-gazette.co.uk/news/categoryfront.php/id/91/Mc,_Mac.html','','',0),
     Array('92',1, null,'N, O, P, Q','http://www.forres-gazette.co.uk/news/categoryfront.php/id/92/N,_O,_P,_Q.html','','',0),
     Array('93',1, null,'R, S, T, U','http://www.forres-gazette.co.uk/news/categoryfront.php/id/93/R,_S,_T,_U.html','','',0),
     Array('94',1, null,'V, W, X, Y, Z','http://www.forres-gazette.co.uk/news/categoryfront.php/id/94/V,_W,_X,_Y,_Z.html','','',0)),'Wedding Days','http://www.forres-gazette.co.uk/news/categoryfront.php/id/37/Wedding_Days.html','','',0)),'GALLERY','http://www.forres-gazette.co.uk/news/categoryfront.php/id/14/GALLERY.html','','',0),
 Array('15',1, Array(
   Array('278',1, null,'Film Trailers','http://www.forres-gazette.co.uk/filmtrailers','','',0),
   Array('31',1, null,'In the Spotlight','http://www.forres-gazette.co.uk/news/categoryfront.php/id/31/In_the_Spotlight.html','','',0),
   Array('179',1, null,'The Music Room','http://www.forres-gazette.co.uk/news/categoryfront.php/id/179/The_Music_Room.html','','',0),
   Array('32',1, null,'Regional Round-up','http://www.forres-gazette.co.uk/news/categorypool.php/id/3','','',0),
   Array('263',1, null,'Shopping','http://www.forres-gazette.co.uk/shopping.php','','',0),
   Array('175',1, null,'Sudoku','http://www.forres-gazette.co.uk/sudoku','','',0),
   Array('294',1, null,'Travel','http://www.forres-gazette.co.uk/news/categoryfront.php/id/294/Travel.html','','',0)),'LEISURE','http://www.forres-gazette.co.uk/news/categoryfront.php/id/15/LEISURE.html','','',0),
 Array('171',1, Array(
   Array('172',1, null,'Crosswords','http://www.poinscrosswords.com/quickcrosswords.html','','',0),
   Array('274',1, null,'Horoscopes','http://www.g8wave.co.uk/RussellGrant/SPP/Horoscopes.htm','','',0),
   Array('270',1, null,'TV Guide','http://www.spp-group.com/tv/fgtv.htm','','',0)),'','','','',0),
 Array('6',1, Array(
   Array('8',1, null,'Contact Us','http://www.forres-gazette.co.uk/info/contact_us.php','','',0),
   Array('7',1, null,'About the Paper','http://www.forres-gazette.co.uk/info/about_us.php','','',0),
   Array('120',1, null,'Place an Ad','mailto:admin@forres-gazette.co.uk','','',0)),'SERVICES','','','',0),
 Array('77',1, Array(
   Array('131',1, Array(
     Array('267',1, null,'Culbin Singers','http://www.manachie.eclipse.co.uk/culbinsingers.htm','','',0),
     Array('213',1, null,'Fčisean nan Gŕidheal','http://www.feisean.org/','','',0),
     Array('214',1, null,'Hi-Arts','http://www.hi-arts.co.uk/','','',0),
     Array('219',1, null,'Highland Feltmakers Group','http://www.spanglefish.com/HighlandFelters/','','',0),
     Array('132',1, null,'Iona','http://www.iona.tv','','',0),
     Array('208',1, null,'Moray Art Centre','http://www.morayartcentre.org/','','',0),
     Array('188',1, null,'Universal Hall, Findhorn','http://www.findhorn.org/content/uhall/index.php','','',0),
     Array('187',1, null,'Warehouse Theatre, Lossiemouth','http://www.thewarehousetheatre.co.uk/','','',0)),'Arts, Music and Entertainment','','','',0),
   Array('176',1, Array(
     Array('177',1, null,'Highlands and Islands Enterprise','http://www.hie.co.uk/','','',0),
     Array('178',1, null,'HIE Moray','http://www.hie.co.uk/moray','','',0),
     Array('142',1, null,'Rotary Club of Forres','http://www.rotary-ribi.org/clubs/homepage.asp?ClubID=31','','',0),
     Array('284',1, null,'Shambala Retreat Centre','http://www.shambala-retreat.org/','','',0)),'Business','','','',0),
   Array('84',1, Array(
     Array('147',1, null,'Findhorn Foundation','http://www.findhorn.org/home_new.php','','',0),
     Array('257',1, null,'Findhorn & Kinloss Community Council','http://freespace.virgin.net/rick.walker1/','','',0),
     Array('150',1, null,'Forres - Royal Burgh','http://www.forres-net.co.uk/','','',0),
     Array('134',1, null,'Forres Community Web','http://www.forresweb.net/','','',0),
     Array('156',1, null,'Kinloss and Findhorn','http://www.findhornbay.info/','','',0),
     Array('269',1, null,'Moray','http://www.thisismoray.com/','','',0),
     Array('254',1, null,'Moray Council','http://www.moray.org/','','',0),
     Array('167',1, null,'Moray Gateway','http://www.moraygateway.com/page.php?id=619','','',0),
     Array('160',1, null,'Moray Hydrotherapy Pool','http://www.morayhydrotherapypool.co.uk/','','',0),
     Array('290',1, null,'Moray Voluntary Service Organisation','http://www.mvso.org.uk/','','',0),
     Array('288',1, null,'Outfit Moray','http://www.outfitmoray.com/','','',0),
     Array('149',1, null,'St John the Evangelist, Forres','http://myweb.tiscali.co.uk/stjohnsforres/index.htm','','',0),
     Array('289',1, null,'Voluntary Sector Partnership Moray','http://www.vspm.org.uk/','','',0),
     Array('276',1, null,'Volunteer Centre Moray','http://www.volunteermoray.org.uk/','','',0)),'Community','','','',0),
   Array('158',1, Array(
     Array('168',1, null,'Blas','http://www.blas-festival.com/','','',0),
     Array('229',1, null,'Bootstock','http://bootstock.org/default.aspx','','',0),
     Array('138',1, null,'Forres Highland Games','http://www.forreshighlandgames.fsnet.co.uk/index.htm','','',0)),'Events','','','',0),
   Array('162',1, Array(
     Array('161',1, null,'Dava Way','http://www.davaway.org.uk/','','',0),
     Array('137',1, null,'Forres Footpaths Trust','http://www.forresfootpathstrust.org.uk/','','',0),
     Array('220',1, null,'Highland Hillwalking Club','http://www.spanglefish.com/HighlandHillwalkingClub/','','',0),
     Array('183',1, null,'Moray Inshore Rescue Organisation','http://www.morayinshorerescue.org/','','',0)),'Outdoors','','','',0),
   Array('143',1, Array(
     Array('148',1, null,'Forres Angling Association','http://www.forres-angling.net/','','',0),
     Array('283',1, null,'Forres Area Soccer Sevens','http://www.soccer7s.piczo.com/?cr=5','','',0),
     Array('227',1, null,'Forres Bluefins','http://www.forresbluefins.orangehome.co.uk/','','',0),
     Array('242',1, null,'Forres Curling Club','http://www.royalcaledoniancurlingclub.org/areas/10/prv/moray/club/Forres48427/','','',0),
     Array('165',1, null,'Forres Golf Club','http://www.forresgolfclub.co.uk/epages/es108644.sf','','',0),
     Array('144',1, null,'Forres Harriers','http://www.forresharriers.fsnet.co.uk/','','',0),
     Array('146',1, null,'Forres Mechanics','http://eteamz.active.com/forresmechanicsfc/index.cfm?','','',0),
     Array('216',1, null,'Forres Pub Darts League','http://forrespubdartsleague.co.uk/','','',0),
     Array('185',1, null,'Forres Soccer Sevens','http://www.soccer7s.piczo.com/','','',0),
     Array('293',1, null,'Forres St. Lawrence Cricket Club','http://www.forrescricket.co.uk','','',0),
     Array('291',1, null,'Forres Tennis Club','http://www.forrestennisclub.co.uk/','','',0),
     Array('145',1, null,'Forres Thistle','http://eteamz.active.com/FORRESTHISTLEUNOFFICIAL/index.cfm?','','',0),
     Array('217',1, null,'Highland Disability Sport','http://www.highlanddisabilitysport.info/','','',0),
     Array('218',1, null,'Highland Sports Development Association','http://www.hsda.co.uk/','','',0),
     Array('228',1, null,'Moravian Orienteers','http://www.moravianorienteering.org/','','',0),
     Array('277',1, null,'Moray Muay Thai Club','http://www.moraymuaythai.co.uk/','','',0),
     Array('212',1, null,'Moray and Nairn Golf League','http://www.mngl.co.uk/','','',0),
     Array('166',1, null,'Royal Findhorn Yacht Club','http://www.royalfindhornyachtclub.com/','','',0),
     Array('286',1, null,'SEPF Ladies Pool','http://www.sepfladies.com/news.php','','',0)),'Sport','','','',0),
   Array('209',1, Array(
     Array('210',1, null,'Greater Speyside','http://www.greaterspeyside.com/','','',0)),'Tourism','','','',0),
   Array('139',1, Array(
     Array('140',1, null,'Benromach','http://www.benromach.com/','','',0),
     Array('141',1, null,'Gordon and MacPhail','http://www.gordonandmacphail.com/','','',0)),'Whisky','','','',0),
   Array('169',1, Array(
     Array('170',1, null,'Forres Academy','http://www.forresacademy.org.uk/','','',0),
     Array('275',1, null,'Moray Sea Cadets','http://www.morayseacadets.co.uk/','','',0),
     Array('222',1, null,'Youth Highland','http://www.spanglefish.com/YouthHighland/','','',0)),'Youth','','','',0)),'LINKS','','','',0),
 Array('189',1, Array(
   Array('190',1, Array(
     Array('191',1, null,'Community Councils','http://www.forres-gazette.co.uk/news/categoryfront.php/id/191/Community_Councils.html','','',0),
     Array('192',1, null,'Moray Council','http://www.forres-gazette.co.uk/news/categoryfront.php/id/192/Moray_Council.html','','',0),
     Array('193',1, null,'Scottish Parliament','http://www.forres-gazette.co.uk/news/categoryfront.php/id/193/Scottish_Parliament.html','','',0),
     Array('194',1, null,'Westminster','http://www.forres-gazette.co.uk/news/categoryfront.php/id/194/Westminster.html','','',0),
     Array('195',1, null,'European Parliament','http://www.forres-gazette.co.uk/news/categoryfront.php/id/195/European_Parliament.html','','',0)),'Council and Parliament','http://www.forres-gazette.co.uk/news/categoryfront.php/id/190/Council_and_Parliament.html','','',0),
   Array('196',1, Array(
     Array('197',1, null,'Colleges','http://www.forres-gazette.co.uk/news/categoryfront.php/id/197/Colleges.html','','',0),
     Array('198',1, null,'Schools','http://www.forres-gazette.co.uk/news/categoryfront.php/id/198/Schools.html','','',0)),'Education','http://www.forres-gazette.co.uk/news/categoryfront.php/id/196/Education.html','','',0),
   Array('199',1, Array(
     Array('200',1, null,'Citizens Advice Bureaux','http://www.forres-gazette.co.uk/news/categoryfront.php/id/200/Citizens_Advice_Bureaux.html','','',0),
     Array('201',1, null,'Samaritans','http://www.forres-gazette.co.uk/news/categoryfront.php/id/201/Samaritans.html','','',0),
     Array('202',1, null,'Watchdogs','http://www.forres-gazette.co.uk/news/categoryfront.php/id/202/Watchdogs.html','','',0)),'Emergency and Advice','http://www.forres-gazette.co.uk/news/categoryfront.php/id/199/Emergency_and_Advice.html','','',0),
   Array('203',1, Array(
     Array('260',1, null,'Babyfeeding','http://www.forres-gazette.co.uk/news/categoryfront.php/id/260/Babyfeeding.html','','',0),
     Array('204',1, null,'Doctors','http://www.forres-gazette.co.uk/news/categoryfront.php/id/204/Doctors.html','','',0),
     Array('205',1, null,'Giving Blood','http://www.forres-gazette.co.uk/news/categoryfront.php/id/205/Giving_Blood.html','','',0),
     Array('215',1, null,'Hospices','http://www.forres-gazette.co.uk/news/categoryfront.php/id/215/Hospices.html','','',0),
     Array('206',1, null,'Hospitals','http://www.forres-gazette.co.uk/news/categoryfront.php/id/206/Hospitals.html','','',0),
     Array('207',1, null,'Search for Help','http://www.forres-gazette.co.uk/news/categoryfront.php/id/207/Search_for_Help.html','','',0)),'Health','http://www.forres-gazette.co.uk/news/categoryfront.php/id/203/Health.html','','',0),
   Array('285',1, null,'Jobs in Moray','http://www.jobs-north.co.uk/Moray-jobs/','','',0),
   Array('211',1, null,'Scottish Clans','http://www.forres-gazette.co.uk/news/categoryfront.php/id/211/Scottish_Clans.html','','',0)),'DIRECTORY','http://www.forres-gazette.co.uk/news/categoryfront.php/id/189/DIRECTORY.html','','',0),
 Array('224',1, Array(
   Array('225',1, null,'Executive','http://www.executive-magazine.co.uk/','','',0),
   Array('226',1, null,'Highland Life','http://www.highland-life.co.uk/','','',0),
   Array('245',1, null,'Highland Weddings','http://www.thehighlandweddingdirectory.com/','','',0),
   Array('246',1, null,'Lochaber Life','http://www.lochaber-life.co.uk/','','',0),
   Array('240',1, null,'<br>','','','',0),
   Array('230',1, null,'Banffshire Journal','http://www.banffshire-journal.co.uk/','','',0),
   Array('241',1, null,'Caithness Courier','http://www.johnogroat-journal.co.uk/','','',0),
   Array('231',1, null,'Highland News','http://www.highland-news.co.uk/','','',0),
   Array('232',1, null,'Inverness Courier','http://www.inverness-courier.co.uk/','','',0),
   Array('233',1, null,'John O\'Groat Journal','http://www.johnogroat-journal.co.uk/','','',0),
   Array('234',1, null,'Lochaber News','http://www.lochaber-news.co.uk/','','',0),
   Array('235',1, null,'North Star','http://www.north-star-news.co.uk/','','',0),
   Array('236',1, null,'Northern Scot','http://www.northern-scot.co.uk/','','',0),
   Array('237',1, null,'Northern Times','http://www.northern-times.co.uk/','','',0),
   Array('238',1, null,'Ross-shire Journal','http://www.ross-shirejournal.co.uk/','','',0),
   Array('239',1, null,'Strathspey & Badenoch Herald','http://www.strathspey-herald.co.uk/','','',0)),'SPP PUBLICATIONS','','','',0),
 Array('280',1, Array(
   Array('abli',1, null,'Previous&nbsp;issue','http://www.forres-gazette.co.uk/news/archive_browser.php/issue/1283227200.html','','',0),
   Array('abbi',1, null,'Browse&nbsp;articles&nbsp;by&nbsp;date','http://www.forres-gazette.co.uk/news/archive_browser.php','','',0)),'Back Issues','javascript:void(0);','','',0));
NavbarItems[1] = Array(
 Array('19',1, Array(
   Array('20',1, null,'Jobs in Moray','http://www.jobs-north.co.uk/Moray-jobs/','','',0),
   Array('152',1, null,'CV Online','http://www.jobs-north.co.uk/','','',0),
   Array('268',1, null,'Dating','http://www.perfectpartnersonline.co.uk/','','',0),
   Array('23',1, null,'For Sale','http://www.classifieds-north.co.uk/','','',0),
   Array('21',1, null,'Motors','http://www.motors-north.co.uk','','',0),
   Array('22',1, null,'Property','http://www.property-north.co.uk/','','',0),
   Array('252',1, null,'Photo Sales','http://3276.e-printphoto.co.uk/spp/','','',0)),'','','','',0),
 Array('4',1, Array(
   Array('251',1, null,'Family Notices','http://www.forres-gazette.co.uk/news/categoryfront.php/id/251/Family_Notices.html','','',0),
   Array('133',1, null,'Special Features','http://www.forres-gazette.co.uk/news/categoryfront.php/id/133/Special_Features.html','','',0),
   Array('153',1, null,'Eating Out','http://www.forres-gazette.co.uk/news/categoryfront.php/id/153/Eating_Out.html','','',0),
   Array('164',1, null,'Supplements','http://www.forres-gazette.co.uk/news/categoryfront.php/id/164/Supplements.html','','',0)),'','','','',0));
NavbarItems[2] = Array(
 Array('248',1, null,'','','','',0));
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%%<ul class="navbar">%%SUB%%</ul>',
   '',
   '<div class="header navbar visual"><a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a></div>',
   '<div class="header navbar">%%TEXT%%</div>'),

   Array('%%ITEMS%%', 
   '%%ITEM%%%%SUB%%',
   '',
   '<li class="navbar item">%%PADLOCK%%<a class="button" href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a></li>',
   '<li class="navbar item">%%PADLOCK%%<a class="button" href="%%LINK%%">%%TEXT%%</a></li>',
   '<li class="navbar item haschild">%%PADLOCK%%<a class="button" href="%%LINK%%" onClick="toggleNavbarItem(\'%%ID%%\');return false;"><img src="http://www.forres-gazette.co.uk/themes/itc2/trade_arrow_opened.gif" hspace=0 vspace=1 border=0>%%TEXT%%</a></li>',
   '<li class="navbar item haschild">%%PADLOCK%%<a class="button" href="%%LINK%%" onClick="toggleNavbarItem(\'%%ID%%\');return false;"><img src="http://www.forres-gazette.co.uk/themes/itc2/trade_arrow_closed.gif" hspace=0 vspace=1 border=0>%%TEXT%%</a></li>'),

   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%%<ul class="navbar">%%SUB%%</ul>',
   '',
   '<div class="header navbar visual"><a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a></div>',
   '<div class="header navbar">%%TEXT%%</div>'),

   Array('%%ITEMS%%', 
   '%%ITEM%%%%SUB%%',
   '',
   '<li class="navbar item">%%PADLOCK%%<a class="button" href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a></li>',
   '<li class="navbar item">%%PADLOCK%%<a class="button" href="%%LINK%%">%%TEXT%%</a></li>',
   '<li class="navbar item haschild">%%PADLOCK%%<a class="button" href="%%LINK%%" onClick="toggleNavbarItem(\'%%ID%%\');return false;"><img src="http://www.forres-gazette.co.uk/themes/itc2/trade_arrow_opened.gif" hspace=0 vspace=1 border=0>%%TEXT%%</a></li>',
   '<li class="navbar item haschild">%%PADLOCK%%<a class="button" href="%%LINK%%" onClick="toggleNavbarItem(\'%%ID%%\');return false;"><img src="http://www.forres-gazette.co.uk/themes/itc2/trade_arrow_closed.gif" hspace=0 vspace=1 border=0>%%TEXT%%</a></li>'),

   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='<img src="http://www.forres-gazette.co.uk/pixmaps/padlock.gif" border="0" align="right" hspace="1" vspace="1">';
