


//power animator dev 1.2, mDI, march 2006, adds partial clipping
var animTimer = [];
animate = function (oArg){
  clearTimeout(animTimer[oArg.timerName]);
  var cD,cS,pS,pD
  cD = !oArg.currDist ? 0 : oArg.currDist;
  cS = !oArg.currSpeed ? 0 : oArg.currSpeed;
  cS = !oArg.currSpeed && !oArg.easeIn ? oArg.speed : cS;
  pS = !oArg.peakSpeed ? oArg.speed : oArg.peakSpeed;
  if (oArg.peakDist){
    pD = oArg.peakDist;
  }
  else { 
    pD = oArg.easeIn && oArg.easeOut ? parseInt((oArg.dist)/(oArg.easeIn+oArg.easeOut)*oArg.easeIn) : 0;
  }
  if (cD >= pD && oArg.easeOut){
    cS = parseInt(((oArg.dist-cD)+((oArg.speed-cS)/2))/(oArg.easeOut+0.5)+1);
    if (cS > pS){
      cS = pS;
    }
  }
  else if (oArg.easeIn){
    cS = parseInt((cD+((oArg.speed-cS)/2))/(oArg.easeIn-0.5)+1);
    if (cS > oArg.speed){
      cS = oArg.speed;
    }
  }
  if (cD+cS > oArg.dist){
    cS = oArg.dist-cD;
  }
  cD += cS;
  for (var i in oArg.elements){
    var o = oArg.elements[i];
    var currPosition = o.negMove ? o.startPos-cD : o.startPos+cD;
    if (o.style == 'clip'){
      if (o.clipType == 'vertFromCenter'){
        var d = 'rect(' + (o.maxHeight - currPosition) + 'px, ' + o.clipRight + 'px, ' + currPosition + 'px, 0)' ;
        getEl(o.id).style[o.style] = d;
      }
    }
    else {
      getEl(o.id).style[o.style] = currPosition + 'px';
    }
  }
  if (cD < oArg.dist){
    oArg.currDist = cD;
    oArg.currSpeed = cS;
    oArg.peakDist = pD;
    oArg.peakSpeed = pS;
    animTimer[oArg.timerName] = setTimeout(function(){animate(oArg)},25);
    return;
  }
  if (oArg.callBack != ''){
    if (!oArg.obj){
      oArg.obj = 'window';
    }    
    animTimer[oArg.timerName] = setTimeout(oArg.obj + '.' + oArg.callBack,0);
  }  
}



