propExpanded = 'hideItems';
    propContracted = 'showItems';
    id = 'toggleMenu';

    subItem1 = Array('Der Zauber Nepals','Reiseinformationen','Programmes','Flössen','Hotel Reservation','Trekking','Wildlife');
    subItem1Link = Array('Der Zauber Nepals.htm','Reiseinfo.htm','suggestedprogramm.htm','Flossen.htm','hotelreservation.htm','trekking.htm','#')
	
	subItem2 = Array('Programmes');
	subItem2Link = Array('bhutanprogramm.htm');
	
    subItem3 = Array('Reiseinformationen','Programmes');
	subItem3Link = Array('tibetinfo.htm','tibetprogramm.htm');
	
    subItem4 = subItem2;
	subItem4Link = Array('sikkimprogramm.htm');
	
    subItem5 = Array();
	subItem5Link = Array('#','#');
	
    subItem6 = Array();
	subItem6Link = Array('#','#');
	
    subItem7 = Array();
	subItem7Link = Array('#','#');

    subItems = Array(subItem1, subItem2, subItem3, subItem4, subItem5, subItem6, subItem7);
	subItemLinks = Array(subItem1Link, subItem2Link, subItem3Link, subItem4Link, subItem5Link, subItem6Link, subItem7Link);
    items = Array('Nepal','Bhutan','Tibet','Sikkim and Darjeeling','Inquiry','Die zahlende Gäste','Kontakt');
	
	noSubItemLinks = Array('#','payingguest.htm','contactus.htm');
	
	linkClass = 'rightnav';
	innerSubItemClass = 'inner';
	innerLinkClass = 'innerlink';
		
	itemStyle = new Object();
	subItemStyle = new Object();
	linkStyle = new Object();
	
	itemStyle['height'] = '25';
	itemStyle['background'] = 'url(../images/kettours_10.gif)';
	itemStyle['valign'] = 'middle';
	itemStyle['paddingleft'] = '15';
	
	subItemStyle['background'] = 'url(../images/kettours_19.gif)';
	subItemStyle['paddingleft'] = '20px';
	
	linkStyle['fontsize'] = '11px';
	
		
function init()
{
    tblObj = getTableObject(id);
	j = 0;
	
	for(i = 0; i<items.length; i++){
	    addRow(tblObj, i);
		cellObj = addCell(tblObj, i, 0);
		if( i >= 4 )
		    addContents( tblObj, i, 0, items[i].link(noSubItemLinks[j++]) );
		else
		    addContents( tblObj, i, 0, items[i].link('javascript:showItems(' + i + ',' + 0 + ',' + i + ')') );
			
		
		for( attr in itemStyle ){
		    setStyle(cellObj, null, attr, itemStyle[attr], false, true);
		}
		
		for( attr in linkStyle ) setStyle(cellObj.firstChild, linkClass, attr, linkStyle[attr], true, true);
	}
}

	
	
	function setStyle( obj, namedClass, namedStyle, styleValue, hasClass, hasStyle )
	{
	    if(hasClass)
		    obj.className = namedClass;
		if(hasStyle){
		    switch(namedStyle){
			    case 'background' :
				    obj.style.backgroundImage = styleValue;
					break;
					
				case 'paddingleft' :
				    obj.style.paddingLeft = styleValue;
					break;
					
				case 'align' :
				    obj.style.textAlign = styleValue;
					break;
					
				case 'valign' :
				    obj.style.vAlign = styleValue;
					break;
					
				case 'height' :
				    obj.style.height = styleValue;
					break;
					
				case 'fontsize' :
				    obj.style.fontSize = styleValue;
					break;
					
				case 'fontsize' :
				    obj.style.fontSize = styleValue;
					break;
					
				case 'borderwidth' :
				    obj.style.borderWidth = styleValue;
					break;
					
				case 'borderstyle' :
				    obj.style.borderStyle = styleValue;
					break;
					
				case 'bordercolor' :
				    obj.style.borderColor = styleValue;
					break;
			}
			
		}
			
	}
	
	
	
function showItems(rowIndex, cellIndex, itemIndex)
{
    tblObj = getTableObject(id);
	innerTable = createTableObject();
	//innerTable.setAttribute('border','1');
	innerTable.setAttribute('width','85%');
	setStyle(innerTable, innerSubItemClass, null, null, true, false);
	
	
	//if(subItems[itemIndex].length == 0 ) return;
	
	addRow(tblObj, rowIndex + 1);
	cellObj = addCell(tblObj, rowIndex + 1, 0);
	cellObj.appendChild(innerTable);
	
	for( attr in subItemStyle )  setStyle(cellObj, null, attr, subItemStyle[attr], false, true);
		
	for(i=0;i<subItems[itemIndex].length;i++){//alert(subItems[itemIndex].length);
		addRow(innerTable, i);
		cellObj = addCell(innerTable, i, 0);
		addContents(innerTable, i, 0, '<a href="'+subItemLinks[itemIndex][i]+'" class="'+ innerLinkClass +'">'+subItems[itemIndex][i]+'</a>');
	}
	//alert(itemIndex);
	if((obj = tblObj.rows[rowIndex].cells[0]).hasChildNodes()){
		strHref = obj.firstChild.getAttribute('href');
		funcName = getFunctionName(strHref);
		
		if(funcName === propContracted){
		    funcName = propExpanded;
			newFuncName = setFunctionName(funcName, strHref);
			obj.firstChild.setAttribute('href',newFuncName);
			
			revalidateLinks(rowIndex, itemIndex, 'down');
		}	
		else
		    return;
	}	
}

