NavbarItems = Array(3);
NavbarItems[0] = Array(
 Array('4',1, Array(
   Array('122',1, Array(
     Array('123',1, null,'Triumph','/news/categoryfront.php/id/123/Triumph.html','','',0),
     Array('124',1, null,'sloggi','/news/categoryfront.php/id/124/sloggi.html','','',0),
     Array('211',1, null,'Bravado! Designs','/news/categoryfront.php/id/211/Bravado!_Designs.html','','',0)),'Brand Profiles','/news/categoryfront.php/id/122/Brand_Profiles.html','','',0),
   Array('111',1, null,'Agent Profiles','/news/categoryfront.php/id/111/Agent_Profiles.html','','',0),
   Array('200',1, null,'Store Profiles','/news/categoryfront.php/id/200/Store_Profiles.html','','',0),
   Array('75',1, null,'Directory','/news/categoryfront.php/id/75/Directory.html','','',0),
   Array('170',1, null,'LB Interviews','/news/categoryfront.php/id/170/LB_Interviews.html','','',0)),'INDUSTRY GUIDE','/news/categoryfront.php/id/4/INDUSTRY_GUIDE.html','','',0),
 Array('71',1, Array(
   Array('94',1, null,'LB Briefs','/news/categoryfront.php/id/94/LB_Briefs.html','','',0),
   Array('198',1, null,'Trends','/news/categoryfront.php/id/198/Trends.html','','',0),
   Array('178',1, null,'LB Reports','/news/categoryfront.php/id/178/LB_Reports.html','','',0),
   Array('109',1, null,'Lingerie Events Calendar','http://www.lingerie-buyer.co.uk/calendar/index.php','','',0),
   Array('78',1, Array(
     Array('179',1, null,'Lingerie Bloggers','/news/categoryfront.php/id/179/Lingerie_Bloggers.html','','',0),
     Array('114',1, null,'LB Agony Aunt','/news/categoryfront.php/id/114/LB_Agony_Aunt.html','','',0),
     Array('108',1, null,'EPOS Clinic','/news/categoryfront.php/id/108/EPOS_Clinic.html','','',0)),'Blogs','/news/categoryfront.php/id/78/Blogs.html','','',0)),'NEWS AND FEATURES','/news/categoryfront.php/id/71/NEWS_AND_FEATURES.html','','',0),
 Array('5',1, Array(
   Array('213',1, null,'SS11 Swimwear Launches','/news/categoryfront.php/id/213/SS11_Swimwear_Launches.html','','',0),
   Array('172',1, null,'SS10 Launches and Brand News ','/news/categoryfront.php/id/172/SS10_Launches_and_Brand_News_.html','','',0),
   Array('176',1, null,'AW10 Launches and Brand News','/news/categoryfront.php/id/176/AW10_Launches_and_Brand_News.html','','',0),
   Array('204',1, Array(
     Array('188',1, null,'Swimwear','/news/categoryfront.php/id/188/Swimwear.html','','',0),
     Array('191',1, null,'Men\'s Underwear','/news/categoryfront.php/id/191/Men_s_Underwear.html','','',0),
     Array('202',1, null,'Maternity','/news/categoryfront.php/id/202/Maternity.html','','',0),
     Array('195',1, null,'Plus Size','/news/categoryfront.php/id/195/Plus_Size.html','','',0),
     Array('193',1, null,'Bridal','/news/categoryfront.php/id/193/Bridal.html','','',0),
     Array('197',1, null,'Point of Sale Accessories','/news/categoryfront.php/id/197/Point_of_Sale_Accessories.html','','',0)),'Specialist Lingerie','/news/categoryfront.php/id/204/Specialist_Lingerie.html','','',0),
   Array('73',1, Array(
     Array('86',1, null,'Advertise in Lingerie Buyer','/news/categoryfront.php/id/86/Advertise_in_Lingerie_Buyer.html','','',0),
     Array('74',1, null,'Recent advertisers','/news/categoryfront.php/id/74/Recent_advertisers.html','','',0)),'Advertise','/news/categoryfront.php/id/73/Advertise.html','','',0)),'PRODUCTS','/news/categoryfront.php/id/5/PRODUCTS.html','','',0),
 Array('96',1, Array(
   Array('206',1, null,'Latest Issue - May','/news/categoryfront.php/id/206/Latest_Issue_-_May.html','/images/decor//cat_nav_206.jpg','',0)),'LATEST ISSUE','/news/categoryfront.php/id/96/LATEST_ISSUE.html','','',0),
 Array('31',1, Array(
   Array('182',1, Array(
     Array('215',1, null,'February','/news/categoryfront.php/id/215/February.html','','',0),
     Array('183',1, null,'January','/news/categoryfront.php/id/183/January.html','','',0)),'2010','/news/categoryfront.php/id/182/2010.html','','',0),
   Array('53',1, Array(
     Array('65',1, null,'December','/news/categoryfront.php/id/65/December.html','','',0),
     Array('63',1, null,'October','/news/categoryfront.php/id/63/October.html','','',0),
     Array('61',1, null,'August','/news/categoryfront.php/id/61/August.html','','',0),
     Array('60',1, null,'July','/news/categoryfront.php/id/60/July.html','','',0),
     Array('59',1, null,'June','/news/categoryfront.php/id/59/June.html','','',0),
     Array('57',1, null,'April','/news/categoryfront.php/id/57/April.html','','',0),
     Array('55',1, null,'February','/news/categoryfront.php/id/55/February.html','','',0),
     Array('54',1, null,'January','/news/categoryfront.php/id/54/January.html','','',0)),'2009','/news/categoryfront.php/id/53/2009.html','','',0),
   Array('40',1, Array(
     Array('50',1, null,'October','/news/categoryfront.php/id/50/October.html','','',0),
     Array('42',1, null,'August','/news/categoryfront.php/id/42/August.html','','',0),
     Array('48',1, null,'July','/news/categoryfront.php/id/48/July.html','','',0),
     Array('47',1, null,'June','/news/categoryfront.php/id/47/June.html','','',0),
     Array('45',1, null,'April','/news/categoryfront.php/id/45/April.html','','',0),
     Array('41',1, null,'February','/news/categoryfront.php/id/41/February.html','','',0)),'2008','/news/categoryfront.php/id/40/2008.html','','',0),
   Array('33',1, Array(
     Array('32',1, null,'October','/news/categoryfront.php/id/32/October.html','','',0),
     Array('34',1, null,'August','/news/categoryfront.php/id/34/August.html','','',0),
     Array('35',1, null,'June','/news/categoryfront.php/id/35/June.html','','',0),
     Array('37',1, null,'April','/news/categoryfront.php/id/37/April.html','','',0),
     Array('38',1, null,'February','/news/categoryfront.php/id/38/February.html','','',0),
     Array('39',1, null,'January','/news/categoryfront.php/id/39/January.html','','',0)),'2007','/news/categoryfront.php/id/33/2007.html','','',0)),'BACK ISSUES','/news/categoryfront.php/id/31/BACK_ISSUES.html','','',0),
 Array('80',1, Array(
   Array('82',1, null,'Breast Cancer Care','http://lingerie-buyer.pressflex.com/news/fullstory.php/aid/684/Lingerie_Buyer_Supports_Breast_Cancer_Care.html','','',0),
   Array('81',1, null,'DeMontfort University','http://lingerie-buyer.pressflex.com/news/fullstory.php/aid/249/Lingerie_Buyer_supports_De_Montfort_University.html','','',0)),'PARTNERS','','','',0));
NavbarItems[1] = Array(
 Array('6',1, Array(
   Array('208',1, null,'Home','http://www.lingerie-buyer.co.uk/','','',0),
   Array('7',1, null,'About us','/info/about_us.php','','',0),
   Array('68',1, null,'Contact us','/info/contact_us.php','','',0),
   Array('69',1, null,'Subscribe','/subscription.php','','',0),
   Array('70',1, null,'Terms and Conditions','http://lingerie-buyer.pressflex.com/news/fullstory.php/aid/37/Terms_and_Conditions','','',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>');
}

// 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://lingerie-buyer.pressflex.com/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://lingerie-buyer.pressflex.com/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://lingerie-buyer.pressflex.com/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://lingerie-buyer.pressflex.com/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';
