// *****************************************************************
// eBD GUI.
// ObjectItemFotos.js
// *****************************************************************

var eBDObjectItemFotosID=0;
function ObjectItemFotos(name,descripcion,sel_name,ico,posicion,id_foto,href,clase_href,fecha_cre,comentarios_precio,tipo,clase1,clase2,literal_tipo,literal_comentario, publica, publica_alt)
{
	this.type = 'foto';
	this.idwidget = eBDObjectItemFotosID++;
	this.name = name;
	this.descripcion = descripcion;
	this.sel_name = sel_name;
	this.ico = ico;
	this.posicion = posicion; //La foto es Vertical (V) u horizontal (H)
	this.href = href;
	this.id_foto = id_foto;
	this.clase_href = clase_href;
	this.target = null;
	this.columns = new Array();
	this.fecha_cre = fecha_cre;
	this.totalfotos = comentarios_precio;
	this.publica = publica;
	this.publica_alt = publica_alt;
	this.tipo = tipo; //indica si la foto es de tipo mis fotos (mias), yo he compartido (he_compartido), me han compartido (me_comparte) u otras (todas). Tb si son fotos de una coleccion (colecciones)
	this.baseclass = clase1;
	this.classselected = clase2;
	this.literal_tipo = literal_tipo;
	this.literal_comentario = literal_comentario;
	this.literal_crear_producto = "";
	this.href_crear = "";
		
	this.opened=false;
	this.selected=false;
	this.active=false;
	
	this.setClass = ObjectItemFotos_setClass;
	this.getHTML = ObjectItemFotos_getHTML;
	this.getIdFoto = ObjectItemFotos_getIdFoto;
	this.getMultipleHTML = ObjectItemFotos_getMultipleHTML;
	this.setSelected = ObjectItemFotos_setSelected;
	this.repaint = ObjectItemFotos_repaint;
	this.addColumnHTML = ObjectItemFotos_addColumnHTML;
	this.setTarget = ObjectItemFotos_setTarget;
	this.getTotalFotos = ObjectItemFotos_getTotalFotos();
	this.getHTML_Blog = ObjectItemFotos_getHTML_Blog;
	this.getHTML_BlogMini = ObjectItemFotos_getHTML_BlogMini;
}

function ObjectItemFotos_setTarget(t)
{ this.target=t; }

function ObjectItemFotos_setClass(baseclass)
{ this.baseclass = baseclass; }

function ObjectItemFotos_getIdFoto()
{ return this.id_foto; }

function ObjectItemFotos_addColumnHTML(html)
{ this.columns[this.columns.length] = html; }

function ObjectItemFotos_setSelected(b,tr)
{
	this.selected=b;
	if (this.selected && this.tr == null)
	{ this.tr = tr; }
	this.repaint();	
}

function ObjectItemFotos_repaint()
{
	if (this.tr != null)
	{		
		if (this.selected)
		{ 
			this.tr.className = this.classselected; 
		}
		else
		{ this.tr.className = this.baseclass; }
	}
}

function ObjectItemFotos_getMultipleHTML(home,cols,aligns,actived)
{
	var str = "<td class=\"objectManager_rowcell\"";
	str += "><span class=\"objectManager_text\">";

	if (this.tab > 0)
        {
                var l = this.tab * 20;
                str += "<img src=\"" + home + "images/point.gif\" alt=' ' height=1 width=\"" + l + "\">";
        }


	str+="<table border=0 cellspacing=0 cellpadding=0><tr>";
	str += "<TD><INPUT TYPE=CHECKBOX NAME="+this.ico+"></TD>";
	str += "<td bgcolor=\""+this.ico+"\"> <img border=0 src=\""+home+"images/preview_color.gif\" alt='' width=16 heighy=16 class='objectManager_ico'> </td>";
        //str += "<img border=0 src=\"" + home + this.ico + "\" alt='' width=16 height=16 class='objectManager_ico'>";
	str+="<td>";

	if (this.href != null) {
        	str += "<a class=\"objectManager_link\" href=\"" + this.href + "\" ";
        	if (this.target != null)
        	{ str += " target=\"" + this.target + "\" "; }
		str += ">" + this.name + "</a>";
	}
        else { str += this.name  }

        if (this.text != null && this.text != '') {
                str+=" ("+this.text+")</span></td></tr></table>"
        }
        else {str += "</span></td></tr></table>" }

	return str;
}

