﻿var MAX_IMAGENES=8;function GestorImagenes(c,b){this.id=c;this.imagenes;this.numeroImagenes=0;this.idPortada=0;if(b){this.numeroImagenes=parseInt(b.substr(0,1));this.idPortada=parseInt(b.substr(1,1));this.imagenes=b.substr(2,MAX_IMAGENES).split("")}else{this.imagenes=new Array(MAX_IMAGENES);for(var a=0;a<MAX_IMAGENES;a++){this.imagenes[a]=0}}}GestorImagenes.prototype.Descriptor=function(){return(String(this.numeroImagenes)+String(this.idPortada)+this.imagenes.join(""))};GestorImagenes.prototype.Lleno=function(){return(this.numeroImagenes>=MAX_IMAGENES)};GestorImagenes.prototype.Existe=function(a){return(1==this.imagenes[a-1])};GestorImagenes.prototype.SetPortada=function(b){if(b){if((b!=this.idPortada)&&(this.Existe(b))){this.idPortada=b}}else{if(!this.idPortada){for(var a=1;a<=MAX_IMAGENES;a++){if(this.Existe(a)){this.idPortada=a;break}}}}};GestorImagenes.prototype.Eliminar=function(b){var a;if(this.Existe(b)){a=this.GetImagen(b);this.numeroImagenes--;this.imagenes[b-1]=0;if(b==this.idPortada){this.idPortada=0;this.SetPortada()}}return(a)};GestorImagenes.prototype.Nuevo=function(){var b=0;if(!this.Lleno()){for(var a=1;a<=MAX_IMAGENES;a++){if(!this.Existe(a)){b=a;break}}this.imagenes[b-1]=1;this.numeroImagenes++;this.SetPortada()}return(b)};GestorImagenes.prototype.GetImagen=function(b){var a;var c=this.id;if(this.Existe(b)){a={id:b,miniatura:"{0}-{1}.jpg".Format(c,b),normal:"{0}-{1}b.jpg".Format(c,b),esPortada:(b==this.idPortada)}}else{a=null}return(a)};GestorImagenes.prototype.GetPortada=function(){return(this.GetImagen(this.idPortada))};GestorImagenes.prototype.GetImagenes=function(){var a=new Array();for(var b=1;b<=MAX_IMAGENES;b++){if(this.Existe(b)){a.push(this.GetImagen(b))}}return(a)};