NavbarItems = Array(3);
NavbarItems[0] = Array(
 Array('1',1, Array(
   Array('14',1, null,'Events','/news/categoryfront.php/id/14/Events.html','/images/decor//cat_nav_14.gif','',0),
   Array('12',1, null,'News','/news/categoryfront.php/id/12/News.html','/images/decor//cat_nav_12.gif','',0),
   Array('47',1, null,'Where is Archie','/news/categoryfront.php/id/47/Where_is_Archie.html','/images/decor//cat_nav_47.gif','',0),
   Array('50',1, null,'Recruitment','/news/categoryfront.php/id/50/Recruitment.html','/images/decor//cat_nav_50.gif','',0),
   Array('56',1, null,'Webcam','/news/categoryfront.php/id/56/Webcam.html','/images/decor//cat_nav_56.gif','',0)),'Discover','/news/categoryfront.php/id/1/Discover.html','','',0),
 Array('6',1, Array(
   Array('26',1, null,'Community Forums','http://forums.arranbanner.net','','',0),
   Array('58',1, null,'Advert enquiry','http://www.arranbanner.co.uk/news/fullstory.php/aid/1330/Advert_Enquiry.html','','',0),
   Array('8',1, null,'Contact us','/info/contact_us.php','','',0),
   Array('9',1, null,'Subscribe online','http://shop.wyvexmedia.co.uk','','',0),
   Array('7',1, null,'Banner History','/info/about_us.php','','',0),
   Array('31',1, null,'Got a story?','/news/fullstory.php/aid/55/Got_a_Story_.html','','',0),
   Array('37',1, null,'RSS','/news/rss.php/rss.xml','/images/decor//cat_nav_37.gif','',0),
   Array('40',1, null,'RSS - What is it?','http://forums.arranbanner.net/showthread.php?t=42','','',0),
   Array('42',1, null,'Terms & Conditions','/news/categoryfront.php/id/16/Terms___Conditions.html','','',0),
   Array('46',1, null,'Archive by date','/news/archive_browser.php','','',0)),'Interact','','','',0),
 Array('21',1, Array(
   Array('23',1, null,'Holiday West Highland','http://www.holidaywesthighland.co.uk','','',0),
   Array('22',1, null,'Illustrated Maps','http://www.scottishtouristmaps.co.uk','','',0),
   Array('51',1, null,'Holiday Arran','http://www.holidayarran.co.uk','','',0),
   Array('52',1, null,'Scottish Calendars','http://www.scottishcalendars.co.uk','','',0),
   Array('57',1, null,'West Coast Jobs','http://www.westcoastjobs.co.uk','','',0)),'Discover more','','','',0),
 Array('36',1, Array(
   Array('24',1, null,'Lorn Life','http://www.lornlife.com','','',0),
   Array('30',1, null,'The Oban Times','http://www.obantimes.co.uk','','',0),
   Array('54',1, null,'Illustrated maps','http://www.scottishtouristmaps.co.uk','/images/decor//cat_nav_54.jpg','',0)),'Into Argyll','','','',0));