var BGSwitch = function(oArg){
  
  this.colors = oArg.colors;
  this.delay = oArg.delay;
  this.currentDelay = null;
  this.colorHash = [];
  this.passes = oArg.passes;
  this.currentPass = null;
  
  this.currentColor = oArg.currentColor;
  this.currentNum = null;
  this.nextColor = null;
  this.nextNum = null;
  this.currentColorContrast = oArg.currentColorContrast;
  this.currentNumContrast = null;
  this.nextColorContrast = null;
  this.nextNumContrast = null;
  
  this.instance = null;
  this.currentRGB = [];
  this.currentRGBContrast = [];
  this.CSSSelectors = oArg.CSSSelectors;
  this.CSSSelectorsContrast = oArg.CSSSelectorsContrast;
  this.animTimer = null;
  this.els = [];
  this.elsContrast = [];
  this.currentDate = new Date();
  this.firstDelay = null;
  this.interval = 50;
  this.paused = false;
  
  if (!BGSwitch.prototype.instances){
    // Class methods and variables
    BGSwitch.prototype.instances = [];
    BGSwitch.prototype.setupAll = function(){
      var inst = BGSwitch.prototype.instances;
      for (var i in inst){
        inst[i].startSwitch();
      }
    }
    addEvent(window,'DOMContentLoaded',function(){BGSwitch.prototype.setupAll();});
    BGSwitch.prototype.beforeOnloadAll = function(){
      var inst = BGSwitch.prototype.instances;
      for (var i in inst){
        inst[i].beforeUnload();
      }
    }
    addEvent(window,'beforeunload',function(){BGSwitch.prototype.beforeOnloadAll();});
  }
  
  this.instance = BGSwitch.prototype.instances.length;
  BGSwitch.prototype.instances[this.instance] = this;
  

  this.getNextNum = function(){
    while(this.currentNum == this.nextNum){
      this.nextNum = Math.floor(Math.random() * this.colorHash.length);
    }
  }; 
  
  this.getNextNumContrast = function(){
    while(this.nextNumContrast == this.nextNum || this.nextNumContrast == this.currentNumContrast){
      this.nextNumContrast = Math.floor(Math.random() * this.colorHash.length);
    }
    //alert(this.nextNumContrast);
  }; 
  
  this.calculateColor = function(oldColor, newColor){
    return Math.round(oldColor + (((newColor - oldColor) / this.passes) * this.currentPass));
  };  
  
  // cookie functionality
  var currentColor = getCookie('BGSwitchCurrentColor' + this.instance);
  if (currentColor && this.colors[currentColor]){
    this.currentColor = currentColor;
  }
  var currentColorContrast = getCookie('BGSwitchCurrentColorContrast' + this.instance);
  if (currentColorContrast && this.colors[currentColorContrast]){
    this.currentColorContrast = currentColorContrast;
  }
  var nextColor = getCookie('BGSwitchNextColor' + this.instance);
  if (nextColor && this.colors[nextColor]){
    this.nextColor = nextColor;
  }
  var nextColorContrast = getCookie('BGSwitchNextColorContrast' + this.instance);
  if (nextColorContrast && this.colors[nextColorContrast]){
    this.nextColorContrast = nextColorContrast;
  }
  
  for (var i in this.colors){
    var cL = this.colorHash.length;
    this.colorHash[cL] = i;
    if (i == this.nextColor){
      this.nextNum = cL;
    }
    if (i == this.nextColorContrast){
      this.nextNumContrast = cL;
    }
    if (i == this.currentColor){
      this.currentNum = cL;
    }
    if (i == this.currentColorContrast){
      this.currentNumContrast = cL;
    }
  }
  
  if (!this.nextNum){
    this.nextNum = this.currentNum;
    this.getNextNum();
    this.nextColor = this.colorHash[this.nextNum];
  }
  
  if (!this.nextNumContrast){
    this.nextNumContrast = this.currentNumContrast;
    this.getNextNumContrast();
    this.nextColorContrast = this.colorHash[this.nextNumContrast];
  }

  this.firstDelay = getCookie('BGSwitchFirstDelay' + this.instance);
  if(this.firstDelay === null){
    this.firstDelay = this.delay;
  }
  this.currentPass = getCookie('BGSwitchCurrentPass' + this.instance);
  if(this.currentPass === null){
    this.currentPass = 0;
  }
  else if (this.currentPass > 0){
    this.firstDelay = 0;
  }
    
  for (var i = 0; i < this.CSSSelectors.length; i++){
    var cC = this.colors[this.currentColor][this.CSSSelectors[i][1]];
    var nC = this.colors[this.nextColor][this.CSSSelectors[i][1]];
    addStyle(this.CSSSelectors[i][0],'background-color:rgb(' + this.calculateColor(cC[0],nC[0]) +',' +  this.calculateColor(cC[1],nC[1]) + ',' +  this.calculateColor(cC[2],nC[2]) + ')');
  }
  
  for (var i = 0; i < this.CSSSelectorsContrast.length; i++){
    var cCC = this.colors[this.currentColorContrast][this.CSSSelectorsContrast[i][1]];
    var nCC = this.colors[this.nextColorContrast][this.CSSSelectorsContrast[i][1]];
    addStyle(this.CSSSelectorsContrast[i][0],'background-color:rgb(' + this.calculateColor(cCC[0],nCC[0]) +',' +  this.calculateColor(cCC[1],nCC[1]) + ',' +  this.calculateColor(cCC[2],nCC[2]) + ')');
  }
  
  this.startSwitch = function(){
    for (var i = 0; i < this.CSSSelectors.length; i++){
      this.els[i] = [getElementsByCSSSelector(this.CSSSelectors[i][0]),this.CSSSelectors[i][1]];
    }
    for (var i = 0; i < this.CSSSelectorsContrast.length; i++){
      this.elsContrast[i] = [getElementsByCSSSelector(this.CSSSelectorsContrast[i][0]),this.CSSSelectorsContrast[i][1]];
    }
    this.animTimer = setTimeout('BGSwitch.prototype.instances[' + this.instance + '].switchColor()',this.firstDelay);
    this.currentDate = new Date();
  }
  
  this.setBGColor = function(el, r, g, b){
    el.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
    //status = 'rgb(' + r + ',' + g + ',' + b + ')';
  }
  
  this.newSwitch = function(){
    
    this.currentDate = new Date();
    this.currentColor = this.nextColor;
    this.currentNum = this.nextNum;
    this.currentColorContrast = this.nextColorContrast;
    this.currentNumContrast = this.nextNumContrast;
    this.currentPass = 0;
    this.getNextNum();
    this.getNextNumContrast();
    this.nextColor = this.colorHash[this.nextNum];
    this.nextColorContrast = this.colorHash[this.nextNumContrast];
    this.animTimer = setTimeout('BGSwitch.prototype.instances[' + this.instance + '].switchColor()',this.delay);
    //status = this.nextColor;
  };
  
  this.switchColor = function(){
  
    this.firstDelay = null;
    
    if (this.paused){
      this.animTimer = setTimeout('BGSwitch.prototype.instances[' + this.instance + '].switchColor()',this.interval);
      return;
    }
    
    var finished = false;
    if (this.currentPass >= this.passes - 1){
      finished = true;
      this.currentRGB = [];
      this.currentRGBContrast = [];
    }

    //new color
    var nC = this.colors[this.nextColor];
    for (var i = 0; i < nC.length; i++){
      if (finished){
        this.currentRGB[i] = [nC[i][0],nC[i][1],nC[i][2]];
      }
      else {
        var cC = this.colors[this.currentColor];
        this.currentRGB[i] = [];
        for (var j = 0; j < 3; j++){
          this.currentRGB[i][j] = this.calculateColor(cC[i][j],nC[i][j]);
        } 
      }
    }
    
    //new contrast
    var nCC = this.colors[this.nextColorContrast];
    for (var i = 0; i < nCC.length; i++){
      if (finished){
        this.currentRGBContrast[i] = [nCC[i][0],nCC[i][1],nCC[i][2]];
      }
      else {
        var cCC = this.colors[this.currentColorContrast];
        this.currentRGBContrast[i] = [];
        for (var j = 0; j < 3; j++){
          this.currentRGBContrast[i][j] = this.calculateColor(cCC[i][j],nCC[i][j]);
        } 
      }
    }
    
    for (var i = 0; i < this.els.length; i++){
      var list = this.els[i][0];
      var shade = this.els[i][1];
      for (var j = 0; j < list.length; j++){
        this.setBGColor(list[j], this.currentRGB[shade][0], this.currentRGB[shade][1], this.currentRGB[shade][2]);
      }
    }
    
    for (var i = 0; i < this.elsContrast.length; i++){
      var list = this.elsContrast[i][0];
      var shade = this.elsContrast[i][1];
      for (var j = 0; j < list.length; j++){
        this.setBGColor(list[j], this.currentRGBContrast[shade][0], this.currentRGBContrast[shade][1], this.currentRGBContrast[shade][2]);
      }
    }
    if (finished){
      this.newSwitch();
      return;
    }
    this.currentPass++;
    this.animTimer = setTimeout('BGSwitch.prototype.instances[' + this.instance + '].switchColor()',this.interval);
  };
  
  this.addToElsContrast = function(el,setNum){
    var set = this.elsContrast[setNum];
    if (!set){
      return;
    }
    set[0][set[0].length] = el;
    if (this.currentRGBContrast.length){
      var shade = set[1];
      this.setBGColor(el, this.currentRGBContrast[shade][0], this.currentRGBContrast[shade][1], this.currentRGBContrast[shade][2]);
    }
  }
  
  this.pause = function(){
    this.paused = true;
    //status = 'paused';
  }
  
  this.resume = function(){
    this.paused = false;
    //status = 'resumed';
  }
  
  this.beforeUnload = function(){
    setCookie('BGSwitchCurrentColor' + this.instance,this.currentColor,365);
    setCookie('BGSwitchNextColor' + this.instance,this.nextColor,365);
    setCookie('BGSwitchCurrentColorContrast' + this.instance,this.currentColorContrast,365);
    setCookie('BGSwitchNextColorContrast' + this.instance,this.nextColorContrast,365);
    var delay = this.firstDelay !== null ? this.firstDelay : this.delay;
    setCookie('BGSwitchFirstDelay' + this.instance,delay - (new Date() - this.currentDate),365);
    setCookie('BGSwitchCurrentPass' + this.instance,this.currentPass,365);  
  };

};

// browser sniffer
function Browser(){
  this.uA = navigator.userAgent.toLowerCase();
  this.aN = navigator.appName.toLowerCase();
  this.iE = this.aN.indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  this.uA.indexOf('mac') != -1 ? 1 : 0;
  this.win = this.uA.indexOf('windows') != -1 ? 1 : 0;
  this.safari =  this.uA.indexOf('webkit') != -1 ? 1 : 0;
  this.opera =  this.uA.indexOf('opera') != -1 ? 1 : 0;    
  this.mozilla = this.aN.indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.winIE6Down = this.winIE && parseInt(this.uA.split('msie ')[1].substring(0,1)) <= 6 ? 1: 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
};

var browser = new Browser();

// getElementById wrapper
if (typeof document.getElementById != 'undefined'){
  var getEl = function(id){
    var el = document.getElementById(id);
    if (!el){
      error('elById: element width id "' + id + '" not found in DOM');
      return false;
    }
    return(el);
  };
}
else {
  error('document.getElementById not supported');
}
  

// array for DOMContentLoaded events
var DOMCLEvents = [];  
var executeDOMCLEvents = function(){
  if(DOMCLEvents.preventExecution){
    return;
  }
  DOMCLEvents.preventExecution = true;
  for (var i = 0; i < DOMCLEvents.length; i++){
    DOMCLEvents[i]();
  }
};

