var NavMain_Active=null;
onLoadObj[onLoadObj.length]='NavMain_Init();';

function NavMain_Init(){
	var TNavMain=document.getElementById('TNavMain');
 	if(TNavMain && CurNavLevel[2]!=''){
 		var tL=getElementsByAttributeValue('nav2id',CurNavLevel[2],'a',TNavMain);
 		if(tL[0]){
 			NavMain_Active=tL[0].childNodes.item(0);
 			NavMain_Show(NavMain_Active, true,true);
		}
	}
	NavM4Init();
}

function NavMain_Show(img,on,active){
	var state='n';
	if(img){
		if(on){ 
			state='o';
			if(active || (NavMain_Active==img)) state='a';
		}else if (NavMain_Active==img) state='a';
		NavMain_ChangeImg(img,state);
	}
}
function NavLang_Show(img,on,active){
	var state='n';
	if(img){
		if(on){ 
			state='o';
			//alert(img==getElementsByAttributeValue('nav1id',CurNavLevel[1],'a')[0].childNodes[0]);
			if(active || img==getElementsByAttributeValue('nav1id',CurNavLevel[1],'a')[0].childNodes[0]) state='a';
		}else if (img==getElementsByAttributeValue('nav1id',CurNavLevel[1],'a')[0].childNodes[0]) state='a';
		NavMain_ChangeImg(img,state);
	}
}

function NavMain_ChangeImg(img,state){
	var SRC=img.src;
	img.src=SRC.substring(0,SRC.length-5)+state+SRC.substring(SRC.length-4,SRC.length);
	//alert(img.src);
}

function Nav_GetLocationAsString(lang){
	if(lang==null || lang=="") lang=CurNavLevel[1];
	if((CurNavLevel[2]!="loesungen" && CurNavLevel[2]!="home" && CurNavLevel[2]!="presse" && CurNavLevel[2]!="presse_detail" && CurNavLevel[2]!="feeds")||(CurNavLevel[2]=="presse" && CurNavLevel[3]!="" && CurNavLevel[4]!="")){
	var url='/'+lang+'/content_'+CurNavLevel[2];
	url += (CurNavLevel[3] !='') ? '_'+CurNavLevel[3] : '';
	url += (CurNavLevel[4] !='') ? '_'+CurNavLevel[4] : '';
	url += (CurNavLevel[5] !='') ? '_'+CurNavLevel[5] : '';
	url +='.php?lang='+lang;
	}
	else{
	var url="/"+(CurNavLevel[2]=="home"?"index":CurNavLevel[2]);
	url += (CurNavLevel[3] !='suche') ? '':'_'+CurNavLevel[3];
	url += '.php';
	url += '?lang='+lang;
	url+= (RequestParam('cid')!=null&&RequestParam('cid')!='')?'&cid='+RequestParam('cid'):'';
	url+= (RequestParam('Con4Open')!=null&&RequestParam('Con4Open')!='')?'&Con4Open='+RequestParam('Con4Open'):'';
	url+= (RequestParam('id')!=null&&RequestParam('id')!='')?'&id='+RequestParam('id'):'';
	}	
	url=escape(url);
//alert(url); 
	return url;
}

function Nav_SwitchLang(lang){
	var url=unescape(Nav_GetLocationAsString(lang));
	if(top!=self) {
		top.setTimeout('setrss("'+lang+'","'+url+'");',40); }
		else self.location.href=url;
}

function writeBackButton(win, title, klasse){
	if(!(history.length<=1)){
		if(CurNavLevel[3]!='' && !CurNavLevel['nolvl3'] && !win.document.referrer.match(/loc/gi)) {		
			win.document.write('<a href="javascript:history.back();" class="'+klasse+'">'+title+'</a>');
		}
		else{
			win.document.write('<a href="javascript:Nav_SwitchLang(\''+ (CurNavLevel[1]=='de' ? 'en' : 'de') + '\');" class="'+klasse+'">'+title+'</a>');
		}
	}
}

