function grohaScrollToPos(posNew,lnkActive,lnkPassive) {
   document.getElementById('3schritteInnen').style.marginLeft=posNew;
   document.getElementById(lnkActive).style.fontWeight='bold';
   document.getElementById(lnkPassive).style.fontWeight='normal';
}





/* image-blend-functions */
lnkIdActive = 'prodCatAgrar';
function grohaViewProductImages(start) {
	var blendtimer = 0;
	var blenddelay = 3500;
	var totalDelay = 0;
	shownCnt = 0;
	for(var imageCnt = start; imageCnt < blendImages.length; ++imageCnt) {
		blendtimer = (shownCnt+1)*blenddelay;
		setTimeout("blendimage('itemImageBlendDiv_Products','itemImage_Products','"+blendImages[imageCnt].image+"',1500)",blendtimer);
		setTimeout("grohaChangeLinkProducts('"+blendImages[imageCnt].lnkDiv+"')",blendtimer);
		totalDelay+=blenddelay;
		shownCnt++;
	}
	setTimeout("grohaViewProductImages(0)",totalDelay);
}
function grohaChangeLinkProducts(id) {
//	alert(id);
	var links = document.getElementsByName("productLnk");
	for(var lnkCount=0; lnkCount<links.length;++lnkCount) {
	    if(links[lnkCount].id == id) {
			colorFade(links[lnkCount].id,'background','eeeeee','aaaaaa',60,30)
			lnkIdActive = links[lnkCount].id;
	    }
		else {
				colorFade(links[lnkCount].id,'background','aaaaaa','eeeeee',60,30)
		}
	}
}

function grohaViewImages(start) {
	var blendtimer = 0;
	var blenddelay = 3500;
	var totalDelay = 0;
	shownCnt = 0;
	for(var imageCnt = start; imageCnt < blendImages.length; ++imageCnt) {
		blendtimer = (shownCnt+1)*blenddelay;
		setTimeout("blendimage('itemImageBlendDiv','itemImage','"+blendImages[imageCnt]+"',1500)",blendtimer);
		totalDelay+=blenddelay;
		shownCnt++;
	}
	setTimeout("grohaViewImages(0)",totalDelay);
}


function sohoShowImage (imgId,numImages) {

	//try blending:
	if(imgId != sohoCurrentImageId)
		blendimage('itemImageBlendDiv','itemImage','/elements/gfx/referenzen/'+imgId+'.jpg',250);
	sohoCurrentImageId = imgId;
	for(var i=1;i<=numImages;i++) {
		lnkContainer = document.getElementById("imgLnk_"+i);
		//alert(lnkContainer.rel);
		if(lnkContainer.rel!=imgId) { //falsch !!!
			lnkContainer.style.color='rgb(180,180,180)';
		} else {
			lnkContainer.style.color='#fff';
		}
	}
	return false;
}

function sohoShowImageOver (imgId,numImages) {
	if(imgId != sohoCurrentImageId)
		blendimage('itemImageBlendDiv','itemImage','/elements/gfx/referenzen/'+imgId+'.jpg',250);
}
function sohoShowImageOut (imgId,numImages) {
	if(imgId != sohoCurrentImageId)
		blendimage('itemImageBlendDiv','itemImage','/elements/gfx/referenzen/'+sohoCurrentImageId+'.jpg',250);
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
}

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    imagefile = imagefile.replace(/\/groha\.de/g,'');
    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    //make image transparent
    changeOpac(0, imageid);

    //make new image
    document.getElementById(imageid).src = imagefile;
    newBigImage = imagefile.replace('/produkte/','/produkteGross/');
	document.getElementById('blendImageLink').href=newBigImage;

    //hide old background:
//    setTimeout(document.getElementById(divid).style.backgroundImage = "url(/elements/gfx/white.gif)",(100*speed));

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
}

// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16),
    parseInt(color.substring(2,4),16),
    parseInt(color.substring(4,6),16)];
  return rgb;
}