//event listening
if (window.addEventListener){
  var addEvent = function(obj, eventType, functionName){
    if (eventType == 'DOMContentLoaded'){
      DOMCLEvents[DOMCLEvents.length] = functionName;
    }
    obj.addEventListener(eventType, functionName, false);
    return true;
  };
  if (/WebKit/i.test(navigator.userAgent)){ //for safari
    var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {            
    clearInterval(_timer); executeDOMCLEvents();}}, 10);
  };
  addEvent(window,'load',executeDOMCLEvents); //for opera < 9, ..
  addEvent(window,'DOMContentLoaded',function(){DOMCLEvents.preventExecution = true;}); //not for firefox
}
else if(window.attachEvent && Function.apply){ //for ie 5.5+
  var addEvent = function(obj, eventType, functionName){
    if (eventType == 'DOMContentLoaded'){
      DOMCLEvents[DOMCLEvents.length] = functionName;
      return true;
    }
    var r = obj.attachEvent("on"+eventType, function() { functionName.apply(obj); });
    return r;
  };
  document.write('<script type="text/javascript" id="__ie_onload" defer="defer" src="javascript:void(0);"><\/script>');
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      executeDOMCLEvents();
    }
  }
}
else {
  error("event handling not supported");
}


// event on part of element
function eventOnPartOfElement(e,element,to){
  var t;
  if (window.event){
    t = to ? window.event.toElement : window.event.srcElement;
  }
  else if (e){
    t = to ? e.relatedTarget : e.target;
  } 
  else {
    return false;
  }
  if (t == null){
    return false;
  }
  while (t.tagName != 'BODY' && t.tagName != 'HTML'){
    if (t == element){
      return true;
    }
    t = t.parentNode;
  }
  return false;
};


// setInlineStyle 
function setInlineStyle(el,cssText){
  if (!cssText){
    return;
  }
  var elStyle = el.getAttribute('style');
  if (elStyle){
    elStyle.setAttribute('cssText',cssText);
  }
  else {
    el.setAttribute('style',cssText);
  }
};


// setClassName
function addClassName(el,className){
  if (!className){
    return;
  }
  if (el.getAttribute('className') != null){
    el.setAttribute('className',className);
  }
  else {
    el.setAttribute('class',className);
  }
};


// getClassName
function getClassName(el){
  var cN;
  if (el.getAttribute('className') != null){
    cN = el.getAttribute('className');
  }
  else {
    cN = el.getAttribute('class');
  }
  return cN ? cN : '';
};


// get src Element
function getTarget(e,to){
  if (window.event){
    var t = to ? window.event.toElement : window.event.srcElement;
  }
  else if (e){
    var t = to ? e.relatedTarget : e.target;
  }
  if (t == null){
    window.body;
  }  
  return t;
};


// getElementsByCSSSelector
function getElementsByCSSSelector(selector,pN){
  var els = [];
  var iterator = 0;
  var pNs = pN;
  if (!pNs){
    pNs = Array(document);
  }
  var selectorArr = selector.split(' ');
  var cN = false;
  var currSelector = selectorArr[0];
  if (currSelector.indexOf('#') != -1){
    var elFromId  = document.getElementById(currSelector.split('#')[1]);
    if (!elFromId){
      return els;
    }
    els[0] = elFromId;
  }
  else {
    if (currSelector.indexOf('.') != -1){
      var currSelectorArr = currSelector.split('.');
      currSelector = currSelectorArr[0];
      cN = currSelectorArr[1];
    }
    for (var i = 0; i < pNs.length; i++){
      var elsFromTN = pNs[i].getElementsByTagName(currSelector);
      for (var j = 0; j < elsFromTN.length; j++){
        //alert(elsFromTN[j].className);
        /*if (cN && elsFromTN[j].className.indexOf(cN)== -1){
          continue;
        }*/
        var matchedClassNames = true;
        if (cN){
          for (var k = 1; k < currSelectorArr.length; k++){
            var elCN = elsFromTN[j].className;
            if (elCN.indexOf(currSelectorArr[k])== -1){
              matchedClassNames = false;
              //alert(elCN);
              break;
            }
          }
        }
        if (!matchedClassNames){
          continue;
        }
        els[iterator] = elsFromTN[j];
        iterator++;
      }
    }
    if (iterator == 0){
      return [];
    }        
  }

  if (selectorArr.length == 1){
    return els;
  }
  var s = '';
  var space = '';
  for (var i = 1; i < selectorArr.length; i++){
    s += space + selectorArr[i];
    space = ' ';
  }
  return getElementsByCSSSelector(s,els);
};


// add stylesheet
var styleSheetFromScript = false;
function addStyle(selector,properties){
  if (document.styleSheets) {
    if (!styleSheetFromScript){
      styleSheetFromScript = document.createElement('style');
      styleSheetFromScript.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(styleSheetFromScript);
    }

    var lastSheet = document.styleSheets[document.styleSheets.length - 1];
    if(lastSheet && typeof lastSheet.addRule == 'object'){
      lastSheet.addRule(selector, properties);
      //status = 'ie'; 
      //alert(selector);
    }
    else {
      styleSheetFromScript.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));
      //status = 'iedd'; 
    }
  }
};


//handy trace
function trace(str){
  var el = getEl('trace');
  if (!el){
    return;
  }
  el.value = str;
};

/*************************
flash adapted for this project, see wiki for last version, mdi 1.1
*************************/


// check if the proper version is installed
function hasMinFlashVersion(versionNumber){
  var versionInCache = hasMinFlashVersion.prototype.cache[versionNumber];
  if (versionInCache != undefined){
    return versionInCache;
  }
  var versionFound = false;
  if (window.ActiveXObject){
    try{
      var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + versionNumber);
      versionFound = true;
    }
    catch(e){
      versionFound = false;
    }
  }
  else {
    if(navigator.plugins.length){
      for (var i=0; i < navigator.plugins.length; i++){
        var pluginIdent = navigator.plugins[i].description.split(" ");
        if(pluginIdent[0] == "Shockwave" && pluginIdent[1] == "Flash"){
          var versionArray = pluginIdent[2].split(".");
          versionFound = versionArray[0] >= versionNumber;
        }
      }   
    }
  }
  //alert(versionFound);
  hasMinFlashVersion.prototype.cache[versionNumber] = versionFound;
  return versionFound;
};
hasMinFlashVersion.prototype.cache = [];

// Class FlashObject
flashObjects = [];
function FlashObject(oArg){

  this.hasRequiredVersion = hasMinFlashVersion(oArg.requiredVersion);
  
  this.id = oArg.id;
  this.parentId = oArg.parentId;      
  this.uri = oArg.uri;
  this.width = oArg.width ? 'width:' + oArg.width + 'px;' : '';
  this.height = oArg.height ? 'height:' + oArg.height + 'px;' : '';
  
  this.className = oArg.className ? oArg.className : '';
  this.params = oArg.params;
  this.noFocus = oArg.noFocus;
	this.inlineStyle = oArg.inlineStyle ? oArg.inlineStyle : '';
  if (this.hasRequiredVersion && (oArg.alternateContent == undefined)){
    addStyle('#' + oArg.parentId + ' .alternate-content','display:none !important;');
  }
  
  // create the object
  this.create = function(){
    if ((!this.hasRequiredVersion) || (!getEl(this.parentId))){
      return;
    }
    var obj = document.createElement('object');
    obj.type = 'application/x-shockwave-flash';
    if (this.id){
      obj.setAttribute('id',this.id);
    }
    obj.setAttribute('data',this.uri);
    obj.setAttribute('src',this.uri);
     
    setInlineStyle(obj,'display:block;' + this.width + this.height + this.inlineStyle);
    if (this.noFocus){
      obj.setAttribute('tabIndex',-1);
    }
    obj.className = this.className;
    for (var i in this.params){
      var param = document.createElement('param');
      param.setAttribute('name',i);
      param.setAttribute('value',this.params[i]);
      obj.appendChild(param);
      obj[i] = this.params[i];
    };
    var title = document.title;
    getEl(this.parentId).appendChild(obj);
    document.title = title;
    
    if (typeof obj.loadMovie == 'undefined'){
      return;
    }
    try {
      obj.loadMovie(0,this.uri);
    }
    catch (e){
    }
  }
  
};