NavbarItems[1] = Array(
 Array('33',1, Array(
   Array('34',1, null,'Home','http://www.arranbanner.co.uk','','',0),
   Array('35',1, null,'Community Forums','http://forums.arranbanner.net','','',0),
   Array('39',1, null,'Banner Post e-Alerts','/email_signup/','','',0),
   Array('41',1, null,'Make this your home page','/news/fullstory.php/aid/72/Set_the_Arran_Banner_as_your_Homepage..html','','',0),
   Array('53',1, null,'Holiday Arran','http://www.holidayarran.co.uk','','',0),
   Array('59',1, null,'<!--[if IE]>      <![endif]--> <![if !IE]> <script type=\"text/javascript\"> <!--     function toggle_visibility(id) {        var e = document.getElementById(id);        if(e.style.display == \'block\')           e.style.display = \'none\';        else           e.style.display = \'block\';     } //--> </script> <div id=\"site_switcher\">     <h6 id=\"switcher-trigger\" class=\"switcher\"><a href=\"#site_switcher\" onclick=\"toggle_visibility(\'links-wrap\');\">Wyvexmedia Network</a></h6>     <div id=\"links-wrap\" style=\"display:none;\">     <div id=\"links\">       <div id=\"first\">         <table>                      <tr>             <td class=\"my_alt\"><a href=\"http://www.obantimes.co.uk/\" title=\"The Oban Times Newspaper\">The Oban Times</a></td>             <td><a href=\"http://www.obantimes.co.uk/\" title=\"The Oban Times Newspaper\">The West Highland\'s newspaper</a></td>           </tr>                      <tr>             <td class=\"my_alt\"><a href=\"http://www.campbeltowncourier.co.uk/\" title=\"The Campbeltown Courier\">The Campbeltown Courier</a></td>             <td><a href=\"www.campbeltowncourier.co.uk\" title=\"The Campbeltown Courier\">The local newspaper for Campbeltown</a></td>           </tr>                      <tr>             <td class=\"my_alt\"><a href=\"http://www.argyllshireadvertiser.co.uk\" title=\"The Argyllshire Advertiser\">The Argyllshire Advertiser</a></td>             <td><a href=\"http://www.argyllshireadvertiser.co.uk\" title=\"The local paper for Mid Argyll \">The local paper for Mid Argyll</a></td>           </tr>                      <tr>             <td class=\"my_alt\"><a href=\"http://www.arranbanner.co.uk/\" title=\"The Arran Banner\">The Arran Banner</a></td>             <td><a href=\"http://www.arranbanner.co.uk/\" title=\"The Local Newspaper for Arran\">The Local newspaper for The Isle of Arran</a></td>           </tr>                                          </table>       </div>       <div id=\"second\">         <table> 			<tr> 	        <td class=\"my_alt\"><a href=\"http://www.scottishfield.co.uk\" title=\"Scottish Field Magazine\">Scottish Field Magazine</a></td> 	            <td><a href=\"http://www.scottishfield.co.uk\" title=\"Scottish Field Magazine\">Scotlands Premier Lifestle Magazine</a></td> 	          </tr>           <tr>             <td class=\"my_alt\"><a href=\"http://www.usscots.com\" title=\"US Scots - Scots Heritage Magazine\">Scots Heritage Magazine</a></td>             <td><a href=\"http://www.usscots.com\" title=\"US Scots - Scots Heritage Magazine\">Connecting you with Scotland</a></td>           </tr>           <tr>             <td class=\"my_alt\"><a href=\"http://www.whiskychallenge.com/\" title=\"Scottish Field Whisky Challenge\">Whisky Challenge</a></td>             <td><a href=\"http://www.whiskychallenge.com/\" title=\"Scottish Field Whisky Challenge\">Unearthing Scotland\'s best whiskies</a></td>           </tr>                  <tr>             <td class=\"my_alt\"><a href=\"http://www.scottishcalendars.co.uk\" title=\"Scottish Calendars from Scotland\">Scottish Calendars</a></td>             <td><a href=\"http://www.scottishcalendars.co.uk\" title=\"Scottish Calendars from Scotland\">A Calendar from Scotland</a></td>           </tr>            <tr>             <td class=\"my_alt\"><a href=\"http://www.krispprint.co.uk\" title=\"Krisp Printing and Stationery\">Krisp Print</a></td>             <td><a href=\"http://www.krispprint.co.uk\" title=\"Krisp Printing and Stationery\">Kintyre and South Argyll Printers</a></td>           </tr>                      </tbody>         </table>       </div>       <div id=\"third\">         <table>           <tbody>                     <tr>               <td class=\"my_alt\"><a href=\"http://www.westcoastjobs.co.uk\" title=\"West Coast Jobs\">West Coast Jobs</a></td>               <td><a href=\"http://www.westcoastjobs.co.uk\" title=\"West Coast Jobs\">Job listings on the West Coast of Scotland</a></td>             </tr>             <tr>               <td class=\"my_alt\"><a href=\"http://www.westcoastpropertyguide.co.uk\" title=\"West Coast Property Guide\">West Coast Property Guide</a></td>               <td><a href=\"http://www.westcoastpropertyguide.co.uk\" title=\"West Coast Property Guide\">Property listings on the West Coast of Scotland</a></td>                       </tr>                          <tr>               <td class=\"my_alt\"><a href=\"http://www.westcoastclassifieds.co.uk\" title=\"Classified listings on the West Coast of Scotland\">West Coast Classifieds</a></td>               <td><a href=\"http://www.westcoastclassifieds.co.uk\" title=\"Classified listings on the West Coast of Scotland\">Classified listings on the West Coast of Scotland</a></td>             </tr>             <tr>               <td class=\"my_alt\"><a href=\"http://www.scottishtouristmaps.co.uk\" title=\"Scottish Tourist Maps\">Scottish Tourist Maps</a></td>               <td><a href=\"http://www.scottishtouristmaps.co.uk\" title=\"Scottish Tourist Maps\">Illustrated maps of Scotland</a></td>             </tr>                        <tr>               <td class=\"my_alt\"><a href=\"http://www.holidayarran.co.uk\" title=\"Holiday Arran\">Holiday Arran</a></td>               <td><a href=\"http://www.holidayarran.co.uk\" title=\"Holiday Arran\">Free Arran tourist guide</a></td>             </tr>             <tr>               <td class=\"my_alt\"><a href=\"http://www.holidaywesthighland.co.uk/\" title=\"AppStorm\">Holiday West Highland</a></td>               <td><a href=\"http://www.holidaywesthighland.co.uk/\" title=\"The Mac Apps Blog\">Discover the West Highlands Tourist Guide</a></td>             </tr>                        </tbody>           </table>            </div>           <div id=\"second\">         <table> 			<tr> 	        <td class=\"my_alt\"><a href=\"http://www.fishupdate.com\" title=\"FISHupdate\">Fish Update</a></td> 	            <td><a href=\"http://www.fishupdate.com\" title=\"FISHupdate\">All the latest Fish Industry News</a></td> 	          </tr>           <tr>             <td class=\"my_alt\"><a href=\"http://www.fishfarmer-magazine.com/\" title=\"Fish Farmer Magazine\">Fish Farmer Magazine</a></td>             <td><a href=\"http://www.fishfarmer-magazine.com/\" title=\"Fish Farmer Magazine\">All the latest Aquaculture News</a></td>           </tr>           <tr>             <td class=\"my_alt\"><a href=\"http://www.fisnindustryyearbook.eu/\" title=\"The Fish Industry Yearbook\">Fish Industry Yearbook</a></td>             <td><a href=\"http://www.fisnindustryyearbook.eu/\" title=\"Scottish Field Whisky Challenge\">A - Z Fishing Directory</a></td>           </tr>                                  </tbody>         </table>       </div>                          </div><!-- #lists -->     </div><!-- #slidedown_demo -->   </div><!-- #switcher --> <![endif]>','','','',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.arranbanner.co.uk/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.arranbanner.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="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://www.arranbanner.co.uk/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.arranbanner.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';
