//Author: Wiktor Jarka - wiktor.jarka.pl
        var ul = document.getElementById("slideshow");
		var wrapper = document.getElementById("wrapper");		
		var width = wrapper.style.width.replace('px','');//413;
		var height = wrapper.style.height.replace('px','');//310;
		var items = ul.getElementsByTagName("img");		
		var ratio;
		var margin;				
		function switchImg(i) {	
			if (i == items.length) {
				i = 0;
			}
			if (items == null || wrapper == null || ul == null) {
				return;
			}
			var img = new Image();
			img.style.filter = "alpha(opacity:0)";            
            // Safari
            img.style.KHTMLOpacity = 0;             
            // Older Mozilla and Firefox
            img.style.MozOpacity = 0;
            // Safari 1.2, newer Firefox and Mozilla, CSS3
            img.style.opacity = 0;
			wrapper.innerHTML = '';								
			img.src = items[i].src;			
			if (img.width > img.height) {
				ratio = img.width / width;
				img.width = width;	
				img.style.width = img.width;		
				img.height = img.height / ratio;
				img.style.height = img.height;
				margin = (height - img.height) / 2;			
				img.style.marginTop = Math.ceil(margin) + "px";
				img.style.marginBottom = Math.floor(margin) + "px";			
			} else {				
				ratio = img.height / height;
				img.height = height;	
				img.style.height = img.height;		
				img.width = img.width / ratio;
				img.style.width = img.width;
				margin = (width - img.width) / 2;			
				img.style.marginLeft = Math.ceil(margin) + "px";
				img.style.marginRight = Math.floor(margin) + "px";
			}		
			wrapper.appendChild(img);
			
			setOpacity(img, 0, 1);			
			setTimeout(function() {
				setOpacity(img, 100, -1);
			}, 4500);
			setTimeout(function() {
				switchImg(i+1);
			}, 5000);
		}
		function setOpacity(img, opacity, direction) {
			//var img = wrapper.getElementsByTagName('img');			
            img.style.filter = "alpha(opacity:"+opacity+")";            
            // Safari
            img.style.KHTMLOpacity = opacity/100;             
            // Older Mozilla and Firefox
            img.style.MozOpacity = opacity/100;
            // Safari 1.2, newer Firefox and Mozilla, CSS3
            img.style.opacity = opacity/100;
            if (direction > 0 && opacity == 100) {
            } else if (direction <0 && opacity == 0) {
            } else {
                setTimeout(function() {
                    setOpacity(img, opacity+10*direction, direction);
                }, 50);
            }                                    
		}				
		switchImg(0);