// make a flash object
function createFlashObject(oArg){
  flashObjects[flashObjects.length] = new FlashObject(oArg);
};

// create all the flash objects (onload)
function createFlashObjects(){
  for (var i in flashObjects){
    flashObjects[i].create();
  }
};



/*************************
flash header, mdi 2.01
  dependencies:
  - function getEl
  - 
*************************/

function FlashHeaders(){

  // instance variables
  this.path;
  this.calibrationId;
  this.calibrationHeight;
  this.currentCalibrationHeight;
  this.hasFlash6up;
  this.hasFlash8up;
  this.headers = [];
  this.replacements = [];
  this.maxId = 0;
  
  // start
  this.start = function(oArg){
    this.hasFlash6up = hasMinFlashVersion(6);
    if (!this.hasFlash6up || browser.macIE || browser.opera){ // not minimal version, buggy ie5 mac, TODO:Opera
      return;
    }
    this.hasFlash8up = hasMinFlashVersion(8);
    this.path = oArg.path;
    this.calibrationId = oArg.calibrationId;
    this.calibrationHeight = oArg.calibrationHeight;
    for (var i in this.headers){ // hide all elements
      if (!this.hasFlash8up && !this.headers[i].fontPath7Down){
        continue;
      }
      addStyle(this.headers[i].cssSelector,'height:' + this.headers[i].lineHeights[0] + 'px;visibility:hidden');
    }
    addEvent(window,'DOMContentLoaded',function(){flashHeaders.create();});
  };
  
  // add headers
  this.add = function(oArg){

    var o = this.headers[this.headers.length] = new Object;
    o.fontPath = oArg.fontPath;
    o.fontPath7Down = oArg.fontPath7Down ? oArg.fontPath7Down : false;
    o.cssSelector = oArg.cssSelector;
    o.size = oArg.size ? oArg.size : '';
    o.align = oArg.align ? oArg.align : 'left';
    o.color = oArg.color ? '0x' + oArg.color : '';
    o.bGColor = oArg.bGColor ? '0x' + oArg.bGColor : '';
    o.hoverColor = oArg.hoverColor ? '0x' + oArg.hoverColor : '';
    o.hoverBGColor = oArg.hoverBGColor ? '0x' + oArg.hoverBGColor : '';
    o.paddingTop = oArg.paddingTop ? oArg.paddingTop : 0;
    o.paddingRight = oArg.paddingRight ? oArg.paddingRight : 0;
    o.paddingBottom = oArg.paddingBottom ? oArg.paddingBottom : 0;
    o.paddingLeft = oArg.paddingLeft ? oArg.paddingLeft : 0;
    o.menuHover = oArg.menuHover;
    o.leading = oArg.leading ? oArg.leading : 0;
    o.letterSpacing = oArg.letterSpacing? oArg.letterSpacing : 0;
    o.capitalize = oArg.capitalize;
    o.thickness = oArg.thickness ? oArg.thickness : '';
    o.sharpness = oArg.sharpness ? oArg.sharpness : '';
    o.gridFitType = oArg.gridFitType ? oArg.gridFitType : '';
    o.lineHeights = oArg.lineHeights ? oArg.lineHeights : [20];
  };
  
  //add an id
  this.newId = function(){
    this.maxId++;
    return 'flash-header' + this.maxId;
  };
  
  //check for resize (win ie only)
  this.checkResize = function(){
    if (!browser.winIE){
        return;
    }
    if (this.currentCalibrationHeight != getEl(this.calibrationId).offsetHeight){
      location.href = location.href;
    }
  };
  
  this.create = function(){
    //scaling
    var cHS = getEl(this.calibrationId);
    if (cHS){
      this.currentCalibrationHeight = cHS.offsetHeight;
      addEvent(window,'resize',function(){flashHeaders.checkResize();});
    }
    var fontScale = cHS ? cHS.offsetHeight / this.calibrationHeight : 1;
    //fontScale = 1;
    // create the flash headers
    
    for (var i in this.headers){

      var o = this.headers[i];
      if (!this.hasFlash8up && !this.headers[i].fontPath7Down){
        continue;
      }
      
      var list = getElementsByCSSSelector(o.cssSelector);
      var htmlLineHeights = [];
      for (var j = 0; j < list.length; j++){
        var el = list[j];
        
        if (el.getAttribute('flashSet')){
          continue;
        }
        el.setAttribute('flashSet',true);
        
        el.style.visibility = 'visible';
        var text = o.capitalize ? el.innerHTML.toUpperCase() : el.innerHTML;
        
        /* link shizzle */
        var hLinkEl = el.getElementsByTagName('A')[0];
        hLink = hLinkEl ? this.URLEncode(hLinkEl.href) : '';
        if (hLinkEl){
          text = o.capitalize ? hLinkEl.innerHTML.toUpperCase() : hLinkEl.innerHTML;
        }
        
        text = this.URLEncode(text);
        
        var elInnerHTML = el.innerHTML;
        el.innerHTML = '';
        var oldHeader = document.createElement('DIV');
        el.appendChild(oldHeader);
        if (j == 0){ // check html lineHeights
          for (var k = 0; k < o.lineHeights.length; k++){
            oldHeader.innerHTML += 'line<br />';
            htmlLineHeights[oldHeader.offsetHeight] = o.lineHeights[k];
          }
        }
        oldHeader.innerHTML = elInnerHTML;
        var h = oldHeader.offsetHeight;
        var height = htmlLineHeights[h] && fontScale == 1 ? htmlLineHeights[h] : o.lineHeights[0];
        var width = oldHeader.offsetWidth;
        oldHeader.className = 'print-header';
        
        var fontPath = this.hasFlash8up ? o.fontPath : o.fontPath7Down;
  
        var swfURL = this.path + 
          '?swfFont=' + fontPath + 
          '&hText=' + text + 
          '&hSize=' + parseInt(o.size * fontScale,10)  + 
          '&hWidth=' + width + 
          '&hAlign=' + o.align +    
          '&hLink=' + hLink +     
          '&hPaddingTop=' + o.paddingTop + 
          '&hPaddingRight=' + o.paddingRight + 
          '&hPaddingBottom=' + o.paddingBottom + 
          '&hPaddingLeft=' + o.paddingLeft +
          '&hLeading=' + o.leading + 
          '&hLetterSpacing=' + o.letterSpacing +  
          '&hThickness=' + o.thickness +  
          '&hSharpness=' + o.sharpness + 
          '&hGridFitType=' + o.gridFitType + 
          '&winIE=' + browser.winIE ;
  
        var colorSet = 
          '&hColor=' + o.color + 
          '&hBGColor=' + o.bGColor;
          
        if (!o.menuHover){
          colorSet += 
          '&hHoverColor=' + o.hoverColor + 
          '&hHoverBGColor=' + o.hoverBGColor;
        }
          
        var params = {'scale':'noscale','salign':'lt','wmode':'transparent','allowScriptAccess':'always'};
        id = this.newId();
        var wTN = hLinkEl ? 'A' : 'DIV'; // wrapperTagName
        //alert(wTN);
        var wrapper = document.createElement(wTN);
        var parentId = id + '-wrapper';
        wrapper.setAttribute('id',parentId);
        if (hLinkEl){
          wrapper.href = hLinkEl.href;
        }
        el.appendChild(wrapper);
        el.style.height = height + 'px';
        this.createFlashObject(o,'flash-header',hLinkEl,id,parentId,swfURL + colorSet,params,width,height);
        
        if (o.menuHover){
          colorSet = 
          '&hColor=' + o.hoverColor + 
          '&hBGColor=' + o.hoverBGColor +         
          '&hHoverColor=' + o.hoverColor + 
          '&hHoverBGColor=' + o.hoverBGColor;
          this.createFlashObject(o,'flash-header-hover',hLinkEl,id + '-MH',parentId,swfURL + colorSet,params,width,height);
        }
      }
    }
    if (browser.winIE) {
      setTimeout('flashHeaders.getHeights()',10);
    }
    //status = (timer.since());
  };

  this.createFlashObject = function(o,className,hLinkEl,id,parentId,swfURL,params,width,height){
    this.replacements[id] = o;
    var fO = new FlashObject({
      id:id,
      parentId:parentId,
      uri:(swfURL + '&hId=' + id),
      params:params,
      requiredVersion:6,
      className:className,
      width:width,
      height:height,
      noFocus:true,
      alternateContent:false
    });
    fO.create();
  };
    
  // win ie getHeights
  this.getHeights = function(){
    for (var i in this.replacements){
      this.getHeight(i,0);
    }
  };
  
  // win ie try to get variables from flash
  this.getHeight = function(i,numTrys){
  
    var h = getEl(i);
    if (h){
      try {
        this.setHeight(i,h.GetVariable('headerHeight'));
      } 
      catch (e) {
        numTrys++;
        if (numTrys < 20){
          setTimeout('flashHeaders.getHeight(\''+i+'\',' + numTrys + ')',200);
        }
      }
    }
  };

  this.setHeight = function(_id,_height,setFromFlash){
		if (setFromFlash){
			//ugly hard coded f**r
			if (projectVisualSizer){
				projectVisualSizer.setColumnHeights();
				return;
			}
		}
    //alert('**' + _height);
    var o = this.replacements[_id];
    var el = getEl(_id);
    el.style.height = _height +'px';
    //alert(el.parentNode.parentNode.innerHTML);
    el.parentNode.parentNode.style.height = 'auto';
  };
  
  this.URLEncode = function(inp){
    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do...
    var SAFECHARS = "0123456789" +          // Numeric
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +  // Alphabetic
            "abcdefghijklmnopqrstuvwxyz" +   //"éëèêáäãâöõóôüúùûïíìîÉËÈÊÁÄÃÂÖÕÓÔÜÚÙÛÏÍÌÎ" +
            "-_.!~*'()";          // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";
    var SAFECHARCODES = "|233|235|232|234|225|228|227|226|246|245|243|244|252|250|249|251|239|237|236|238|201|203|200|202|193|196|195|194|214|213|211|212|220|218|217|219|207|205|204|206";
    var plaintext = inp;
    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
      var ch = plaintext.charAt(i);
        if (ch == " ") {
          encoded += "+";        // x-www-urlencoded, rather than %20
      }
      else if (SAFECHARS.indexOf(ch) != -1) {
          encoded += ch;
      }
      else {
          var charCode = ch.charCodeAt(0);
        if (SAFECHARCODES.indexOf('|'+charCode+'|') != -1){
          encoded += ch;
        }
        else if (charCode > 255) {
          encoded += "+";
        }
        else {
          encoded += "%";
          encoded += HEX.charAt((charCode >> 4) & 0xF);
          encoded += HEX.charAt(charCode & 0xF);
        }
      }
    }
    return encoded;
  };
  
}

