
function warten(prmSec)
  {
  prmSec *= 1000;
  var eDate = null;
  var eMsec = 0;
  var sDate = new Date();
  var sMsec = sDate.getTime();

  do {
      eDate = new Date();
      eMsec = eDate.getTime();

  } while ((eMsec-sMsec)<prmSec);
}


//Navigations Kästchen.


var effectActive = false;
var durationtime = 0.7;
var effectActive = false;
function effectDone() {
 effectActive = false;
}

var ids = new Array("link1", "link2", "link3", "link4", "link5", "link6", "content");
var states = new Array(false, false, false, false, false, false, false);

function grow(index) {
 if (!effectActive) {
  effectActive = true;
  doGrow(index, true);
 }
}
function doGrow(index, allowOtherEffects) {
 states[index] = false;
 var doneFunc = function(){};
 if (allowOtherEffects) {
  doneFunc = effectDone;
 }
 new Effect.Grow(ids[index], {direction: 'top-left', duration: durationtime, afterFinish:doneFunc});

}

function shrink(index) {
 if (!effectActive) {
  effectActive = true;
  ids.each(function(id, i) {
   if ((states[i]) && (i != index)) doGrow(i, false);
  });
  doShrink(index, true);
 }
}


function doShrink(index, allowOtherEffects) {
 states[index] = true;
 var doneFunc = function(){};
 if (allowOtherEffects) {
  doneFunc = effectDone;
 }
 new Effect.Shrink(ids[index], {direction: 'top-left', duration: durationtime, afterFinish:doneFunc});
}



//Contentkiste auziehen

var contentAufgezogen = false;
function growContent(index) {
doneFunc = effectDone;
 if (!contentAufgezogen && !effectActive) {
 effectActive = true;
    new Effect.Scaleem('content', 18.4, {scaleContent: false, scaleX: false, scaleMode:'box', scaleFrom:9, afterFinish:doneFunc});
  new Effect.Scaleem('rand', 18.4, {scaleContent: false, scaleX: false, scaleMode:'box', scaleFrom:9, afterFinish:doneFunc});
if (index == 2 || index == 1) {
Element.update('upanddown', '<img src="/design-images/pfeil_down.gif" />');} else {
Element.update('upanddown', '<img src="/design-images/pfeil_up.gif" />');}
 contentAufgezogen = true;
 } 
 else if (contentAufgezogen && !effectActive){
 effectActive = true;
 new Effect.Scaleem('content', 9, {scaleContent: false, scaleX: false, scaleMode:'box', scaleFrom:18.4, afterFinish:doneFunc});
  new Effect.Scaleem('rand', 9, {scaleContent: false, scaleX: false, scaleMode:'box', scaleFrom:18.4, afterFinish:doneFunc});

if (index == 2 || index == 1) {
Element.update('upanddown', '<img src="/design-images/pfeil_up.gif" />');} else {
Element.update('upanddown', '<img src="/design-images/pfeil_down.gif" />');}
 contentAufgezogen = false;
 }
}


function changeArrows(index) {
 if (!contentAufgezogen) {
 warten(1);
 alert("wurst");
Element.update('upanddown', '<img src="/design-images/pfeil_down.gif" />');
 } 
 else if (contentAufgezogen){
  warten(1);
  alert("jetzt sollte der pfeil hochgehen");
Element.update('upanddown', '<img src="/design-images/pfeil_up.gif" />');}

 }




//make javascript barrierefrei
   
      var theRules = {
        '#box1 a.haupt' : function(el){
          el.onclick = function(){
				grow(0);
          }      
        },
        '#box1 a.navi-overlay-box' : function(el){
          el.onclick = function(){
				shrink(0);
				return false;
          }      
        },
        '#box1 a.kleiner-kasten-navi' : function(el){
          el.onclick = function(){
				grow(0);
          }      
        },
        '#box2 a.haupt' : function(el){
          el.onclick = function(){
				grow(1);

          }      
        },
        '#box2 a.navi-overlay-box' : function(el){
          el.onclick = function(){
				shrink(1);
				return false;
          }      
        },
        '#box2 a.kleiner-kasten-navi' : function(el){
          el.onclick = function(){
				grow(1);

          }      
        },
        '#box3 a.haupt' : function(el){
          el.onclick = function(){
				grow(2);
          }      
        },
        '#box3 a.navi-overlay-box' : function(el){
          el.onclick = function(){
				shrink(2);
				return false;
          }      
        },
        '#box3 a.kleiner-kasten-navi' : function(el){
          el.onclick = function(){
				grow(2);
          }      
        },
        '#box4 a.haupt' : function(el){
          el.onclick = function(){
				grow(3);
          }      
        },
        '#box4 a.navi-overlay-box' : function(el){
          el.onclick = function(){
				shrink(3);
				return false;
          }      
        },
        '#box4 a.kleiner-kasten-navi' : function(el){
          el.onclick = function(){
				grow(3);

          }      
        },
        '#box5 a.haupt' : function(el){
          el.onclick = function(){
				grow(4);

          }      
        },
        '#box5 a.navi-overlay-box' : function(el){
          el.onclick = function(){
				shrink(4);
				return false;
          }      
        },
        '#box5 a.kleiner-kasten-navi' : function(el){
          el.onclick = function(){
				grow(4);
          }      
        },	
        '#box5 a.kleiner-kasten-navi' : function(el){
          el.onclick = function(){
				grow(4);
          }      
        },	
        '#seiten-link1' : function(el){
          el.onclick = function(){
				hidepageboxes(1);
				return false;
          }      
        },	
        '#seiten-link2' : function(el){
          el.onclick = function(){
				hidepageboxes(2);
				return false;
          }      
        },	
        '#seiten-link3' : function(el){
          el.onclick = function(){
				hidepageboxes(3);
				return false;
          }      
        },	
        '#seiten-link4' : function(el){
          el.onclick = function(){
				hidepageboxes(4);
				return false;
          }      
        },	
        '#seiten-link5' : function(el){
          el.onclick = function(){
				hidepageboxes(5);
				return false;
          }      
        },
        '#seiten-link6' : function(el){
          el.onclick = function(){
				hidepageboxes(6);
				return false;
          }      
        },
        'a.resize-container' : function(el){
          el.onclick = function(){
growContent();
          }
			 }		
			 ,
        'a.nachoben' : function(el){
          el.onclick = function(){
growContent(2);
          }
			 }			
		  								  
		  
    
      };
