employees = {
  empl : {cList:[],bList:[],maxV:800,keyVs:[250,500,750],keySteps:5},
  revs : {cList:[],bList:[],maxV:160000000,keyVs:[50000000,100000000,150000000],keySteps:5},
  
  init : function(){ 
    empl = this.empl;
    revs = this.revs;
    
    // (hcl080714) if cmsValues are valid they override default values here !
    if(cmsValues.rkeyvals.length>0) revs.keyVs = cmsValues.rkeyvals;
    if(!isNaN(cmsValues.rkeymax)) revs.maxV = cmsValues.rkeymax;
    if(!isNaN(cmsValues.rkeysteps)) revs.keySteps = cmsValues.rkeysteps;
    if(cmsValues.ekeyvals.length>0) empl.keyVs = cmsValues.ekeyvals;
    if(!isNaN(cmsValues.ekeymax)) empl.maxV = cmsValues.ekeymax;
    if(!isNaN(cmsValues.ekeysteps)) empl.keySteps = cmsValues.ekeysteps;
    
    
    domtable = yui.Selector.query('ul em','historic_data');
    domrows = yui.Selector.query('li','historic_data');
    fieldcount = yui.Selector.query('em',domrows[0]).length;
    reccount = domrows.length;
    var oneY = "";
    
    // get table values
    for (i=0;i<reccount;i++){ // read markdowndata
      b= i*fieldcount;
      oneY = domtable[b].innerHTML;
      empl.cList[i] = {};
      empl.cList[i].key = oneY;
      empl.cList[i].value = Number(domtable[b+1].innerHTML);
      revs.cList[i] = {};
      revs.cList[i].key = oneY;
      revs.cList[i].value = Number(domtable[b+2].innerHTML);
    }
    var eStage = Dom.get('graf-1');
    var rStage = Dom.get('graf-2');
    var graphMaxV = eStage.offsetHeight;
    var graphMaxH = eStage.offsetWidth -114;
    var barWidth = Math.ceil(graphMaxH/empl.cList.length);
    var emplFaktor = graphMaxV/empl.maxV;
    var revsFaktor = graphMaxV/revs.maxV;
    
    var curLoc = {};
    
    // setup employee horizontal lines
    var aStep = Math.round(emplFaktor * empl.keyVs[0] / empl.keySteps);
    var newV = 0;
    for (i=0;i<empl.keyVs.length;i++){
      for (j=0;j<empl.keySteps;j++){
        curLoc = document.createElement("div");
        if (j==empl.keySteps-1) {
          curLoc.className = "backline label";
          newText = document.createTextNode(empl.keyVs[i]);
          curLoc.appendChild(newText);
          newV = Math.round(emplFaktor * empl.keyVs[i]);
        } else {
          curLoc.className = "backline";
          newV += aStep;
        }
        curLoc.style.bottom = newV+"px";
        eStage.appendChild(curLoc);
      }
    }
    
    // setup revenue horizontal lines
    var aStep = Math.round(revsFaktor * revs.keyVs[0] / revs.keySteps);
    var newV = 0;
    for (i=0;i<revs.keyVs.length;i++){
      for (j=0;j<revs.keySteps;j++){
        curLoc = document.createElement("div");
        if (j==revs.keySteps-1) {
          curLoc.className = "backline label";
          displayVal = Math.round(revs.keyVs[i]/10000)/100;
          newText = document.createTextNode(displayVal);
          curLoc.appendChild(newText);
          newV = Math.round(revsFaktor * revs.keyVs[i]);
        } else {
          curLoc.className = "backline";
          newV += aStep;
        }
        curLoc.style.bottom = newV+"px";
        rStage.appendChild(curLoc);
      }
    }
    
    
    // draw year values
    var leftPos = 0;
    for (i=0;i<empl.cList.length;i++){
      
      leftPos = i * barWidth + 40;
      y = empl.cList[i].key % 5;
      
    // draw years if yyy5
      if(y==0){
        curLoc = document.createElement("div");
        newText = document.createTextNode(empl.cList[i].key);
        curLoc.appendChild(newText);
        curLoc.style.left = leftPos-5 +"px";
        Dom.get('years').appendChild(curLoc);
      }
      
    // draw employee bars
      if(empl.cList[i].value>0){
        curLoc = document.createElement("div");
        eStage.appendChild(curLoc);
        curLoc.className = "bar";
        curLoc.style.height = Math.ceil(empl.cList[i].value * emplFaktor)+"px";
        curLoc.style.left = leftPos +"px";
        curLoc.style.width = (barWidth-2)+"px";
        curLoc.title = empl.cList[i].key + ": " + empl.cList[i].value + " " + document.getElementById("link-1").innerHTML;
        empl.bList[empl.bList.length] = curLoc;
      }
      
    // draw revenue bars
      if(empl.cList[i].value>0){
        curLoc = document.createElement("div");
        rStage.appendChild(curLoc);
        curLoc.className = "bar";
        curLoc.style.height = Math.ceil(revs.cList[i].value * revsFaktor)+"px";
        curLoc.style.left = leftPos+"px";
        curLoc.style.width = (barWidth-2)+"px";
        var displayVal = Math.round(revs.cList[i].value/10000)/100;
        curLoc.title = revs.cList[i].key + ": " + displayVal + " Mio. € " + document.getElementById("link-2").innerHTML;
        revs.bList[revs.bList.length] = curLoc;
      }
    }
  },
  
  hideAll : function(){
    for(i=0;i<revs.bList.length;i++){ if(revs.bList[i].style.display != "none") revs.bList[i].style.display = "none";}
    for(i=0;i<empl.bList.length;i++){ if(empl.bList[i].style.display != "none") empl.bList[i].style.display = "none";}
  },
  
  animate : function(aNdx){
    this.buildingList[aNdx].style.display = "block";
    aNdx += 1
    if (aNdx<this.buildingList.length) setTimeout("employees.animate("+aNdx+")",30);
  },
  
  showGraph : function(aElement){
    // (hcl080714) todo:animation starts here !
    theId = aElement.id.replace(/link-/,"");
    theContainer = document.getElementById('mContainer');
    this.hideAll();
    theContainer.className = "visible-"+theId;
    this.buildingList = (theId == 1)?empl.bList:revs.bList;
    setTimeout("employees.animate(0)",10);
  }
}

yui.Event.onDOMReady(function () {
    employees.init();
});