//create the instance
var flashHeaders = new FlashHeaders();


/************* end flash header *****************/



// set external links
var setExternalLinks = function(){
  var localDomain = (location.href.split('/')[2]);
    var localExtensionsInNewWindow = Array('doc','xls','pdf');
    var list = document.getElementsByTagName('A');
    for (var i = 0; i < list.length; i++){
      var aEl = list[i];
      var aElHref = aEl.href;
      // check for extensions
      var extension = (aElHref.substring(aElHref.length - 4,aElHref.length)).toLowerCase();
      var foundExtension = false;
      for (var j = 0; j < localExtensionsInNewWindow.length; j++){
        if (extension == '.' + localExtensionsInNewWindow[j]){
          foundExtension = true;
          break;
        }
      }
      // open in new window if conditions are right
      if ((aElHref.split('/')[2] != localDomain && aElHref.indexOf('mailto:') == -1 && aElHref.indexOf('javascript:') == -1) || foundExtension){
        aEl.onclick = function(){
        window.open(this.href);
        return false;
      }
    }
  }
};




/* get and set cookies */
function setCookie(cookieName,cookieValue,nDays) {
  var today = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString()+";path=/";
};

function getCookie(c_name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1){ 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end));
      } 
    }
  return null;
};


// for print
function setLogoForPrintIE6(){
  if (!browser.winIE6Down){
    return;
  }
  addEvent(window,'DOMContentLoaded',
    function(){
      if (!getEl('logo')){
        return;
      }
      getEl('logo').getElementsByTagName('img')[0].setAttribute('src','_images/ie6/logo.gif')
    }
  );
};

function error (){

}


var VertScroller = function(oArg){

  this.itemHeight = oArg.itemHeight;
  this.startItem = oArg.startItem;
  this.delay = oArg.startDelay;
  this.tempDelay = oArg.delay;
  this.scrollerId = oArg.scrollerId;
  this.speed = oArg.speed;
  this.easeIn = oArg.easeIn;
  this.easeOut = oArg.easeOut;  
  this.startPos;

  if (!VertScroller.prototype.instances){
    VertScroller.prototype.instances = [];
  }  
  
  this.instance = VertScroller.prototype.instances.length;
  VertScroller.prototype.instances[this.instance] = this;
  
  this.setup = function(){
    this.scroller = getEl(this.scrollerId);
    this.scroller.style.marginTop = - (this.itemHeight * this.startItem) + 'px';
    this.onMoveFinished();
  }
  
  this.move = function(){
    animate({
      timerName:this.scrollerId,
      elements:Array(
        {id:this.scrollerId,style:'marginTop',startPos:this.scroller.offsetTop,negMove:true}
      ),
      dist:this.itemHeight,
      speed:this.speed,
      easeIn:this.easeIn,
      easeOut:this.easeOut,
      callBack:'VertScroller.prototype.instances[' + this.instance +'].onMoveFinished()'
    });
  }
  
  this.onMoveFinished = function(){
    var scrollerTop = this.scroller.offsetTop;
    if (Math.abs(scrollerTop) >= this.scroller.offsetHeight - this.itemHeight){
      var el = this.scroller.getElementsByTagName('DIV')[0];
      this.scroller.appendChild(el);
      this.scroller.style.marginTop = (scrollerTop + this.itemHeight) + 'px';
    }
    animTimer[this.scrollerId] = setTimeout('VertScroller.prototype.instances[' + this.instance +'].move()',this.delay);
    this.delay = this.tempDelay;
  }
}





