NavbarItems = Array(3);
NavbarItems[0] = Array(
 Array('2',1, Array(
   Array('1',1, null,'Home                                                                                                ','/news/categoryfront.php/id/1/Home________________________________________________________________________________________________.html','','',0),
   Array('33',1, null,'News','/news/categoryfront.php/id/33/News.html','','',0)),'Sections','/news/categoryfront.php/id/2/Sections.html','','',0),
 Array('13',1, Array(
   Array('39',1, null,'Le Bouvreuil','/news/categoryfront.php/id/39/Le_Bouvreuil.html','','',0),
   Array('32',1, null,'RJ Doyle','/news/categoryfront.php/id/32/RJ_Doyle.html','','',0),
   Array('38',1, null,'Wine twitter','/news/categoryfront.php/id/38/Wine_twitter.html','','',0)),'Specials','/news/categoryfront.php/id/13/Specials.html','','',0),
 Array('10',1, Array(
   Array('30',1, null,'Burgundy','/news/categoryfront.php/id/30/Burgundy.html','','',0),
   Array('20',1, Array(
     Array('21',1, null,'General','/news/categoryfront.php/id/21/General.html','','',0),
     Array('12',1, null,'Meursault','/news/categoryfront.php/id/12/Meursault.html','','',0),
     Array('36',1, null,'Monthelie','/news/categoryfront.php/id/36/Monthelie.html','','',0)),'Beaune area','/news/categoryfront.php/id/20/Beaune_area.html','','',0),
   Array('23',1, Array(
     Array('27',1, null,'General','/news/categoryfront.php/id/27/General.html','','',0)),'Chalon area','/news/categoryfront.php/id/23/Chalon_area.html','','',0),
   Array('34',1, null,'Italy','/news/categoryfront.php/id/34/Italy.html','','',0)),'Villages-regions','/news/categoryfront.php/id/10/Villages-regions.html','','',0),
 Array('15',1, Array(
   Array('17',1, null,'Contact','/info/contact_us.php','','',0),
   Array('19',1, null,'Grape Vine links','/company_index/','','',0)),'Services','','','',0));
NavbarItems[1] = Array(
);
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!="") {
	        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('<table cellpadding="5" cellspacing="0" border="0"><tr><td><font face="arial,helvetica" size="1" color="#993366">%%ITEMS%%</font></td></tr></table>', 
   '%%ITEM%%<br>%%SUB%%',
   '',
   '<p><a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a>',
   '<p><font face="arial,helvetica" size="2" color="#993366"><b>%%TEXT%%</b></font>'),

   Array('%%ITEMS%%', 
   '%%ITEM%%<br>%%SUB%%',
   '',
   '<a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a>',
   '<a href="%%LINK%%">%%TEXT%%</a>',
   '<a href="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://burgundyworld.com/pixmaps/up.gif" hspace=0 vspace=1 border=0></a>',
   '<a href="javascript:void(0);" onclick="toggleNavbarItem(\'%%ID%%\');return false;">%%TEXT%%<img src="http://burgundyworld.com/pixmaps/down.gif" hspace=0 vspace=1 border=0></a>'),

   Array('%%ITEMS%%', 
   '%%ITEM%%<br>',
   '',
   '<a href="%%LINK%%"><img src="%%IMG_URL%%" alt="" border="0"></a>',   
   '<a href="%%LINK%%">- %%TEXT%%</a>')
 ),
 Array(),
 Array()
);

