/* NWP javascript */

// init
window.onload = init;
window.onresize = resizeInit;

function fixObjects() {
	theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

function startSlideshow() {
  // load images slideshow
  getslides('slideShow');
  runSlides();
}

function init() {
	startSlideshow();
	fixObjects();
	resizeInit();
}

function resizeInit() {
  // initiate variables for switching wrapper id name
  var sw = 990;
  var ws = "wrapperSmall";
  var wl = "wrapperLarge";
  var we = document.getElementsByTagName('BODY')[0].getElementsByTagName('DIV')[0];
  // set wrapper id
  sPW(sw,ws,wl,we);
}

function setAdvanced(t){
  var myEl=document.getElementById(t);
  var elm=document.getElementById('searchOptions');
  if (myEl.checked==true)elm.style.display='none';
  myEl.onclick = function(){
    elm.style.display=(elm.style.display=='none')?'block':'none';
  }
}

function checkAll(t){
  var el=document.getElementById(t);
  var e=fpd(el,'UL');
  var i = e.getElementsByTagName('INPUT');
  el.onclick=function(){
    this.checked = (this.checked) ? true : false;
    for(n=0;n<i.length;n++){
      if(i[n]==this)continue;
      if(!i[n].checked)i[n].checked=true;
    }
  }
  for(n=0;n<i.length;n++){
    if(i[n]==el)continue;
    i[n].onclick=function(){
      if(!this.checked)el.checked=false;
    }
  }
}

// setting the wrapper width by setting it's ID name 
function sPW(sw,ws,wl,we){
  var s = new gMS();
  we.id = ( s.w > sw ) ? wl : ws;
}


// returns web client window width and height [crossbrowser]
function gMS(w,h){
  if( typeof( window.innerWidth ) == 'number' ) {
    this.w = window.innerWidth; 
    this.h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    this.w = document.documentElement.clientWidth; 
    this.h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    this.w = document.body.clientWidth; 
    this.h = document.body.clientHeight;
  }
}


//------------------------------------------------------
// Toggle scripts

// Zappwerk menu
var o="open";
var c="closed";
function zappMenu(el,t){
  var t = ( t=="" || t==undefined || t==null ) ? 'LI' : t
  var e = fpd(el,t);
  var u = fpd(e,'UL');
  var l = u.getElementsByTagName('LI');
  for(n=0;n<l.length;n++){
    l[n].id=(u.id)+n;
    if (l[n].className.indexOf(c)>-1) {
      switchClassName(e,c,c);
    }
  }
  var eul = e.getElementsByTagName('UL')[0];
  if (eul){
    e.onmouseover = function(){
      switchClassName(e,c,o);
      eul.style.zIndex="300"
    }
    e.onmouseout = function(){
      setTimeout("switchClassName(document.getElementById('"+e.id+"'),o,c)", 0)
      eul.style.zIndex="0"
    }
  }
}

// Zappwerk toggle
function zappToggle(el,t){
  var t = ( t=="" || t==undefined || t==null ) ? 'LI' : t
  var e = fpd(el,t);
  var u = fpd(e,'UL');
  var l = u.getElementsByTagName('LI');
  for(n=0;n<l.length;n++){
    l[n].id="menu"+n;
    if (l[n].className.indexOf(o)>-1) {
      switchClassName(e,o,c);
    }else{
      if (l[n].className.indexOf(c)>-1) {
        switchClassName(e,c,o);
      }
    }
  }
}

// End Toggle scripts
//------------------------------------------------------

//------------------------------------------------------
// Jump to the next input 'elm' after 'n' chracters

function jumpTab(elm,n){
  if (elm.value.length>=n){
    var pe=fcd((fsd((fpd(elm,'DIV')),'DIV')),'INPUT');
    pe.focus();
  }
}
//------------------------------------------------------

//------------------------------------------------------
// Classname & node handlers

function addCSSClass(elem,cn){elem.className=(elem.className+" "+cn).trim();}
function removeCSSClass(elem,cn){elem.className=elem.className.replace(cn,"").trim();}
String.prototype.trim=function(){return this.replace( /^\s+|\s+$/, "" );}
function switchClassName(e,a,b){e.className=e.className.replace(a,"").trim();e.className=(e.className+" "+b).trim();}
function fpd(elem,e){var o=elem;while(o.parentNode.nodeName!=e.toUpperCase()){o=o.parentNode;}return o.parentNode;}
function fps(elem,e){var o=elem;while(o.previousSibling.nodeName!=e.toUpperCase()){o=o.previousSibling;}return o.previousSibling;}
function fns(elem,e){var o=elem;while(o.nextSibling.nodeName!=e.toUpperCase()){o=o.nextSibling;}return o.nextSibling;}
function fcd(elem,e){var o=elem;if(o.firstChild.nodeName==e.toUpperCase()){return o.firstChild;}else{while(o.nextSibling.nodeName!=e.toUpperCase()){o=o.nextSibling;}return o.nextSibling;}}

// End Classname & node handlers
//------------------------------------------------------


//------------------------------------------------------
// Images slider functions

var detect = navigator.userAgent.toLowerCase();
var WinIE;
if (checkIt('msie')) WinIE = true;
if (checkIt('opera')||checkIt('mac')) WinIE = false;

function checkIt(string){
	place = detect.indexOf(string) + 1;
	return place;
}

var timer, numberOfPictures, slide;
var counter = 0
var pic = new Array()
var fadeTime = 3
var viewingTime = 4000

function getslides(containerID){
  slide = document.getElementById(containerID)
  if (slide){
    pic = slide.getElementsByTagName('IMG');
    numberOfPictures = pic.length
    if (numberOfPictures<=0) return;
    slide.style.backgroundImage='url('+pic[0].src+')';
  }  
}

function runSlides(){
  if (numberOfPictures<=0) return;
  if (slide){
    if (WinIE){
      slide.style.filter="blendTrans(duration=fadeTime)"
      slide.filters.blendTrans.Apply()      
    }
    slide.style.backgroundImage='url('+pic[counter].src+')';
    if (WinIE){
      slide.filters.blendTrans.Play();
    } 
    counter++;
    if (counter > (numberOfPictures-1)) counter=0; 
    timer = setTimeout('runSlides()', viewingTime);
  } else {
      return;
  }
}

// End Images slider functions
//------------------------------------------------------


//  EOF