var NavProjects = function(oArg){

  this.containerId = oArg.containerId;
  this.speed = oArg.speed;
  this.easeIn = oArg.easeIn;
  this.easeOut = oArg.easeOut;     
  this.elContainer = false;
  this.el = false;
  this.id = false;
  this.maxWidth = false;
  this.minWidth = false;
  this.minHeight = false;
  this.maxHeight = false;
  this.state = 'closed';
  
  addEvent(window,'DOMContentLoaded',function(){navProjects.setup()});
  
  this.setup = function(){
    this.elContainer = getEl(this.containerId);
    if (!this.elContainer){
      return;
    }
    this.el = this.elContainer.getElementsByTagName('ul')[0];
    if (!this.el){
      return;
    }
    this.id = 'nav-projects-inner';
    this.el.setAttribute('id',this.id);
    var list = this.el.childNodes;
    var numProjectsOnRow = 0;
    for (var i = 0; i < list.length; i++){
      if (numProjectsOnRow == 6){
        break;
      }
      if(list[i].nodeType == 1){
        numProjectsOnRow++;
      }
    }
    var maxWidth = numProjectsOnRow * 98;
    this.el.style.width = maxWidth + 'px';
   
    this.maxWidth = maxWidth + 20;
    this.maxHeight = this.el.offsetHeight;
    this.minWidth = this.elContainer.offsetWidth;
    this.minHeight = this.elContainer.offsetHeight;
    addEvent(this.el,'mouseover',function(e){navProjects.show(e)});
    addEvent(this.el,'mouseout',function(e){navProjects.hide(e)});
    var list = this.el.getElementsByTagName('a');
    for (var i = 0; i < list.length; i++){
      addEvent(list[i],'focus',function(e){navProjects.show(e)});
      //addEvent(list[i],'blur',function(e){navProjects.hide(e)});
    }
  };
  
  this.show = function(e){
    if (this.state == 'opening' || this.state == 'opened'){
      return;
    }
    this.state = 'opening';
    animate({
      timerName:this.id,
      elements:Array(
        {id:this.containerId,style:'width',startPos:this.elContainer.offsetWidth,negMove:false}
      ),
      dist:this.maxWidth - this.elContainer.offsetWidth,
      speed:this.speed,
      easeIn:this.easeIn,
      easeOut:this.easeOut,
      callBack:'navProjects.onShowFinished()'
    });
    animate({
      timerName:this.id + '-vert',
      elements:Array(
        {id:this.containerId,style:'height',startPos:this.elContainer.offsetHeight,negMove:false}
      ),
      dist:this.maxHeight - this.elContainer.offsetHeight,
      speed:this.speed,
      easeIn:this.easeIn,
      easeOut:this.easeOut
    });
  };
  
  this.onShowFinished = function(){
    this.state = 'opened';
  };
  
  this.onHideFinished = function(){
    this.state = 'closed';
  };
  
  this.hide = function(e){
    if (eventOnPartOfElement(e,this.el,true)){
      return;
    }
    this.state = 'closing';
    animate({
      timerName:this.id,
      elements:Array(
        {id:this.containerId,style:'width',startPos:this.elContainer.offsetWidth,negMove:true}
      ),
      dist:this.elContainer.offsetWidth - this.minWidth,
      speed:this.speed,
      easeIn:this.easeIn,
      easeOut:this.easeOut,
      callBack:'navProjects.onHideFinished()'
    });
    animate({
      timerName:this.id + '-vert',
      elements:Array(
        {id:this.containerId,style:'height',startPos:this.elContainer.offsetHeight,negMove:true}
      ),
      dist:this.elContainer.offsetHeight - this.minHeight,
      speed:this.speed,
      easeIn:this.easeIn,
      easeOut:this.easeOut
    });
  };
 
};


var ProjectVisualSizer = function(oArg){

  this.speed = oArg.speed;
  this.easeIn = oArg.easeIn;
  this.easeOut = oArg.easeOut;
  this.elPV = false;
  this.elCF = false;
  this.elButton = false;
  this.elH1Object = false;
  this.buttonId = 'project-sizer';
  this.textColumnSize = 'small';
  
  addEvent(window,'DOMContentLoaded',function(){projectVisualSizer.setup()});
  addEvent(window,'load',function(){projectVisualSizer.setColumnHeights()});
  
  this.createButton = function(){
    var pElAfter = getEl('content').getElementsByTagName('P')[0];
    if (!pElAfter){
      return;
    }
    var pEl = document.createElement('p');
    pEl.className = 'text-small';
    var aEl = document.createElement('a');
    aEl.setAttribute('id',this.buttonId);
    aEl.setAttribute('href','javascript:void(0)');
    aEl.appendChild(document.createTextNode('brede tekstkolom'));
    pEl.appendChild(aEl);
    this.elButton = aEl;
    pElAfter.parentNode.insertBefore(pEl,pElAfter);
  };
  
  this.setup = function(){
    this.elPV = getEl('project-visuals');
    this.elCF = getEl('content-framework');
    if (!this.elPV){
      return;
    }
    this.createButton();
    if (!this.elButton){
      return;
    }
    addEvent(this.elButton,'click',function(){projectVisualSizer.buttonOnClick()});
    addEvent(this.elPV,'click',function(){projectVisualSizer.textColumnSize = 'wide';projectVisualSizer.buttonOnClick()});
    this.elH1Object = getElementsByCSSSelector('h1 object')[0];
    this.setColumnHeights();
  };
  
  this.buttonOnClick = function(){
    var button = this.elButton;
    if(this.textColumnSize == 'small'){
      this.textColumnSize = 'wide';
      button.childNodes[0].data = 'smalle tekstkolom';
      animate({
        timerName:'project-animation',
        elements:Array(
          {id:'content-framework',style:'left',startPos:this.elCF.offsetLeft,negMove:true},
          {id:'content-framework',style:'width',startPos:this.elCF.offsetWidth,negMove:false},
          {id:'project-visuals',style:'width',startPos:this.elPV.offsetWidth,negMove:true}
        ),
        dist:this.elCF.offsetLeft - 480,
        speed:this.speed,
        easeIn:this.easeIn,
        easeOut:this.easeOut,
        callBack:'projectVisualSizer.onSmallFinished()'
      });
    }
    else {
      /*this.elCF.style.width = '275px';
      if (this.elH1Object){
        this.elH1Object.style.width = '275px';
      }*/
      
      this.setColumnHeights();
      this.textColumnSize = 'small';
      this.elCF.className = '';
      button.childNodes[0].data = 'brede tekstkolom';
      animate({
        timerName:'project-animation',
        elements:Array(
          {id:'content-framework',style:'left',startPos:this.elCF.offsetLeft,negMove:false},
          {id:'content-framework',style:'width',startPos:this.elCF.offsetWidth,negMove:true},
          {id:'project-visuals',style:'width',startPos:this.elPV.offsetWidth,negMove:false}
        ),
        dist:665 - this.elCF.offsetLeft,
        speed:this.speed,
        easeIn:this.easeIn,
        easeOut:this.easeOut,
        callBack:'projectVisualSizer.onWideFinished()'
      });
    }
  };
  
  this.onWideFinished = function(){
     this.setColumnHeights();
  };
  
  this.onSmallFinished = function(){
    /*this.elCF.style.width = '460px';
    if (this.elH1Object){
			//alert('');
      this.elH1Object.style.width = '460px';
    }*/
    this.setColumnHeights();
    this.elCF.className = 'wide';
  };
  
  
  this.setColumnHeights = function(){
    if (!this.elPV){
      return;
    }
    this.elPV.style.height = 'auto';
    this.elCF.style.height = 'auto';
    if (this.elPV.offsetHeight > this.elCF.offsetHeight){
      this.elCF.style.height = this.elPV.offsetHeight + 'px';
    }
    else {
      this.elPV.style.height = this.elCF.offsetHeight + 'px';
      this.elCF.style.height = this.elCF.offsetHeight + 'px';
    }
  };
  
};



