// The menu
//
// $Id: menu_en.js 18 2008-06-18 08:50:00Z eric $
// $LastChangedDate: 2008-06-18 10:50:00 +0200 (Mi, 18 Jun 2008) $

// {{{ MenuItem "class"
function MenuItem(strID, strParentID, strName, strUrl, strTarget) {
	this.strID = strID ;				// itemID
	this.strParentID = strParentID ;	// who is parent?
	this.strName = strName ;			// node name
	this.strUrl = strUrl ;				// where to go?
	this.strTarget = strTarget ;		// target of link
}
// }}} MenuItem
		
function WriteMenu(strParentID, menu, strPath, cur_item) {
	var iOffset 	= 0 ;				// position offset
	var curItem 	= strParentID ;		// curItem for "tree"
	var outBuffer	= new Array() ;		// final "tree"
	var strList 	= new Array() ;		// list of id's
	var strQuery	= location.search;	// da browsers query string
	
	// "stay-menu"-feature
	if ( (iPosition = strQuery.search(/area=/)) != -1 ) {
		strAfterArea = strQuery.substr(iPosition + 5) ;
		iSep = strAfterArea.search (/&/) ;
		
		if ( iSep != -1 )
			curItem = strQuery.substr(iPosition + 5, iSep) ;
		else
			curItem = strQuery.substr(iPosition + 5) ;
			
		strParentID = curItem ;
	}
	
	//strList.push(curItem) ;	// add first entry to "tree"-list
	strList[strList.length] = curItem ;
	
	// loop through items to find the position
	// of the last suitable entry
	for (var i = 0; i < menu.length; i++)
	{
		if (menu[i].strParentID == strParentID)
			iOffset = i ; // set position
		else if(iOffset != 0 && menu[i].strParentID != strParentID)
			break ; // leave loop if id's are different
	} // for
	
	// build first part of the final "tree"
	// "tree" from 0 to offset
	for (var i = iOffset; i >= 0; i--)
	{
		// item found => add to final "tree"
		if (menu[i].strParentID == curItem) {
			//outBuffer.push(menu[i]) ;
			outBuffer[outBuffer.length] = menu[i] ;
		} else if (menu[i].strID == curItem) {	
			// parent "node" found =>
			// change the curItem to its ID
			//outBuffer.push(menu[i]) ;
			outBuffer[outBuffer.length] = menu[i] ;
			curItem = menu[i].strParentID ;
			//strList.push(curItem) ;
			strList[strList.length] = curItem ;
		} // else if
	} // for
	
	// in order to "append" more items
	// to the final "tree" a reverse order
	// is needed!
	outBuffer.reverse() ; 
	
	// reverse "tree" list to get the right order
	strList.reverse() ;
	
	// the last - 1 item of the list is the
	// starting parentID of the second part
	// of the final "tree"
	curItem = strList[strList.length - 2] ;
	
	// build second part of the final "tree"
	// from offset + 1 to the end
	for (var i = iOffset + 1; i < menu.length; i++) {
		// entry belongs to parentID => add to buffer
		if (menu[i].strParentID == curItem) {
			//outBuffer.push(menu[i]) ;
			outBuffer[outBuffer.length] = menu[i] ;
		} else { // check if item is in "tree" list
			// loop through "tree"-list
			for (var j = 0; j < strList.length; j++) {
				if (strList[j] == menu[i].strParentID)
					//outBuffer.push(menu[i]) ;
					outBuffer[outBuffer.length] = menu[i] ;
			} // for
		} // else
	} // for
	
	// loop through the final "tree" and output
	// its items
	for (var i = 0; i < outBuffer.length; i++) {
		// calculate the intendt of each "node"
		for (var j = 0; j < strList.length; j++) {
			// item found => intend = j
			if (strList[j] == outBuffer[i].strParentID)
				break ;
		} // for
		
		// write the intend
		//for (k = 0; k <= j - 1; k++)
		//	document.write("&nbsp;&nbsp;&nbsp;") ;
			
		// build "tree node"
		if (j == 0 && i != 0) {
			document.write('<div class="menulink" style="border-top: 1px solid #FFFFFF;">') ;
		} else if (j == 0 && i == 0) {
			document.write('<div class="menulink">') ;
		} else if (j > 0) {
			document.write('<div class="menucelle-sublink">') ;
		}
		
		if (outBuffer[i].strUrl.indexOf('http') == 0) {
            document.write('<a href="' + outBuffer[i].strUrl + '" onfocus="this.blur()" target="_blank"');
        } else {
            document.write('<a href="' + strPath + outBuffer[i].strUrl + '" onfocus="this.blur()"');
        }
		if (cur_item == outBuffer[i].strID) {
			document.write(' style="color:#FFF;"');	
		}
		document.write('>') ;
		document.write(outBuffer[i].strName + "</a></div>") ;
	} // for
	document.write('<div class="menulink" style="border-top: 1px solid #FFFFFF;">&nbsp;</div>') ;
} // WriteMenu
		
