if (document.getElementById && document.getElementsByTagName) {
	if (window.addEventListener) window.addEventListener('load', init, false);
	else if (window.attachEvent) window.attachEvent('onload', init);
}

function init() {

	var animElements = document.getElementById("menu").getElementsByTagName("div");
	for(var i = 0; i < animElements.length; i++) {
		animElements[i].onmouseover = fadeBgIn;
		animElements[i].onmouseout = fadeBgOut;
	}

	function fadeBgIn() {
		if (!this.currentbgRGB) this.currentbgRGB = [0,0,0];
		doFade(this,this.currentbgRGB,[99,33,00],6,25,1);
	}

	function fadeBgOut() {
		if (!this.currentbgRGB) return;
		doFade(this,this.currentbgRGB,[0,0,0],20,25,1);
	} 

	function doFade(elem,startRGB,endRGB,steps,intervals,powr) {
		if (elem.bgFadeMemInt) window.clearInterval(elem.bgFadeMemInt);
		var actStep = 0;
		elem.bgFadeMemInt = window.setInterval(
		function() {
			elem.currentbgRGB = [
			easeInOut(startRGB[0],endRGB[0],steps,actStep,powr),
			easeInOut(startRGB[1],endRGB[1],steps,actStep,powr),
			easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)
			];
			elem.style.backgroundColor = "rgb("+
			elem.currentbgRGB[0]+","+
			elem.currentbgRGB[1]+","+
			elem.currentbgRGB[2]+")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.bgFadeMemInt);
		},intervals)
	}
}

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var step = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(step);
} 

window.onload = function() {
	var imgArray = document.getElementById("suppliers").getElementsByTagName("img");
	imageObj = new Image();
    images = new Array();
	images_alt = new Array();
	for(var i = 1; i <= imgArray.length; i++) {
		images[i] = "f_logo" + i + ".jpg";
		images_alt[i] = "f_logo" + i + "a.jpg";
	}
	for(var i = 1; i <= images.length; i++) {
		imageObj.src = images[i];
		imageObj.src = images_alt[i];
	}
	for(var i = 0; i < imgArray.length; i++) {
		imgArray[i].onmouseover = function() {
			this.src = this.src.substring(0,this.src.lastIndexOf('.')) + 'a' + this.src.substring(this.src.lastIndexOf('.'));
			console.log(this.src);
		}
		imgArray[i].onmouseout = function() {
			this.src = this.src.substring(0,this.src.lastIndexOf('.')-1) + this.src.substring(this.src.lastIndexOf('.'));
			console.log(this.src);
		}
	}
}

/****************************** pre okno onmousemove **********/
function image_load(meno) {
o=0;
port_opacity();
document.getElementById("port_win").style.display='inline';
document.getElementById("port_pic").src=meno;
}
function pohyb_okna(event) {
	var sirka_okna=170;
	var vyska_okna=170;
	var posy = 0;
	if (!e) var e = event;
	if (e.pageY) {
		posy = e.pageY;
		rozdiel=window.innerHeight-e.clientY;
		if (rozdiel<=vyska_okna){
			posy=posy-vyska_okna-5;
		}
	}
	else if (e.clientY) {
		posy = e.clientY + document.documentElement.scrollTop;
		rozdiel= document.documentElement.clientHeight-e.clientY;
		if (rozdiel<=vyska_okna){
			posy=posy-vyska_okna;
		}
	}
	
	document.getElementById("port_win").style.top=posy+'px';
	//document.getElementById("port_win").style.left=event.clientX+10+'px';
		if ((window.innerWidth-event.clientX)>sirka_okna+10){
			document.getElementById("port_win").style.left=event.clientX+10+'px';	
		}else {
			document.getElementById("port_win").style.left=(event.clientX-sirka_okna-10)+'px';	
		}
	}

function port_opacity() {
	o=o+0.1;
	
	if (o>=1) {
	 o=1;
	}

	document.getElementById("port_win").style.opacity=o;
	document.getElementById("port_win").style.filter='alpha(opacity='+o*100+')';
	casovac=setTimeout('port_opacity()',10);
}

function zavri_okno() {
document.getElementById("port_pic").src='/data/loader.gif';
document.getElementById("port_win").style.display='none';
clearTimeout(casovac);
}
/****************************** pre okno onmousemove **********/