function Nav_SwitchVisual(id){	
	if(visualsList){
		var url=visualsList[id];		
		if((url==null || url=="") && !top.visualUrl && visualsList["home"]) url=visualsList["home"];				
		return url;
	}
}


// LEVEL 4 NAVIGATION, LOESUNGEN, CLOUDTAGS
var aktivN4=null;
var aktivN4Name=null;
var aktivN4NameTop=false;
var aktivN4Img=null;

var arrUp="/images/arrow_folder_up.gif";
var arrDown="/images/arrow_folder_down.gif";

function NavM4Init(){
	if(aktivN4Name!=null){
		showM4(aktivN4Name);
	}
}

function showM4(id,top){
	if(top){
		document.getElementById('home').focus();
	}
	if(aktivN4NameTop){
		aktivN4NameTop=false;
		document.getElementById('home').focus();
	}	
	var l=document.getElementById(id);
	var Img=document.getElementById('img'+id);
	if(l){
		if(aktivN4!=null){
			 showHideLyr(aktivN4,false);
			if(aktivN4Img!=null)  switchImg(aktivN4Img, arrUp);
		}
		if(aktivN4!=l){
			showHideLyr(l,true);
			if(Img) switchImg(Img, arrDown);
			aktivN4Img=Img;
			aktivN4=l;
		}else aktivN4=null;
	
	}
}
function showPartners(){
	if(CurNavLevel[2]=="loesungen")return true;
	return false;
}


function showM4MO(id, doShow){
	var l=document.getElementById(id);
	var Img=document.getElementById('img'+id);
	if(doShow){
		if(Img) switchImg(Img, arrDown);
	}else{
		if(Img)
			if(aktivN4Img!=Img)  switchImg(Img, arrUp);
	}
}


function showHideLyr(l,show){
	if(l)
		if(show){
			l.style.display="block";
			switchStyleClass(document.getElementById('Btn'+l.id.substr(3)),'Btn'+l.id.substr(3)+ ' aktivesloesungselement');
		}
		else{
			l.style.display="none";
			switchStyleClass(document.getElementById('Btn'+l.id.substr(3)),'Btn'+l.id.substr(3));
		}
}

function switchImg(img,src){
	if(img)
		img.src=src;		
}

//Android Windows Phone iPhone ?iPad? SIE- BlackBerry Windows CE HTC_Smart_F3188 LG- LGE- LG/ MOT- Symbian Series60 webOS
//SEC-SGHU600/1.0 SAMSUNG Opera Mini Bada SonyEricsson
var browserAndDevices    = {
/* ---- example
      //passende Infos an passender Stelle
      //seralisierung fürs Cookie fehlt allerdings
      'Iphone'        : {'uaCrit':'iphone', 'device' : {'mobil' : {'w' : 640, 'h' : 960}}}, 
      */
      'Iphone'        : {'uaCrit':'iphone', 'device' : {'mobil' : true}},
      'android'        : {'uaCrit':'android', 'device' : {'mobil': true}},
      'winPhone'        : {'uaCrit':'windows phone', 'device' : {'mobil': true}},
      'blackberry'    : {'uaCrit':'blackberry', 'device' : {'mobil': true}},
      'winCE'            : {'uaCrit':'windows ce', 'device' : {'mobil': true}},
      'symbian'        : {'uaCrit':'symbian', 'device' : {'mobil': true}},
      'siemens'        : {'uaCrit':'sie-', 'device' : {'mobil': true}},
      'samsung'        : {'uaCrit':'samsung', 'device' : {'mobil': true}},
      'motorola'        : {'uaCrit':'mot-', 'device' : {'mobil': true}},
      'sony ericsson'    : {'uaCrit':'sonyericsson', 'device' : {'mobil': true}},
      'series60'        : {'uaCrit':'series60', 'device' : {'mobil': true}},
      'webos'            : {'uaCrit':'webos', 'device' : {'mobil': true}},
      'LG'            : {'uaCrit': function (browser){
              return (String(browser.ua).search(/lg(e-|-|\/|;)/) > -1) ? true : false;
          }
          , 'device' : {'mobil': true}},
      'opera mini'    : {'uaCrit':'opera mini', 'device' : {'mobil': true}}, //Browser for mobiles
      'bada'            : {'uaCrit':'bada', 'device' : {'mobil': true}},
      'sec-sghu600'    : {'uaCrit':'sec-sghu600/1.0', 'device' : {'mobil': true}},
      'htc f3188'        : {'uaCrit':'htc_smart_f3188', 'device' : {'mobil': true}}
};
function writeCookie(name, value, milliSecs, path){
  var expires            = "";
  if(milliSecs){
      var date         = new Date();
      date.setTime(date.getTime()+(milliSecs));
      expires         = "; expires="+date.toGMTString();
  }
  document.cookie    = name+"="+value+expires+"; path="+path;
}

