// slideshow class
// 2008-12-10


function slideshow2(objPic1, objPic2, objText) {

    var thisObj = this;
    this.objPic1 = objPic1;
    this.objPic2 = objPic2;
    this.objText = objText;
    var thisSlide = -2;
    this.slides = null; 	// array
    this.fadeTime = 2000;
    this.slideTime = 10000;
    this.clock = 50;
    var t = null;

    this.objPic1.onload = function () {
        thisObj.fadeIn();
    }


    // opacity
    this.changeOpac = function (opacity) {
        var object = this.objPic1.style;
        object.opacity = (opacity / 100);
        object.MozOpacity = (opacity / 100);
        object.KhtmlOpacity = (opacity / 100);
        object.filter = "alpha(opacity=" + opacity + ")";
    }


    // fade out
    this.fadeOut = function () {
        clearInterval(t);

        var date1 = new Date();

        t = setInterval
		(
				function () {
				    var date2 = new Date();
				    var percent = Math.ceil(((date2.getTime() - date1.getTime()) / thisObj.fadeTime) * 100);
				    if (percent > 100) { percent = 100; clearInterval(t); }
				    thisObj.changeOpac(100 - percent);
				},
				thisObj.clock
		);
    }


    // fade in
    this.fadeIn = function () {
        clearInterval(t);

        var date1 = new Date();

        t = setInterval
		(
				function () {
				    var date2 = new Date();
				    var percent = Math.ceil(((date2.getTime() - date1.getTime()) / thisObj.fadeTime) * 100);
				    if (percent > 100) { percent = 100; clearInterval(t); }
				    thisObj.changeOpac(percent);
				},
				thisObj.clock
		);
    }

    // previous
    this.previous = function () {

        thisSlide -= 2;

        // slide anterior para baixo
        if (thisSlide > -4)
            this.objPic2.src = this.slides[thisSlide + 2];

        // nslide
        if (thisSlide < 0) {
            thisSlide = this.slides.length - 2;
        }

        if (this.objPic1.src != this.slides[thisSlide])  // onload Safari
            this.changeOpac(0);

        this.objPic1.src = this.slides[thisSlide];

        if (this.slides[thisSlide + 1] != "") {
            this.objText.innerHTML = ""; // Safari workaround
            this.objText.innerHTML = this.slides[thisSlide + 1];
        }

        // cache for next slide
        var imageObj = new Image();
        if (thisSlide - 2 >= 0) imageObj.src = this.slides[thisSlide - 2];

        //thisObj.fadeIn();

        return false;
    }


    // next
    this.next = function () {

        thisSlide += 2;

        // slide anterior para baixo
        if (thisSlide > 0)
            this.objPic2.src = this.slides[thisSlide - 2];

        // nslide
        if (thisSlide >= this.slides.length) {
            thisSlide = 0;
        }
        
        if (this.objPic1.src != this.slides[thisSlide])  // onload Safari
            this.changeOpac(0);

        this.objPic1.src = this.slides[thisSlide];

        if (this.slides[thisSlide + 1] != "") {
            this.objText.innerHTML = ""; // Safari workaround
            this.objText.innerHTML = this.slides[thisSlide + 1];
        }

        // cache for next slide
        var imageObj = new Image();
        if (thisSlide + 2 < this.slides.length) imageObj.src = this.slides[thisSlide + 2];

        //thisObj.fadeIn();

        return false;
    }


    // show
    this.show = function () {
        this.next();
        setInterval(function () { thisObj.next(); }, thisObj.slideTime);
    }
}



	
function slideshow(objPic, objText)
{

	var thisObj = this;
	this.objPic = objPic;
	this.objText = objText;
	var thisSlide = -2;
	this.slides = null;		// array
	this.fadeTime = 2000;
	this.slideTime = 10000;
	this.clock = 50;
	var t = null;
	
	this.objPic.onload = function()
	{
        thisObj.fadeIn();
	}
	
	
	// opacity
	this.changeOpac = function (opacity) {
		var object = this.objPic.style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";		
	}
	
		
	// fade out
	this.fadeOut = function()
	{
	    clearInterval(t);
	    
		var date1 = new Date();
		
		t = setInterval
		(
				function()
				{
					var date2 = new Date();
					var percent = Math.ceil(((date2.getTime() - date1.getTime()) / thisObj.fadeTime) * 100);
					if (percent > 100) {percent = 100; clearInterval(t);}
					thisObj.changeOpac(100-percent);
				},
				thisObj.clock
		);		
	}
	
	
	// fade in
	this.fadeIn = function()
	{
	    clearInterval(t);
	    
		var date1 = new Date();
		
		t = setInterval
		(
				function()
				{
					var date2 = new Date();
					var percent = Math.ceil(((date2.getTime() - date1.getTime()) / thisObj.fadeTime) * 100);
					if (percent > 100) {percent = 100; clearInterval(t);}
					thisObj.changeOpac(percent);
				},
				thisObj.clock
		);		
	}
	
	// previous
	this.previous = function() {
			
		thisSlide -= 2;
		if (thisSlide < 0) {
			thisSlide = this.slides.length - 2;
		}
		
		if (this.objPic.src != this.slides[thisSlide])  // onload Safari
		    this.changeOpac(0);
		
		this.objPic.src = this.slides[thisSlide];
		
		if (this.slides[thisSlide + 1] != "")
		{
		    this.objText.innerHTML = "";	// Safari workaround
		    this.objText.innerHTML = this.slides[thisSlide + 1];
		}
				
		// cache for next slide
		var imageObj = new Image();
		if (thisSlide-2 >= 0) imageObj.src = this.slides[thisSlide-2];
		
		//thisObj.fadeIn();
				
		return false;
	}
	
	
	// next
	this.next = function() {		
		
		thisSlide += 2;
		if (thisSlide >= this.slides.length) {
			thisSlide = 0;
		}
		
		if (this.objPic.src != this.slides[thisSlide])  // onload Safari
		    this.changeOpac(0);

		this.objPic.src = this.slides[thisSlide];
		
		if (this.slides[thisSlide + 1] != "")
		{
		    this.objText.innerHTML = "";	// Safari workaround
		    this.objText.innerHTML = this.slides[thisSlide + 1];
		}
				
		// cache for next slide
		var imageObj = new Image();
		if (thisSlide+2 < this.slides.length) imageObj.src = this.slides[thisSlide+2];
		
		//thisObj.fadeIn();
		
		return false;
	}
	
	
	// show
	this.show = function()
	{
		this.next();
		setInterval(function() {thisObj.next();}, thisObj.slideTime);
	}
}