 var pic = new Image();
 var timer;
 var picload = -1;
 var pictureId;
 var first_pic = 100;
 var second_pic = 0;
 var sec = 0;
 var currentPictureId = -1;
 var dw = "http://www.euromotoec.com/Pic/"
 var pictures = new Array("RXV.jpg","Local1.jpg","Stelvio.jpg","Local3.jpg","Shiver.jpg","Local4.jpg","Local2.jpg");
 var total_pictures = pictures.length;
 var slideshow_started = true;
 var start = 0;

 var disabled_opacity = false;
 var step_opacity = 2;
 var step_time = 2;

 var sleep_time = 4000;


 function PicLoading() {
	if (pic.complete == true || picload == -1) {
		if (picload+1 < total_pictures) {
			picload++;
			pic = new Image();
    		pic.src = dw + pictures[picload];
		} else { picload = total_pictures+1; }
	}
 }
 

 function checkLoading(pictureId) {
	 
	currentPictureId = pictureId;	
    document.getElementById("after").src = dw + pictures[currentPictureId];
    changeSlide();
 }

 function changeSlide() {

    first_pic = first_pic - step_opacity;
    second_pic = second_pic + step_opacity;

    document.getElementById("before_div").style.opacity = first_pic / 100;
    document.getElementById("after_div").style.opacity = second_pic / 100;
    document.getElementById("after_div").style.filter = "alpha(opacity=" + second_pic + ")";
    document.getElementById("before_div").style.filter = "alpha(opacity=" + first_pic +")";

    if (second_pic >= 98) {

       clearTimeout(timer);
       document.getElementById("before").src = dw + pictures[currentPictureId];
       document.getElementById("before_div").style.opacity = 100;
       document.getElementById("before_div").style.filter = "alpha(opacity=0)"; 
       document.getElementById("after_div").style.opacity = 0;
       document.getElementById("after_div").style.filter = "alpha(opacity=100)";
       first_pic = 100;
       second_pic = 0;  
	   
	   ShowNextImage2();
	   

    } else {

       timer = setTimeout("changeSlide()", step_time);
    }
 }

 function ShowNextImage2() {
	PicLoading();
    start = new Date().getTime();
	ShowNextImage();
 }
 
 function ShowNextImage() {
	PicLoading(); 
	pictureId = (currentPictureId + 1 == total_pictures) ? 0 : currentPictureId + 1; 
	if (start + sleep_time < new Date().getTime() && picload > pictureId) {
    	checkLoading(pictureId);
	} else {
		PicLoading();
		timer = setTimeout("ShowNextImage()", 1000);	
	}
 }