var menu = new Array() ;

// {{{ Company
menu[menu.length] = new MenuItem("unternehmen", "menu", "Company", "unternehmen/index.html") ;
menu[menu.length] = new MenuItem("werIst", "unternehmen", "Who are we?", "unternehmen/wer_ist.html") ;
menu[menu.length] = new MenuItem("wasMacht", "unternehmen", "What do we do?", "unternehmen/was_macht.html") ;
menu[menu.length] = new MenuItem("woSteht", "unternehmen", "What do we stand for?", "unternehmen/wofuer_steht.html") ;
menu[menu.length] = new MenuItem("Geschichte", "unternehmen", "History", "unternehmen/geschichte/index.html") ;
/// }}} Company

// {{{ career
menu[menu.length] = new MenuItem("karriere", "menu", "Career", "career/index.html");
menu[menu.length] = new MenuItem("ausbildung", "karriere", "Vocational Training", "career/vocational-training/index.html");
menu[menu.length] = new MenuItem("praktika", "karriere", "Traineeships and Theses", "career/traineeship.html");
menu[menu.length] = new MenuItem("stipendium", "karriere", "BPW Study Grant", "career/study_grant.html");
// }}} career

// {{{ Products
menu[menu.length] = new MenuItem("produkte", "menu", "Products", "produkte/index.html") ;
menu[menu.length] = new MenuItem("nfzprog", "produkte", "for drawbar trailers and semi-trailers", "produkte/nfz/index.html") ;
menu[menu.length] = new MenuItem("agrarprog", "produkte", "for the agricultural industry", "../produkte_tl/index.php/bpw-agricultural-programme.html") ;
menu[menu.length] = new MenuItem("trailerprog", "produkte", "for caravans, industrial and towed maschinery, commercial trailers", "http://www.bpw-fahrzeugtechnik.de", "_blank") ;
// }}} Products

// {{{ Sales
menu[menu.length] = new MenuItem("vertrieb", "menu", "Sales", "vertrieb/index.html") ;
menu[menu.length] = new MenuItem("v_dland", "vertrieb", "HGV Range", "vertrieb/deutschland/index.html") ;
menu[menu.length] = new MenuItem("agrar", "vertrieb", "Agricultural Range", "vertrieb/aftermarket/team.html") ;
menu[menu.length] = new MenuItem("car trailer range", "vertrieb", "Car Trailer Range", "http://www.bpw-fahrzeugtechnik.de/vertrieb") ;
menu[menu.length] = new MenuItem("spedition", "vertrieb", "End-customer care", "vertrieb/technical-distribution/index.html") ;
menu[menu.length] = new MenuItem("grossflottenbetreuung", "vertrieb", "Fleet care int.", "vertrieb/grossflottenbetreuung/index.html");
menu[menu.length] = new MenuItem("aftermarket", "vertrieb", "Aftermarket", "vertrieb/aftermarket/index.html") ;
menu[menu.length] = new MenuItem("stellen", "vertrieb", "Worldwide", "../include/service-network/frontend/?locale=en") ;
// }}} Sales

// {{{ service
menu[menu.length] = new MenuItem("service", "menu", "Service", "service/index.html") ;
menu[menu.length] = new MenuItem("direct-service", "service", "Customer Service", "service/direct-service.html") ;
menu[menu.length] = new MenuItem("stellen_direct", "service", "BPW Service Network", "../include/service-network/frontend/?locale=en") ;
menu[menu.length] = new MenuItem("partner-service-package", "service", "Partner Service Package", "service/partner-service-package.html");
menu[menu.length] = new MenuItem("engineering", "service", "Engineering", "service/engineering.html");
menu[menu.length] = new MenuItem("logistics", "service", "Logistics concepts", "service/logistic-concepts.html");
menu[menu.length] = new MenuItem("registrations", "service", "Registrations", "service/registrations.html");
// }}} service