Behaviour.register(theRules);



		
		
//Scale the Contentbox relative needs a new custom Effect for scriptaculous

Effect.Scaleem = Class.create();
Object.extend(Object.extend(Effect.Scaleem.prototype, Effect.Base.prototype), {
  initialize: function(element, percent) {
    this.element = $(element)
    var options = Object.extend({
      scaleX: true,
      scaleY: true,
      scaleContent: true,
      scaleFromCenter: false,
      scaleMode: 'box',        // 'box' or 'contents' or {} with provided values
      scaleFrom: 100.0,
      scaleTo:   percent
    }, arguments[2] || {});
    this.start(options);
  },
  setup: function() {
    this.restoreAfterFinish = this.options.restoreAfterFinish || false;
    this.elementPositioning = this.element.getStyle('position');
    
    this.originalStyle = {};
    ['top','left','width','height','fontSize'].each( function(k) {
      this.originalStyle[k] = this.element.style[k];
    }.bind(this));
      
    this.originalTop  = this.element.offsetTop;
    this.originalLeft = this.element.offsetLeft;
    
    var fontSize = this.element.getStyle('font-size') || '100%';
    ['em','px','%'].each( function(fontSizeType) {
      if(fontSize.indexOf(fontSizeType)>0) {
        this.fontSize     = parseFloat(fontSize);
        this.fontSizeType = fontSizeType;
      }
    }.bind(this));
    
    this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
    this.dims = null;
    if(this.options.scaleMode=='box')
      this.dims = [200, 400];
		//this.dims = [this.element.offsetHeight, this.element.offsetWidth];
    if(/^content/.test(this.options.scaleMode))
      this.dims = [this.element.scrollHeight, this.element.scrollWidth];
    if(!this.dims)
      this.dims = [this.options.scaleMode.originalHeight,
                   this.options.scaleMode.originalWidth];
  },
  update: function(position) {
    var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
    if(this.options.scaleContent && this.fontSize)
      this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
    this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
  },
  finish: function(position) {
    if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
  },
  setDimensions: function(height, width) {
    var d = {};
    

	 if(this.options.scaleX) d.width = width + 'em';
    if(this.options.scaleY) d.height = height + 'em';
    if(this.options.scaleFromCenter) {
      var topd  = (height - this.dims[0])/2;
      var leftd = (width  - this.dims[1])/2;
      if(this.elementPositioning == 'absolute') {
        if(this.options.scaleY) d.top = this.originalTop-topd + 'em';
        if(this.options.scaleX) d.left = this.originalLeft-leftd + 'em';
      } else {
        if(this.options.scaleY) d.top = -topd + 'em';
        if(this.options.scaleX) d.left = -leftd + 'em';
      }
    }
	 //alert(d.height); //debug
    this.element.setStyle(d);
  }
});

function DOMinsert() {
 new Insertion.After('link5', '<a class="haupt no-print" href="#"><span>Kontakt u. Termine</span></a>');
  new Insertion.After('link4', '<a class="haupt no-print" href="#"><span>&Uuml;ber uns</span></a>');
 new Insertion.After('link3', '<a class="haupt no-print" href="#"><span>Kunden, Kommentare, Kooperationen</span></a>');
  new Insertion.After('link2', '<a class="haupt no-print" href="#"><span>Unternehmen Profit</span></a>');
   new Insertion.After('link1', '<a class="haupt no-print" href="#"><span>Unternehmen Non-Profit</span></a>');
new Insertion.Top('upanddown', '');
}