function hideItems(rowIndex, cellIndex, itemIndex)
{
    tblObj = getTableObject(id);
	removeRow(tblObj, rowIndex + 1);
	
	if((obj = tblObj.rows[rowIndex].cells[cellIndex]).hasChildNodes()){
		strHref = obj.firstChild.getAttribute('href');
		funcName = getFunctionName(strHref);
		
		if(funcName === propExpanded){
		    funcName = propContracted;
			newFuncName = setFunctionName(funcName, strHref);
			obj.firstChild.setAttribute('href',newFuncName);
			
			revalidateLinks(rowIndex, itemIndex, 'up');
		}	
		else
		    return;
	}	
}


function isItem(rowObj)
{
    strHref = rowObj.cells[0].firstChild.getAttribute('href'); //alert(strHref);
	if(strHref == null)
	    return false;
	else
	    funcName = getFunctionName(strHref);
	
	if(funcName == propExpanded || funcName == propContracted)
	    return true;
	return false;
}

function revalidateLinks(rowIndex, itemIndex, direction)
{
    tblObj = getTableObject(id);
	rowlen = tblObj.rows.length;
	
	for(i = rowIndex+1; i<rowlen-noSubItemLinks.length; i++){
	    if(isItem(rowObj = tblObj.rows[i])){
		    parms = getParms(rowObj.cells[0].firstChild.getAttribute('href'));
			parts = parms.split(',');
			newRowIndex = parts[0];
			newRowIndex = direction == 'down' ? parseInt(newRowIndex) + 1 : parseInt(newRowIndex) - 1;
			cellIndex = parts[1];
			newLinkHref = setParms( newRowIndex + ',' + cellIndex + ',' + (++itemIndex), rowObj.cells[0].firstChild.getAttribute('href') );
			rowObj.cells[0].firstChild.setAttribute('href', newLinkHref);
		}
	}
	
	
}

function getFunctionName(strHref)
{
    openingIndex = strHref.indexOf(':',0);
	closingIndex = strHref.indexOf('(',0);
	funcName = '';
	index = openingIndex ;
	while( ++index != closingIndex)
	    funcName += strHref.substr(index,1);
		
	return funcName;
}

function setFunctionName(newFuncName, strHref)
{
    openingIndex = strHref.indexOf(':',0);
	closingIndex = strHref.indexOf('(',0);
	
	newlinkHref = strHref.substr(0, openingIndex + 1) + newFuncName + strHref.substr(closingIndex,strHref.length-1);
	return newlinkHref;
}

function getParms(strHref)
{
    openingIndex = strHref.indexOf('(',0);
	closingIndex = strHref.length - 1;
	parms = '';
	index = openingIndex ;
	while( ++index != closingIndex)
	    parms += strHref.substr(index,1);
		
	return parms;
	
}

function setParms(strParm, linkHref)
{
    openingIndex = linkHref.indexOf('(',0);
	closingIndex = linkHref.length - 1;
	
	newlinkHref = linkHref.substr(0, openingIndex + 1) + strParm + linkHref.substr(closingIndex,1);
	return newlinkHref;
}

function createTableObject()
{
    innerTable = document.createElement('table');
	if(innerTable)
	    return innerTable;
	return null;
}

function getTableObject(id)
{
    if(document.getElementById(id))
	    return document.getElementById(id);
	return null;
}


/****************************** begin of private functions *******************************/
/*****************************************************************************************/


function addRow(tableObj, index)
    {
        //alert(index);//lastIndex = tableObj.rows.length;
	    tableObj.insertRow( index );
	
	    if(tableObj.rows[index])
	        return true;
	    return false;
    }


    function addCell(tableObj, rowIndex, cellIndex)
    {
        rowObj = tableObj.rows[rowIndex];
	    cellObj = rowObj.insertCell(cellIndex);
	
	    if( rowObj.cells[cellIndex] )
	        return cellObj;
	    return false;
    }

    function addContents(tableObj, rowIndex, cellIndex, value)
    {
        rowObj = tableObj.rows[rowIndex];
	    cellObj = tableObj.rows[rowIndex].cells[cellIndex];
	    cellObj.innerHTML = value;
	
	    if(cellObj.innerHTML)
	        return true;
	    return false;
    }

    function removeCell(tableObj, rowIndex, cellIndex)
    {
        rowObj = tableObj.rows[rowIndex];
	    cellObj = rowObj.deleteCell(cellIndex);
	
	    if(rowObj.cells[cellIndex] == null)
	        return true;
	    return false;
    }

    function removeRow(tableObj, rowIndex)
    {
        tableObj.deleteRow(rowIndex);
	
	    if( tableObj.rows[rowIndex] == null)
	        return true;
	    return false;
    }
