//cambia imagenes de ultimas expos
function objImage(imgTag, img1, img2, img3) {

	this.imgTag = imgTag;
	
	this.width = 100;
	this.height = 100;
	this.imgAr1 = new Array();
	this.rImg1 = new Array();
	
	//Aqui se aņaden o quitan imagenes
	this.imgAr1[0] = "img_expos/"+img1;
	this.imgAr1[1] = "img_expos/"+img2;
	this.imgAr1[2] = "img_expos/"+img3;
	
	for(var j = 0; j < this.imgAr1.length; j++)
	{
			this.rImg1[j] = new Image();
			this.rImg1[j].src = this.imgAr1[j];
	}
	
	this.slide;
	this.picture = -1;
	this.first = true;
	this.setting = setting;
	this.slideshow = slideshow;
	this.opacity = opacity;
	this.changeOpac = changeOpac;
	this.shiftOpacity = shiftOpacity;
	this.obj = imgTag + "Object"; 
	eval(this.obj + "=this") 

}
function setting()
{
	this.slide = document.getElementById(this.imgTag);
	this.slide.src = this.imgAr1[0];
	//this.slide.setAttribute("width",this.width);
	//this.slide.setAttribute("height",this.height);
	if (this.first) {
		this.slideshow();
		this.first = false;
	}
}

function slideshow(){
	
	if (document.getElementById(this.imgTag) != null) {
		if(this.picture >= this.imgAr1.length-1) this.picture = -1;
		this.shiftOpacity(this.imgTag, 700);
		this.picture=this.picture+1;
		this.slide.src = this.imgAr1[this.picture];

		setTimeout(this.obj+".shiftOpacity('"+this.imgTag+"', 800)", 6100);
	}
	setTimeout(this.obj+".slideshow()", 7000);
}

//Opacidad
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
if (document.getElementById(id) != null) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
	if (document.getElementById(id) != null) {
	//alert(id +", "+document.getElementById(id).style.opacity )
		if(navigator.appName=="Microsoft Internet Explorer" ) {
			if(document.getElementById(id).style.opacity >= 0.95) {
				opacity(id, 99, 0, millisec);
				//alert("uno")
			} else {
				opacity(id, 0, 99, millisec);
				//alert("dos")
			}
			
		}
		else {
			if(document.getElementById(id).style.opacity == 0) {
				opacity(id, 0, 99, millisec);
			} else {
				opacity(id, 99, 0, millisec);
			}
		}
	}
} 