//layout case switcher 
var currentLarge = 1;
function scaleSite() {
  //status = 'he';
  var smaller = ((document.documentElement.clientWidth > 0 && document.documentElement.clientWidth < 960) || document.body.clientWidth < 960);
  if (smaller) {
  	if (currentLarge == 0){
      return;
    }
    currentLarge = 0;
  	getEl('framework').className = 'small'; 
  }
  else {
  	if (currentLarge == 1){
      return;
    }
    currentLarge = 1;
  	getEl('framework').className = ''; 
  }
  //status = currentLarge + 'ja';
};

var wieberTimer;
function setWieberContainer(){
  if (!getEl('wieber-container')){
    return;
  }
  addEvent(getEl('wieber-container'),'mouseover',function(){clearTimeout(wieberTimer);this.className = 'hover';});
  addEvent(getEl('wieber-container'),'mouseout',closeWieber);
}

function closeWieber(){
  wieberTimer = setTimeout('getEl(\'wieber-container\').className = \'\'',1000);
}


function fillEmployeeContactList(){
  if (!window.employeeContactList){
    return;
  }

  for (var i = 0; i < employeeContactList.length;i++){
    var item = employeeContactList[i];
    var em = item[0] + '@' + item[1];
    var el = getEl('employee-' + i);
    el.innerHTML = em;
    el.setAttribute('href','mailto:' + em);
  }
}


function createNavSubHeader (){
  var el = getEl('nav-sub');
  if (!el){
    return;
  }
  var elUl = el.getElementsByTagName('ul')[0];
  if (!elUl){
    return;
  }
  var parentName = el.parentNode.getAttribute('id').split('nav-')[1];
  var elHeader = document.createElement('h2');
  elHeader.setAttribute('id','h2-' + parentName);
  el.insertBefore(elHeader,elUl);
  
  var elLink = document.createElement('a');
  elLink.setAttribute('href',el.parentNode.getElementsByTagName('a')[0].getAttribute('href'));
  elHeader.appendChild(elLink);
  
  elLink.appendChild(document.createTextNode(parentName));
  
}
  
 /*mdi: scripts from the old website -  need some refactoring in my opinion */
 
 /*bist du ein fabriquer*/
function writeBistDu(){
  var el = getEl('bistDuContainer');
  if (!el){
    return;
  }
  var w =
  '<object data="_swf/main.swf" type="application/x-shockwave-flash" width="530" height="340" style="margin:15px 0 10px 0;">' +
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="_swf/main.swf" />'+
	'<param name="quality" value="best" />'+
	'<param name="wmode" value="transparent" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'</object>';
  el.innerHTML = w; 
}
addEvent(window,'DOMContentLoaded',writeBistDu);

// hide screen ads
function hideScreenAd(id){
  getEl(id).style.display = 'none';
}

// poppers
function raw_popup(url, width, height) {
  var theWindow =window.open(url, '_blank', 'width=' + width + ',height=' + height + ',resizable=no,scrollbars=yes,location=no,status=no,statusbar=no,menubar=no');
  theWindow.focus();
	return false;
}

function link_popup(src,width,height,_confirm) {
  var width = width ? width : 600;
  var height = height > 2 ? height : 250;
  if (_confirm && (!confirm(_confirm))){
    return false;
  }
  raw_popup(src.getAttribute('href'), width, height);
  return false;
}


/*encrypted contact*/
function contactMe(prefix,suffix){
	var m =  Array(109,97,105,108,116,111,58);
	var a =  Array(64);
	var s = '';
	for (var i = 0; i < m.length; i++){
		s += String.fromCharCode(m[i]);
	}
	window.location.replace(s + prefix + String.fromCharCode(64) + suffix);
	return false;
}