function readCookie(name){
  var    cookieVals    = String(document.cookie).split(";");
  for(var i=0; i<cookieVals.length;i++){
      if(String(cookieVals[i]).indexOf(name)>-1){
          return String(cookieVals[i]).substr(String(name+"=").length+1);
      }
  }
  return null;
}


browser                    = new Object();
browser.ua                = self.navigator.userAgent.toLowerCase();
browser.actual            = new Object();
browser.device            = new Object();
browser.fCache            = true;
browser.mobil            = null;
browser.mobilResolution    = null;
browser.mobilURL        = "http://www.generationdigitale.net";

browser.isByDeviceList    = function(label){
  var res    = null;
  if(res = this.is(browserAndDevices[label].uaCrit)){
      return browserAndDevices[label];
  }
  return res;
};

browser.is                = function(needles){
  if(typeof needles == "string"){
      if(browser.ua.indexOf(needles) > -1) return true;
          else return false;
  }else if(typeof needles == "object"){
      for(var i=0;i<needles.length;i++){
          if(browser.ua.indexOf(needles[i])==-1) return false;
      }
      return true; 
  }else if(typeof needles == "function"){
      return needles(browser);
  }
  return null;
};

browser.detect            = function(){
//  alert("readCookie mobil:"+readCookie('mobil')+' redirect:'+readCookie('redirected'));
  if(browser.mobilURL){
      if(readCookie('mobil') && this.fCache){
          this.mobil    = true;
          return true;
      }
      if(readCookie('redirected') === null || !this.fCache){
//          console.log("readCookie:"+readCookie('mobile'));
          //Ist die Resolution nicht richtig, gibt es keinen Redirect. Ansonsten wird auf Device geprüft
          if(this.setMobilResolution() === false){
//              var found        = null;
              for(var label in browserAndDevices){
                  if(this.actual = browser.isByDeviceList(label)){
//                      found                = true;
                      this.actual.label    = label;
                      break;
                  }
              }
              if(this.setDevice()){
                  writeCookie('mobil', 'true', false, "/");
              }else{
                  writeCookie('redirected', 'true', false, "/");
              }
          }
//          writeCookie('mobile', 'true', 1000*60*60*24*30, "/");
      }
  }
};

browser.setDevice        = function(){
  if(this.actual){
      if(this.actual.device){
          this.device    = this.actual.device;
      }
  }
  return this.setMobil();
};

browser.setMobil        = function(){
  if(this.actual){
      this.mobil    = new Boolean(this.device.mobil);
  }
  return this.mobil;
};

browser.setMobilResolution    = function(){
  this.mobilResolution    = (Math.max(window.screen.height, window.screen.width)<1024) ? true : false;
  return this.mobilResolution;
};

if(typeof browserAndDevices != "undefined"){
  browser.detect();
//  console.dir(browser);
//  alert('the end');
  if(browser.mobilURL && (browser.mobil || browser.mobilResolution)){
//      alert('redirect');
	 // onLoadObj.push("document.getElementById(\"visualcontainer\").style.display=\"none\";");
  }
}
