
/****
 * Handle click functionality of menu items, header (home) & videos.
 * Set active menu item (highlight)
 */
function menuClick(event) {
	// stop bubbling (prevent this envent is called twice) 
	event = event || window.event; // IE
	event.stopImmediatePropagation();
	
	// retrieve title of link so we can compare with php file
	var lastPage = $.bbq.getState('page');
	var page = $(this).attr("load");
	var id = $(this).attr("id");
	
	// prevent from loading the same site 
	if (page == $.bbq.getState('page')) {
			var lastId = $.bbq.getState('id');
			if(lastId == 0) { return; }
			if (convertServicePageToId(id) == lastId) { return; }
	}
		
	loadContent(page, id);

	// set active menu item
	hightlightMenuItem(page);
}


/****
 * Convert text id of selected service to id of service
 */
function convertServicePageToId(textId) {
	return serviceTextId[textId];
}

/****
 * Convert text id of selected service to id of service
 */
function convertServiceIdToPage(Id) {
	return serviceIdText[Id];
}


/****
 * Hightlight the active menu and submenu item.
 * If submenu has been clicked, parent menu item is highlighted as well.
 *
 ****/
function hightlightMenuItem(page, id) {
/*
	// get menu item: which load attribute equals parameter page?
	if (!page) { page = "home"; } // page is undefined
	var tmp = '[load=' + page + ']';
	var activate = $('#menucontent').find(tmp);
	// convert subpage (id) of services to page
	if (page == 'service') { page = convertServiceIdToPage(id); } 
*/	
	
	page = $.bbq.getState('page');
	id = $.bbq.getState('id');
	var tmp = '[load=' + page + ']';
	
	// special: service menu items are different
	// page is service, id is number and can be converted to the needed page identifier for switch-command
	if (page == "service") {
		page = convertServiceIdToPage(id);
		tmp = '[id=' + page + ']';
	}
	
	var activate = $('#menucontent').find(tmp);	
	
	// deactivate last active items
	$('.menu_item.active').removeClass('active');
	$('.submenu_item.active').removeClass('active');
	
	// activate new item(s)
	switch(page) {
		// company highlight submenu hid automatically
		case "company":
		case "hid":
			$('.menu_item#company').addClass('active');
			$('.submenu_item#hid').addClass('active');
			break;
		// company/*			
		case "agency":
		case "awards":
		case "customers":
		case "jobs":
			$('.menu_item#company').addClass('active');
			activate.addClass('active');
			break;
		// services/*
		case "research":
		case "concept":
		case "design":
		case "evaluation":
		case "development":
		case "strategy":
			$('.menu_item#services').addClass('active');
			activate.addClass('active');
			break;
		// case
		case "case":
			$('.menu_item#case_studies').addClass('active');
			break;
		// all other pages
		default: 
			activate.addClass('active');
	}	
}


/****
 * Show or hide menu and sub menu
 * @param page	just loaded page. Decide about menus are shown or not
 */
function fadeInOutMenus(page) {
	var speed = fadeInSpeed;
	
	// show or hide menu and sub menu
	switch(page) {
		// company/*
		case "awards":		
		case "company":
		case "competences":
		case "customers":		
		case "hid":
		case "jobs":
		// case ...
			fadeInContent($('.menu'), speed);
			fadeOutContent($('#submenu_service'));
			fadeInContent($('#submenu_company'), speed);
			break;
		case "video":
			fadeOutContent($('.menu'), speed);
			fadeOutContent($('#submenu_company'));
			fadeOutContent($('#submenu_service'));
			break;
		// service/* are handled via id from dbase, so page is always service
		case "service":
			fadeInContent($('.menu'), speed);
			fadeOutContent($('#submenu_company'));
			fadeInContent($('#submenu_service'), speed);		
			break;
		// all other pages
		default: 
			fadeOutContent($('.submenu'));
			fadeInContent($('.menu'), speed);
	}	
}


