 function overs(element){
	returnObjById( element).style.backgroundColor='#EFEDD1';	
 }
 function outs(element,nr){
   if(nr!=2){
	returnObjById( element).style.backgroundColor='#E5E1A6';	
	} else{
    returnObjById( element).style.backgroundColor='#C7C38B';
   }
 }

function returnObjById( id )
{
	if (document.getElementById)
	var returnVar = document.getElementById(id);
	else if (document.all)
	var returnVar = document.all[id];
	else if (document.layers)
	var returnVar = document.layers[id];
	return returnVar;
}


// the slides - relative or complete urls for any number of swappable images

var slides = new Array('grafiki/mini/boisko.jpg','grafiki/mini/korty.jpg','grafiki/mini/bilard.jpg','grafiki/mini/grill.jpg','grafiki/mini/silownia.jpg');

var slideIndex = 0; // which slide are we viewing?

var fadeTimer = 2; // time, in seconds, it takes to swap images

var swapTimer = 6; // time, in seconds, between image swaps

var fadeName='fadeBox';


// gotta set it all up before we run it...

function initSwap() {
    var fadeBox = returnObjById(fadeName);

    for(var i=0;i<slides.length;i++) {

        // hooray for the DOM

        var slide = document.createElement('img'); // a new image

        slide.src = slides[i]; // should show this image

        slide.style.position = "absolute"; // important so images stay on top of each other

        slide.style.opacity = '0'; // init to transparent (CSS2)

        slide.style.filter = 'alpha(opacity:0)'; // init to transparent (MSIE)

        fadeBox.appendChild(slide); // put the image in the box

        slides[i] = slide; // reassign to same array for convenience

        // if it's the first image, let's show it now to avoid waiting

        if(i==0) {

            fade(i,1); // fade it in!

            setTimeout(doSwap,swapTimer*1000); // start the swap timer!

        }

        // repeat for each slide

    }

}

 

function doSwap() {

    var s1 = slideIndex; // where *are* we?

    var s2 =( s1+1==slides.length)?0:s1+1; // either the next or the first

    // we just wrapped to the beginning if we hit the end of the array, so...

    slideIndex = s2; // update slide index
	fade(s1,0); 
    fade(s2,1);
// fade the old slide out!

     // fade the new slide in!

    setTimeout(doSwap,swapTimer*1000); // do it again in swapTimer seconds!

}

 

function fade(whoid,dir) {

    var slide = slides[whoid]; // get the slide element at index whoid

    var completed; // so we know when the fade is done

    var opac = parseFloat(slide.style.opacity,10); // get a reference value

    // increment if fading in, decrement if fading out

    if(dir > 0) {

        opac +=0.01; // more opaque

        if(opac >= 1) {

            // fade is at max! fade done!

            completed = true;

        }

    } else {

        opac -=0.01; // less opaque

        if(opac <= 0) {

            // fade is at min! fade done!

            completed = true;

        }

    }

    slide.style.opacity = opac; // set opacity (CSS2)

    slide.style.filter = 'alpha(opacity:'+(opac*100)+')'; // set opacity (MSIE)

    if(!completed) {

        // as long as the fade is not complete, keep doing this in 1/10 increments within fadeTimer seconds

        setTimeout("fade("+whoid+","+dir+")",parseInt(fadeTimer/10,10));

    }

}

