﻿var changeopacity =0;
var opacitynew = 100;
var opacityBoolean = false;
function $(el) {
    if (typeof el == 'string') {
      el = document.getElementById(el);
      return el;
     }
     return;
}
function startAnimation(elementID, newL, newT, time, changeOpaBoolean, newPos2, newTime2, newPos3, newTime3) {
	var el = $(elementID);
	if(el == null)
    	return;
    var steps = 1;
    if(time>0)
    	steps = time/40;
	if(newL!='') {
		var pos = parseInt(el.style.left);
		var newPos = newL;
		var dir = 0;
	} else {
    	var pos = parseInt(el.style.top);
		var newPos = newT;
		var dir =1;
    }
	var dif = newPos - pos;
	if(dif!=0)
		dif/=steps;
		
	if(changeOpaBoolean)
		changeopacity = 100/Math.ceil(steps);
	animate(elementID, pos, newPos, dif, changeOpaBoolean, dir, newPos2, newTime2, newPos3, newTime3);
}
function animate(eID, pos, newPos, dif, changeOpaBoolean, dir, newPos2, newTime2, newPos3, newTime3) {
	if(changeOpaBoolean)
		changeOpac(eID);

	pos += dif;
	if(dif == 0 || (dif>0 && pos>=newPos) ||(dif<0 && pos<=newPos))
		pos = newPos;
	
	if(!dir)
		$(eID).style.left = Math.round(pos) + 'px';
	else
		$(eID).style.top = Math.round(pos) + 'px';
	if(pos == newPos) {
		if(changeOpaBoolean) {
			opacitynew = changeopacity;
			changeOpac(eID);
		}
		if(newPos2!='') {
			if(!dir)
				startAnimation(eID, newPos2, '', newTime2, 0, newPos3, newTime3, '', '');
			else
				startAnimation(eID, '', newPos2, newTime2, 0, newPos3, newTime3, '', '');
		}
    	return;
  	}
    setTimeout( 'animate("'+eID+'",'+pos+','+newPos+','+dif+','+changeOpaBoolean+','+dir+',"'+newPos2+'","'+newTime2+'","'+newPos3+'","'+newTime3+'")', 40);
}
function changeOpac(id) {
	var object = $(id).style;
	opacitynew -= changeopacity;
	object.opacity = (opacitynew / 100);
	object.MozOpacity = (opacitynew / 100);
	object.KhtmlOpacity = (opacitynew / 100);
	object.filter = "alpha(opacity=" + opacitynew + ")";
}
function hide(kategorie) {
	var otherKats = new Array(3);
	otherKats[0] = new Array('prod1','prod2','prod3','prod4','prod5');
	otherKats[1] = new Array('shop1');
	otherKats[2] = new Array('kontakt1','kontakt2','kontakt3');
	for(j=0;j<3;j++) {
		for(i=0;i<otherKats[j].length;i++) {
			var kat = otherKats[j][i];
			if(j!=kategorie) {
				$(kat).style.display = 'none';
				$(kat).style.top = 350+"px";
			} else {
				$(kat).style.display = 'block';
			}
		}
	}
}