var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
      //c.style.opacity = 1;
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
  	//c.style.display = 'none';
    //c.style.height = '0px';
    h.timer = setTimeout(function(){c.style.height = '0px';},20);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  if(c.style.height=="4px") c.style.height="0px"; //changed by PeterM
  c.style.opacity = currh / c.maxh; //changed by PeterM
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}




// SeViR Simple Horizontal Accordion @2007
// http://letmehaveblog.blogspot.com
jQuery.fn.extend({
  haccordion: function(params){
    var jQ = jQuery;
    var params = jQ.extend({
      speed: 500,
      headerclass: "header",
      contentclass: "content",
      contentwidth: 440
    },params);
    return this.each(function(){
    
    	this.opened = jQ("."+params.contentclass,this).filter(".visible").prev();
    
      jQ("."+params.headerclass,this).click(function(){
      	
        var p = jQ(this).parent()[0];
        if (p.opened != "undefined"){
          jQ(p.opened).next("div."+params.contentclass).animate({
            width: "0px"
          },params.speed);
        }
        p.opened = this;
        jQ(this).next("div."+params.contentclass).animate({
          width: params.contentwidth + "px"
        }, params.speed);
      });
    });
  }
});

/* contentwidth: 512 bei 6 Reitern */
/* contentwidth: 476 bei 7 Reitern */
/* contentwidth: 440 bei 8 Reitern */

/* ----------------------------------------*/
/* Accordion New und Old                   */ 
/* ----------------------------------------*/
function SetSel(id) {	
	for (i=1; i<=6; i++) {
		document.images["img_"+i].src = "http://www.lenzing.com/css/images/sub/acc_fibers/h"+i+"_no.gif";
	}
	document.images["img_"+id].src = "http://www.lenzing.com/css/images/sub/acc_fibers/h"+id+"_a.gif";
}

/* ----------------------------------------*/
/* Accordion New mit On mouseover (Reiter) */ 
/* ----------------------------------------*/

var slideMenu=function(){
	var sp,st,t,m,sa,l,w,sw,ot;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s; st=sw; t=mt;
			m=document.getElementById(sm);
			sa=m.getElementsByTagName('li');
			l=sa.length; w=m.offsetWidth; sw=w/l;
			ot=Math.floor((w-st)/(l-1)); var i=0;
			for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)}
			if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)}
		},
		timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}},
		slide:function(s){
			var cw=parseInt(s.style.width,'10');
			if(cw<st){
				var owt=0; var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10');
						if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'}
						owt=owt+(ow-oi)}}
				s.style.width=(w-owt)+'px';
			}else{clearInterval(m.timer)}
		}
	};
}();


$(document).ready(function(){
	if ( $("#sm").length > 0 ) {
		slideMenu.build('sm',548,11,11,1);
		/* 548 bei 6 Reitern */
		/* 512 bei 7 Reitern */
		/* 476 bei 8 Reitern */	}
	
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
});