/*fabSPAM*/
function spam(spamName){
	var w = window.open('fabspam/' + spamName + '.html','fabspam','scrollbars=yes,width=760,height=540');
}
 /*mdi: end scripts from the old website */
 
 
 /*
 * ProjectBrowser, mdi (needs some serious cleanup)
 */
 var ProjectBrowser = {
  
  //internal vars
  data:null,
  lookupByURL:{},
  activeItems:[],
  bGSwitch:null,
  
  //functions
  setup: function(oArg){
  
    //checks
    var elPF = getEl('nav-portfolio');
    if (!elPF){
      return;
    }
    var elACN = elPF.getElementsByTagName('a')[0].className;
    if (elACN.indexOf('ancestor') == -1 && elACN.indexOf('self') == -1){
      return;
    }
    
    //add reference to bGSwitch Class
    ProjectBrowser.bGSwitch = oArg.bGSwitch;
    
    //add data
    var data;
    ProjectBrowser.data = data = oArg.data;
    
    //setup
    var elParent = getEl('nav-sub');
    var elUl = elParent.getElementsByTagName('ul')[0];
    var list = elUl.childNodes;
    var elLiAllCats = document.createElement('LI');
    var elLinkAllCats = document.createElement('A');
    elLinkAllCats.setAttribute('href','all-cats');
    elLinkAllCats.appendChild(document.createTextNode('complete portfolio'));
    elLiAllCats.appendChild(elLinkAllCats);
    elUl.insertBefore(elLiAllCats,list[0]);

    //alter data
    data.unshift({
      "title":"complete portfolio",
      "url":"all-cats",
      "items":[]
    });
    for (var i = 1; i < data.length; i++){
      for (var j = 0; j < data[i].items.length; j++){
        data[0].items[data[0].items.length] = data[i].items[j];
      }
    }
    for (var i = 0; i < data.length; i++){
      data[i].items.unshift({
        "title":"alle projecten",
        "url":data[i].url + "-all",
        "items":[]
      });
      for (var j = 1; j < data[i].items.length; j++){
        for (var k = 0; k < data[i].items[j].items.length; k++){
          data[i].items[0].items[data[i].items[0].items.length] = data[i].items[j].items[k];
        }
      }
    }
    for (var i = 0; i < ProjectBrowser.data.length; i++){
      ProjectBrowser.lookupByURL[ProjectBrowser.data[i].url] = ProjectBrowser.data[i];
      for (var j = 0; j < ProjectBrowser.data[i].items.length; j++){
        var subItem = ProjectBrowser.data[i].items[j];
        ProjectBrowser.lookupByURL[subItem.url] = subItem;
      }
    }
    
    //add onclick events and references on menu links
    for (var i = 0; i < list.length; i++){
      if (list[i].nodeType != 1){
        continue;
      }
      var elLink = list[i].getElementsByTagName('a')[0];
      var aArray = elLink.getAttribute('href').split('/');
      elLink.setAttribute('ProjectBrowserId',aArray[aArray.length-1]);
      elLink.setAttribute('href','javascript:void(0);');
      addEvent(elLink,'click',
        function(){
          ProjectBrowser.toggleSubMenu(this,0);
        }
      );
    }
    
  },
 
  
  toggleSubMenu: function (elLink,level){
  
    for (var i = ProjectBrowser.activeItems.length - 1; i >= level; i--){
      if (ProjectBrowser.activeItems[i] == null){
        continue;
      }
      var currentActive = false;
      ProjectBrowser.activeItems[i].parentNode.className = 'inactive';
      ProjectBrowser.activeItems[i].className = ProjectBrowser.activeItems[i].getAttribute('origClassName');
      ProjectBrowser.onAnimFinished(ProjectBrowser.activeItems[i].getAttribute('foldId'));
      if (ProjectBrowser.activeItems[i] == elLink){
        currentActive = true;
      }
      ProjectBrowser.activeItems[i] = null;
      if (currentActive){
        return;
      }
    }
    elLink.parentNode.className = 'active';
    
    if (!elLink.getAttribute('origClassName')){
      elLink.setAttribute('origClassName',elLink.className);
    }
    elLink.className = 'activeLink';

    ProjectBrowser.activeItems[level] = elLink;
    var foldIds = ProjectBrowser.createSubMenu(elLink,level);
    var foldId = foldIds[0];
    var innerId = foldIds[1];
    
    var animVars = [//FIXME: class constant
      {dist:150,startPos:60,speed:100,easeIn:2,easeOut:10},
      {dist:320,startPos:150,speed:150,easeIn:2,easeOut:12}
    ];
    
    getEl(foldId).style.overflow = 'hidden';
    ProjectBrowser.bGSwitch.pause();
    
    animate({
      timerName:'tester',
      elements:Array(
        {id:foldId,style:'width',startPos:animVars[level].startPos,negMove:false}
        ,{id:innerId,style:'marginLeft',startPos:-animVars[level].dist,negMove:false}
      ),
      dist:animVars[level].dist,
      speed:animVars[level].speed,
      easeIn:animVars[level].easeIn,
      easeOut:animVars[level].easeOut,
      callBack:'ProjectBrowser.onAnimFinished("' + foldId + '")'
    });
    
    
  },
  
  onAnimFinished : function(elId){
    getEl(elId).style.overflow = '';
    ProjectBrowser.bGSwitch.resume();
  },
  
  createSubMenu: function(elLink,level){
    if (elLink.getAttribute('menuSubCatsCreated')){ //bestaat al
      if (browser.winIE){
        elLink.parentNode.appendChild(elLink.parentNode.getElementsByTagName('DIV')[0]);
      }
      return [elLink.getAttribute('foldId'),elLink.getAttribute('innerId')];
    }  
    elLink.setAttribute('menuSubCatsCreated',true);
    
    var items = ProjectBrowser.lookupByURL[elLink.getAttribute('ProjectBrowserId')].items;
    
    //elDiv
    var elDiv = document.createElement('DIV');
    elDiv.className = 'foldout foldlevel' + level;
    var foldId = getId();
    elDiv.setAttribute('id',foldId);
    elLink.setAttribute('foldId',foldId);
    
    //elInner
    var elInner = document.createElement('DIV');
    elInner.className = 'inner';
    var innerId = getId();
    elInner.setAttribute('id',innerId);
    elLink.setAttribute('innerId',innerId);
    elDiv.appendChild(elInner);
    
    //elUl
    var elUl = document.createElement('UL');
    for (var i = 0; i < items.length; i++){
      if (level == 0){
        elLi = ProjectBrowser.createSubCat(items[i]);
      }
      else {
        elLi = ProjectBrowser.createProject(items[i]);
      }
      elUl.appendChild(elLi);
    }
    elInner.appendChild(elUl);
    elLink.parentNode.appendChild(elDiv);
    
    // voeg toe aan kleurenblender (Very dirty)
    var bGSwitch = ProjectBrowser.bGSwitch;
    if (level == 0){
      bGSwitch.addToElsContrast(elLink,2);
      bGSwitch.addToElsContrast(elDiv,3);
    }
    else if (level == 1){
      bGSwitch.addToElsContrast(elLink,4);
      bGSwitch.addToElsContrast(elDiv,5);
    }
    
    //voor cats die minder lang zijn dan de link
    
    var linkTop = findPos(elLink)[1] - 174;
    if (level == 1){
      linkTop -= elLink.parentNode.parentNode.parentNode.parentNode.offsetTop - 40;      
    }
    if (linkTop > elDiv.offsetHeight - elLink.offsetHeight){
      
      elDiv.style.top = (linkTop - Math.round(elDiv.offsetHeight / 2)) + 'px';
    }
    
    //meer minder link
    var moreLessNum = [10,10];//FIXME: class constant
    
    if (items.length > moreLessNum[level]){
      var elMore = document.createElement('a');
      elMore.appendChild(document.createTextNode('meer..'));
      elMore.className = 'projects-more';
      elMore.setAttribute('href','javascript:void(0);');
      addEvent(elMore,'click',
        function(){
          ProjectBrowser.toggleMoreLink(this, moreLessNum[level]);
        }
      );
      elInner.appendChild(elMore);
      ProjectBrowser.toggleLess(elMore.parentNode.getElementsByTagName('ul')[0].childNodes,moreLessNum[level]);
    }
    
    return [foldId,innerId];
    
  },
  
  toggleMoreLink: function(elMore,numItems){
    var nodeList = elMore.parentNode.getElementsByTagName('ul')[0].childNodes;
    //alert(nodeList.length);
    if (elMore.className == 'projects-more'){
      elMore.className = 'projects-less';
      elMore.innerHTML = 'minder..';
      ProjectBrowser.toggleMore(nodeList,numItems);
    }
    else {
      elMore.className = 'projects-more';
      elMore.innerHTML = 'meer..';
      ProjectBrowser.toggleLess(nodeList,numItems);
    }
  },
  
  toggleMore: function(nodeList,numItems){
    for (var i = numItems; i < nodeList.length; i++){
      if (nodeList[i].nodeType != 1){
        continue;
      }
      nodeList[i].style.position = 'static';
    }
  },

  toggleLess: function(nodeList,numItems){
    for (var i = numItems; i < nodeList.length; i++){
      if (nodeList[i].nodeType != 1){
        continue;
      }
      nodeList[i].style.position = 'absolute';
      nodeList[i].style.top = '-999px';
    }
  },
  
  createSubCat: function (data){
    var elLi = document.createElement('LI');
    var elLink = document.createElement('A');
    elLink.setAttribute('href','javascript:void(0)');
    elLink.setAttribute('ProjectBrowserId',data.url);
    addEvent(elLink,'click',
      function(){
        ProjectBrowser.toggleSubMenu(this,1);
      }
    );
    elLink.innerHTML = data.title;//TODO dirty innerHTML, escaping "&"
    //appendChild(document.createTextNode(unescape(data.title)));
    elLi.appendChild(elLink);
    return elLi;
  },
  
  createProject: function (data){
    var elLi = document.createElement('LI');
    var elLink = document.createElement('A');
    elLink.setAttribute('href',data.url.replace('&amp;','&'));//data.url.replace('&amp;','&')
    var linkId = getId();
    elLink.setAttribute('id',linkId);
    
    if (browser.winIE){
      setTimeout("getEl('" + linkId +"').parentNode.appendChild(getEl('" + linkId +"'))",0);
    }
    
    elLink.onclick = function(){
      this.parentNode.appendChild(this);
    }
    var elImg = document.createElement('IMG');
    elImg.setAttribute('src',data.visual);
    elImg.setAttribute('alt',data.title);
    
    elLink.appendChild(elImg);
    elLink.innerHTML += data.title;//TODO dirty innerHTML, escaping "&"
    elLi.appendChild(elLink);
    //alert(data.title);
    return elLi;
  },  
    
  orderSubCats: {
  
  }
  
 }
 
 
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//Yikes
var idnum = 0; 
function getId(){
  idnum++;
  return 'id' + idnum;
}