function ObjectItemFotos_getTotalFotos()
{
	return this.totalfotos;
}

function ObjectItemFotos_getHTML(home,cols,aligns,actived)
{
//	var str = "<tr class=\"" + this.baseclass + "\"";
	//if(actived){str += " onmousedown=\"return objmanager.clicked(event," + this.idwidget + ",this);\"";}
	
	var literal_fotos; 
	var tipo_foto;
	var posicion_f = '12px 0px 14px 0px'; //Posicion de la foto respecto el td Por defecto horizontal
	var posicion_t = '0px 0 0 0'; //Posicion de la foto respecto el td
	var str='';
	var longitud= 18; //longitud maxima del nombre de la foto para que quepa en una linea
	var texto_cortado=this.name;
	var literal; //Literal del alt de la imagen de compartir

	if (texto_cortado.length > longitud)
	{
		texto_cortado = texto_cortado.substring(0,longitud-4)+'...';
	}
	
	if (this.totalfotos != 1)
	{
		literal_fotos = objmanager.getLiteralFotos();
	}else
	{
		literal_fotos = objmanager.getLiteralFoto();
	}
	str += '<td class="'+this.baseclass+'" align="center" id="td_'+this.id_foto+'" onclick="objmanager.clicked(event,' + this.idwidget + ',this);">';
	if (this.posicion == "V")
	{
		posicion_f = '4px 0px 0px 0px';
		posicion_t = '4px 0 0 0';
	}
	if (this.href != null)
		str += '<div style="padding:'+posicion_f+';margin:0;" onDblClick="abrir_dialogo(\'espere_abrir\',\'contenedor_esperar\',300,100,null);redirigir_dobleclick(\''+this.href+'\');"><img src="'+this.ico+'" alt="'+this.name+'"  title="'+this.name+'"></div>';
	else
		str += '<div style="padding:'+posicion_f+';margin:0;"><img src="'+this.ico+'" alt="'+this.name+'" title="'+this.name+'"></div>';
	str += '<div style="padding:'+posicion_t+';margin:0;">';
	if (this.href != null)
		str += '<a href="'+this.href+'" class="'+this.clase_href+'" title="'+this.name+'">';
	else
		str += '<span style="color: #333333;font: bold 11px Arial;">';
	str += texto_cortado;
	if (this.href != null)
		str += '</a>';
	else
		str += '</span>';
		
	if (this.fecha_cre != null)
		str += '<br><font style="font: normal 9px Arial;color:#333333;">'+this.fecha_cre;
	//Tipo de foto,  segun sea compartida, mis carpetas o me han compartido
	switch (this.tipo)
	{
		case "mias":
			tipo_foto = "imatge_negre.gif";
			break;
		case "he_compartido":
			tipo_foto = "imatge_verd.gif";
			break;
		case "me_comparten":
			tipo_foto = "imatge_blau.gif";
			break;
	}
	if (this.tipo == 'mias' || this.tipo == 'he_compartido' || this.tipo == 'me_comparten') //De Mis fotos
	{
		str += '&nbsp;&nbsp;<img src="/imgfiles/Imagenes_mi_dichis/fotos/'+this.publica+'" alt="'+this.publica_alt+'" align="middle"> <img src="/imgfiles/Imagenes_mi_dichis/fotos/'+tipo_foto+'" alt="'+this.literal_tipo+'" align="middle"> <img src="/imgfiles/Imagenes_mi_dichis/fotos/comentarios.gif" alt="'+this.literal_comentario+' " align="middle"> '+this.totalfotos+'</div>';
	}
	if (this.tipo == 'colecciones') //Fotos de mis colecciones
	{
		str += '&nbsp;&nbsp;<font color="#be282d">'+this.totalfotos+' &euro;</font>';
	}
	if (this.tipo == 'guardar_compartida') //De las fotos que se comparten. Pantalla de guardar compartidas
	{
		str += '&nbsp;&nbsp;<img src="/imgfiles/Imagenes_mi_dichis/fotos/comentarios.gif" alt="'+this.literal_comentario+' " align="middle"> '+this.totalfotos+'</div>';
	}
	str += '</td>';
	
	return str;
}