// {{{ purchase
menu[menu.length] = new MenuItem("purchase", "menu", "Purchase", "purchase/index.html");
menu[menu.length] = new MenuItem("products_overview", "purchase", "Purchasing programme", "purchase/programme/index.html");
menu[menu.length] = new MenuItem("become_distributor", "purchase", "Become supplier", "purchase/become-supplier.html");
menu[menu.length] = new MenuItem("request_distribution", "purchase", "Supplier questionnaire", "purchase/supplier-questionnaire.php");
menu[menu.length] = new MenuItem("conditions", "purchase", "General terms and conditions of business", "purchase/terms-and-conditions.html");
menu[menu.length] = new MenuItem("signGoods", "purchase", "Transport label specifications", "purchase/transport-label/index.html");
menu[menu.length] = new MenuItem("initial_sample", "purchase", "Initial Samples", "purchase/initial-samples.html");
menu[menu.length] = new MenuItem("report", "purchase", "8D-Report", "purchase/8d-report.html");
menu[menu.length] = new MenuItem("deviation_request", "purchase", "Deviation request", "purchase/deviation-request.html");
menu[menu.length] = new MenuItem("purchase_contact", "purchase", "Contact", "purchase/contact.html");
// }}} purchase

// {{{ latest news
menu[menu.length] = new MenuItem("aktuell", "menu", "Latest News", "aktuell/index.html") ;
menu[menu.length] = new MenuItem("bpwnews", "aktuell", "BPW NEWS", "download/news/index.html?area=aktuell") ;
/*menu[menu.length] = new MenuItem("new_products", "aktuell", "New Products", "../ecoplus2/uk/index.html?area=aktuell") ;*/
menu[menu.length] = new MenuItem("messen", "aktuell", "Exhibitions", "aktuell/messen.html") ;
menu[menu.length] = new MenuItem("trailerworld", "aktuell", "trailer world", "aktuell/trailerworld/index.html");
menu[menu.length] = new MenuItem("trailermanager", "aktuell", "Trailer software", "../index.php/trailermanager?locale=en");
// }}} latest news

// {{{ press
menu[menu.length] = new MenuItem("press", "menu", "Press", "press/index.html") ;
menu[menu.length] = new MenuItem("pr_contact", "press", "PR contact", "press/contact/index.html") ;
menu[menu.length] = new MenuItem("facts", "press", "Facts about BPW", "press/facts/index.html") ;
menu[menu.length] = new MenuItem("press-releases", "press", "Press releases", "press/press-releases/index.html") ;
menu[menu.length] = new MenuItem("visuals", "press", "Visuals", "press/visuals/index.html") ;
menu[menu.length] = new MenuItem("press-archive", "press", "Press archive", "press/press-archive/index.html") ;
menu[menu.length] = new MenuItem("messen", "press", "Appointments / Exhibitions", "aktuell/messen.html") ;
// }}} press

// {{{ download
menu[menu.length] = new MenuItem("download", "menu", "Downloads", "download/index.html") ;
menu[menu.length] = new MenuItem("bpw_news", "download", "BPW NEWS", "download/news/index.html") ;
menu[menu.length] = new MenuItem("abe", "download", "Test Reports", "download/test-reports/index.html") ;
menu[menu.length] = new MenuItem("trailermanager", "download", "Trailer software", "../../index.php/trailermanager?locale=en") ;
menu[menu.length] = new MenuItem("formulare", "download", "Forms", "download/formulare/index.html") ;

// }}} download

// {{{ contact
menu[menu.length] = new MenuItem("contact", "menu", "Contact", "kontakt/index.html") ;
menu[menu.length] = new MenuItem("wiehl", "contact", "Wiehl", "kontakt/index.html") ;
menu[menu.length] = new MenuItem("germany", "contact", "Germany", "kontakt/germany.html") ;
menu[menu.length] = new MenuItem("worldwide", "contact", "Worldwide", "kontakt/worldwide.html") ;
menu[menu.length] = new MenuItem("k_request", "contact", "Request", "kontakt/request.html") ;
// }}} contact