var myhref="";


function changeNavigation(thref){
	
//	alert(thref);
	if (thref.match('#')!=-1) {
		myhref=thref;
//		if (thref.match('#')==0) {
//		  myhref=document.location.pathname+thref;
//		}
//		alert(myhref);
		initNavigation();
		myhref='';
	}
	
}

function initNavigation() {
	var content=document.getElementById("mycontent");
	var text = '';//content.innerHTML;

   // set true for debugging output
		debug = false;
	
	
	// if (debug)
	 // content.innerHTML+="<p>HalloWelt</p>";
	text += "<p>"
		  

// 	document.write('Hallo Welt<br>');
// 	url =document.URL;
	url = window.location.href;
	if (myhref!="")
   	   url = myhref;
// 	document.write(url,'<br>');
	text+='URL : '+url+'<br>';
	
	var navbar=document.getElementById("navbar");
	if (navbar!=null) {
		// get list items of "navbar"
		items=navbar.getElementsByTagName("li");
	
		xselected=null;
		aselected=null;
	
		for(i=0; i<items.length;++i) {
			x=items[i];
			a=x.getElementsByTagName("a");
			d=x.getElementsByTagName("div");
			if (a.length>0) {
				href=a[0].getAttribute('href'); //attributes['href'].nodeValue;
				if (a[0].getAttribute('class')=='active') a[0].removeAttribute('class','active');
				if (href.match('#') && a[0].getAttribute('onclick')==null)		
				  a[0].setAttribute('onclick',"changeNavigation(this.getAttribute('href'));");
				// find active link
				if (url.match(href)!=null && href!='#') {
					// unreveal sublink if existing
					text+='<p>found:'+href+'</p>';
					aselected=a[0];
					if (d.length>0) {
						d[0].setAttribute('class','subnavbar active');  //subnavbar.active
				//		document.write('divset:',d[0].attributes['id'],'<br>')
					   aselected.style.color='red';
					}
					else {
					  aselected.style.color=null;
					}
					
					if (x.attributes['class']!=null) {
						x.removeAttribute('class');
					}
					xselected=x;
				}
				else if  (url.match(href)==null){ 
					if (x.attributes['class']!=null) 
						x.removeAttribute('class');	
						a[0].style.color=null;
					if (d.length>0 && d[0].attributes['class']!=null) {
					    aclass=d[0].attributes['class'];
						if (aclass!='subnavbar') 
							d[0].setAttribute('class','subnavbar');	
							d[0].style.display='none';
							//d[0].disable=true;
					}		
				}
			}
		}
		if (xselected) {
			xselected.setAttribute('class','active');
		}
		if (aselected) {
			aselected.setAttribute('class','active');
//			aselected.style.weight='bold';
			aselected.style.color='red';
//			aselected.innerHTML+='OK';
			if (debug) {
				text+='<p>selected:'+aselected.innerHTML+'</p>';
			}	
		}
	}
	text+='</p>';

	if (debug)
	  content.innerHTML+=text;
	
	try {
	   //content.innerHTML+='<p>before</p>';
	   writeFooter();
	   //content.innerHTML+='<p>after</p>';
	}
	catch (err) {
	   if (err instanceof ReferenceError) 
	   { }
	   else 
       	   throw err;
	}
}

// based on "Dynamic Resolution Dependent Layout Demo"
// by Author : Kevin Hale
// URL : http://particletree.com
function changeLayout(description){

   var content=document.getElementById("mycontent");
  var i;
  var links = document.getElementsByTagName("link");
   for(i=0; i<links.length ; i++){
	  var a = links[i]
//      if (a.getAttribute("title") =='showNavi' || a.getAttribute("title") =='hideNavi'  ) {
	  list={};
	  list['showNavi']='showNavi';
	  list['hideNavi']='hideNavi';
      if (a.getAttribute("title") in list  ) {
           if(a.getAttribute("title") == description){ 
             a.disabled = true;  // needed for 
             a.disabled = false;
// *debug*             content.innerHTML+='<p>'+description+' enabled</p>';
           }
           else { 
              a.disabled = true;
// *debug*              content.innerHTML+='<p>No: '+description+':'+a.getAttribute("title")+' disabled</p>';
           }
       }
   }
   var validator =document.getElementById("validator");
  /*    var footer =document.getElementById("myfooter"); */
/*   content.innerHTML+='<p>'+description+' called</p>'; */
   if (validator) {
/*   	content.innerHTML+='<p>found validator</p>'; */
      if (description=='hideNavi') 
         validator.style.display = 'none';
      else 
              validator.style.display = 'block';
    }
}