function ObjectItemFotos_getHTML_Blog(home,cols,aligns,actived)
{	

	var literal_fotos; 
	var tipo_foto;
	var posicion_f = '17px 0px 12px 0px'; //Posicion de la foto respecto el td Por defecto horizontal
	var posicion_t = '0px 0 0 0'; //Posicion de la foto respecto el td
	var str='';
	var longitud=20; //longitud maxima del nombre de la foto para que quepa en una linea
	var texto_cortado=this.name;
	var literal; //Literal del alt de la imagen de compartir

	if (texto_cortado.length > longitud)
	{
		texto_cortado = texto_cortado.substring(0,longitud-4)+'...';
	}
	
	if (this.totalfotos != 1)
	{
		literal_fotos = objmanager.getLiteralFotos();
	}else
	{
		literal_fotos = objmanager.getLiteralFoto();
	}
	str += '<td align="left" valign="top" style="padding-left: 5px" valign="top" onclick="objmanager.clicked(event,' + this.idwidget + ',this);">';
	if (this.posicion == "V")
	{
		posicion_f = '4px 0 4px 0';
		posicion_t = '4px 0 4px 0';
	}
	str += '<div style="padding:'+posicion_t+';margin:0;background:white;padding:5px;border:1px solid #E2E1DF;"><span class="txtBlog"><b>'+texto_cortado+'</b></span></div>';

	str += '<div class="baseBlogFotos" style="width:244px;">';
	str += '<div style="padding:'+posicion_f+';margin:0;" width="100%" align="center"><a href="'+this.href+'"><div style="border: solid 1px #f7f6f4"><img src="'+this.ico+'" alt="'+this.name+'" border="0"></div></a></div>';
		
	str += '<div style="background-color: white; padding: 10px 0 10px 0; text-align: left;">';
	
	str += '<div style="padding:'+posicion_t+';margin:5px;" class="txtDescBlog">'+this.descripcion+'</div>';
	str += '<div style = "background: transparent url(/imgfiles/Imagenes/punts_discontinuos.gif) repeat-x scroll 0%; overflow: hidden; height: 20px; width: 100%;";></div>';
	
	//Comentarios
	str += '<table border="0" width="100%" style="font:normal 9px Arial;color:#999;"><tr><td>';
	
	// Aqui, fecha_cre es la data del ultim comentari.
	if (this.fecha_cre != '') 
	{ 	str += this.fecha_cre+"&nbsp;&nbsp;&nbsp;"; }

   //tipo_foto = "imatge_negre.gif";
	//str += '&nbsp;&nbsp;<img src="/imgfiles/Imagenes_mi_dichis/fotos/'+tipo_foto+'" alt="'+this.literal_tipo+'" align="middle">';
	str += '&nbsp;<img src="/imgfiles/Imagenes_mi_dichis/fotos/comentarios.gif" alt="'+this.literal_comentario+' " align="middle"> ' + this.totalfotos + '&nbsp;'+this.literal_comentario;
	str += '</td><td align="right"><img src="/imgfiles/Imagenes/iconos/b_afegir_com_off.gif" alt="'+this.literal_comentario+' " align="middle" class="icono_off" onMouseOver="this.className=\'icono_on\';" onMouseOut="this.className=\'icono_off\';" onClick="location.href=\''+this.href+'\';"></td>';

	str += '</tr></table>';
	//crear producto
	if (this.href_crear != '')
	{
		str += '<div style="background:#EFEFEF;text-align:right;margin:4px;padding-right:4px;"> <a href="'+this.href_crear+'" class="arial_9_norm_99"> > '+this.literal_crear_producto+'</a></div>';
	}
	str += '</div></td>';
	
	return str;
}

function ObjectItemFotos_getHTML_BlogMini(home,cols,aligns,actived)
{	

	var posicion_f = '12px 1px 12px 1px'; //Posicion de la foto respecto el td Por defecto horizontal
	var str='';

	str += '<td align="left" valign="top" onclick="objmanager.clicked(event,' + this.idwidget + ',this);">';
	if (this.posicion == "V")
	{
		posicion_f = '2px 11px 2px 11px';
	}
	//str += '<div class="baseBlogFotos" width="84px"><div style="padding:'+posicion_f+';margin:0;" width="100%" align="center"><a href="'+this.href+'"><div style="border: solid 1px #f7f6f4"><img src="'+this.ico+'" alt="'+this.name+'" border="0"></div></a></div></div>';

	str += '<div class="baseBlogFotos" hstyle="width:84px;height:98px;"><a href="'+this.href+'"><div style="border: solid 1px #f7f6f4"><img src="'+this.ico+'" alt="'+this.name+'" border="0" style="margin:'+posicion_f+';"></div></a></div>';
	
	return str;
}

