/*
         ___                         _____       __
        /  /\        ________       /    /\     / /\
(-----//  /  \//----/_____/__\\--) /____/  \___/_/ //--------------------------)
      /  /   /      \     | //     \    \  /    /\/    this code was created by
     /__/   /        \    |///-----\\____\/____/  \                       sigea
(---\\  \  /   (-----\\___|/        /    /\    \  /       
      \__\/                        /____/ /\____\/            __       sigea.ch
                                   \____\/  \  /             /\_\--------------)
                                         \___\//-------------\/_/  

*/
var navigation;
if(!formAlert){
var formAlert= new Object();
	formAlert['logoff']='Willst Du wirklich ausloggen?';
}
function Navigation(){
	var idName='navigation';
	var interval=59000;
	var adInterval=120000;
	var xhr,t,adT,id;
	this.prepare=function(){
		if(document.getElementById(idName)){
			var navi=document.getElementById(idName);
			var links=navi.getElementsByTagName('a');
			for(var i=0; i< links.length; i++) {
				if(links[i].className){
					if(links[i].className.indexOf('logoff') != -1){
						links[i].onclick = function(){
							return navigation.confirmLogoff();
						};
						id=links[i].href.substring((links[i].href.indexOf('id=')+3));
						xhr=new Hijax();
						t=setTimeout(getNavigationInfo,interval);
					}else{
						links[i].onclick = function(){
							return !navigation.open(this);
						};
					}
				}
			}
//			adT=setTimeout(getNewAd,adInterval);
			//getNewAd();
			links=null;
		}
	};
	this.confirmLogoff=function(){
		return confirm(formAlert['logoff']);
	}
	this.open=function(element){
		var windowname='';
		var options='scrollbars=1,resizable=1,';
		if(element.className.indexOf('help') != -1){
			windowname='swisstalkHilfe';
			options+='width=800,height=670';
		}else if(element.className.indexOf('rechtliches') != -1){
			windowname='swisstalkRechtliches';
			options+='width=800,height=670';
		}else if(element.className.indexOf('support') != -1){
			windowname='Support';
			options+='width=800,height=670';
		}	
		var newWin=window.open(element.href,windowname,options);
		newWin.focus();
		return true;
	};
	var getNavigationInfo=function(){
		if(t)
			clearTimeout(t);
		var url='../navigationXhr/?id='+id;
		xhr.setUrl(url);
		xhr.setCallback(function(request){
			if(request.responseText!='' && request.responseXML.getElementsByTagName('body').length==1){
				var divs=request.responseXML.getElementsByTagName('div');
				removeClass(document.getElementById('mailbox-tab'),'info');
				removeClass(document.getElementById('news-tab'),'info');
				for(var i=0; i<divs.length; i++){
					if(divs[i].getAttribute('class')!=''){
						//alert(divs[i].getAttribute('class'));
						//alert(divs[i].lastChild.nodeValue);
						if(document.getElementById(divs[i].getAttribute('class')+'-tab')){
							var spans=document.getElementById(divs[i].getAttribute('class')+'-tab').getElementsByTagName('span');
							while(spans[spans.length-1].hasChildNodes()){
								spans[spans.length-1].removeChild(spans[spans.length-1].lastChild);
							}
							spans[spans.length-1].appendChild(document.createTextNode(divs[i].lastChild.nodeValue));
							addClass(document.getElementById(divs[i].getAttribute('class')+'-tab'),'info');
							spans=null;
						}
					}
				}
				divs=null;
			}
			request=null;
		});
		xhr.captureData();
		t=setTimeout(getNavigationInfo,interval);
		return true;
	};
	var getNewAd=function(){
		if(adT)
			clearTimeout(adT);
		var adObjects=document.getElementById('headerwrapper').getElementsByTagName('object');
		if(document.all){
			var tmp;
			for(var i=0; i<adObjects.length; i++){
				//adObjects[i].document.location.reload();
				tmp=adObjects[i].cloneNode(true);
				purge(adObjects[i]);
				adObjects[i].parentNode.replaceChild(tmp,adObjects[i]);
			}
			tmp=null;
		}else{
			for(var i=0; i<adObjects.length; i++){
				adObjects[i].contentDocument.location.reload();
			}
		}
		adObjects=null;
		adT=setTimeout(getNewAd,adInterval);
	};
}

function prepareNavigation(){
	navigation=new Navigation();
	navigation.prepare();
}
loadEvent.add(prepareNavigation);