// JavaScript Document
var classPrecarga = function(nom, imgs, elem){
	//Variables
	var obj = nom;
	this.imagenes = imgs;
	this.elem = elem;
	this.carp = 'img/';
	this.time = 200;
	this.funfin = '';
	this.num = 0;
	
	//Metodos
	this.iniciar = function(){
		this.interv = setInterval(obj+".precargar()", this.time);
	}
}

classPrecarga.prototype.precargar = function(){
	setEstilo(this.elem, 'background-image', 'url('+this.carp+this.imagenes[this.num]+')');
	this.num++;
	if(this.precargados()){
		clearInterval(this.interv);	
		if(this.funfin!='')
			eval(this.funfin+"();");
	}
}

classPrecarga.prototype.precargados = function(){
	if(this.num<this.imagenes.length)
		return false;
	return true;
}

//Funcion que asigna el valor del parametro del elemento seleccionado
function setEstilo(elemid, prop, val){
	//alert(elemid+" "+prop+" "+val);
	var elem = document.getElementById(elemid);
	prop = prop.replace(/\-(\w)/g, function (strMatch, p1) {
		return p1.toUpperCase();
	});
	if(elem!=null)
		elem.style[prop] = val;
}
