//<![CDATA[	

/*     
Proyecto: Web Formato Verde
Nombre: formatoverde.js
Descripcion: Funciones para web Formato Verde
Version: 0.1
Autor: IdeiT S.L., <a href="http://www.ideit.es">IdeiT</a>
Autor URI: http://www.ideit.es
*/


/************************************************************************/
/* USO DE LIGHTBOX
/************************************************************************/
var fileLoadingImage = "/webformatoverde/themes/formatoverde/css/lightbox/loading.gif";
var fileBottomNavCloseImage = "/webformatoverde/themes/formatoverde/css/lightbox/closelabel.gif";
var langImage = "Imagen ";
var langOf = " de ";




/************************************************************************/
/* SLIDE PHOTOS
/************************************************************************/
//Rotación de imágenes de cada producto

function SlidePhoto(ulName)
{
	this.currentImage = 0;
	this.ImageList = $(ulName).getElementsByTagName('li');
	this.NumImages = this.ImageList.length;
	
	//Ocultar todos los lis
	for(i=0; i<this.NumImages; i++)
	{
		if(i > 0)
			$(this.ImageList[i]).hide();
	}
	
	this.nextImage = function() {
		nextImage = this.currentImage + 1;
		if(nextImage == this.NumImages)
			nextImage = 0;		
		
		$(this.ImageList[nextImage]).show();
		$(this.ImageList[this.currentImage]).hide();
		
		//Effect.Fade(this.ImageList[this.currentImage], { duration: 1.5, to: 0.0 });
		//Effect.Appear(this.ImageList[nextImage], { duration: 4.5 });
		
		this.currentImage = nextImage;
	};
}






/************************************************************************/
/* TABS CLASS
/************************************************************************/
//Tabs para la visualizacion de documentos del producto

//Ejemplo de Uso
//var tabsDocument = new TabDocument('panelVisibleInicio', 'EstiloCssVisibleInicio');
var tabsDocument;

function TabDocument(activeDiv, activeClass)
{
	this.ActiveDiv = activeDiv;
	this.ActiveClass = activeClass;
	this.RootPanel = "panelMediaTabs";
	//TODO Inicializar
	
	
	this.Show = function(idDiv, objAnchor)
	{
		if(idDiv != this.ActiveDiv)
		{
			$(this.ActiveDiv).hide(); //Ocultacion y muestra
			$(idDiv).show();
			this.ActiveDiv = idDiv; //Asignacion de bloque
			//Restauro estilo
			var objeto = $(this.RootPanel).getElementsByClassName(this.ActiveClass)[0];
			objeto.className = objeto.className.replace("_on", "");
			
			objAnchor.className = objAnchor.className + "_on"; //Activo estilo
			this.ActiveClass = objAnchor.className; //Asigno nuevo estilo
			objAnchor.blur();			
		}
	};

	this.Hide = function(idDiv)
	{
		$(this.ActiveDiv).hide();
		$(idDiv).show();
	};	
}



/************************************************************************/
/* DESPLIEGE DE NOTICIAS
/************************************************************************/
//Funciones para el despliegue de noticias
//TODO: Añadir mantener estado de la solapa noticias

 var NewsDiv;

function ToggleDiv(divName)
{
	this.State = false; //true|false
	this.DivName = divName; //Nombre del Bloque
	$(divName).hide();
	
	this.Show = function (sender)
	{
		sender.blur();
		Effect.SlideDown(this.DivName);
		this.State = !this.State;
	};
	
	this.Hide = function (sender)
	{
		sender.blur();
		Effect.SlideUp(this.DivName);
		this.State = !this.State;
	};
	
	this.Toggle = function (sender)
	{
		if(this.State)
			this.Hide(sender);
		else
			this.Show(sender);
	};
}






/************************************************************************/
/* ENTRADA DE PRODUCTOS
/************************************************************************/
/* Objeto EntryProduct */

function EntryProduct()
{
	this.oImage;
	this.oSchema;
	this.idProduct;
	this.cssClass;
}

/* Objeto para Entrada a Productos */
function ProductEntry(divImage, divDesign, idImage, idDesign)
{
	this.IdDivImage = divImage;
	this.IdDivDesign = divDesign;
	this.IdImage = idImage;
	this.IdDesign = idDesign;
	this.Images = new Array();
	this.Design = new Array();
	this.Data = new Array();

	this.AddData = function(idProduct, srcImage, srcSchema)
	{
		//Carga las imagenes en el Array (y hace preload)
		product = new EntryProduct();
		product.idProduct = idProduct;
		product.oImage = new Image();
		product.oImage.src = srcImage;
		product.oSchema = new Image();
		product.oSchema.src = srcSchema;
		
		this.Data[this.Data.length] = product;
	}

	this.SetProduct = function(idProduct, cssClass, oAnchor)
	{
		for(var i=0; i<this.Data.length; i++)
		{
			if(this.Data[i].idProduct == idProduct)
			{
				if(oAnchor)
				{
					//Deshabilito el estilo de los enlaces
					this.DisableCss(cssClass, oAnchor);
					//Activo el activo
					oAnchor.className = cssClass;
				}
								
				//Effect.Fade('product_info');

				document.getElementById(this.IdImage).src = this.Data[i].oImage.src;
				document.getElementById(this.IdDesign).src = this.Data[i].oSchema.src;
				
				//Effect.Appear(this.IdDivImage);
				
				return;
			}
		}
	};
	
	this.DisableCss = function(cssClass, oAnchor)
	{
		//Deshabilita los estilos de todos los enlaces
		var ul = $(oAnchor.id).up("ul");
		var anchors = ul.getElementsByTagName("a");
		for(var i=0; i<anchors.length; i++)
		{
			var tempClass = anchors[i].className;
			if(tempClass.indexOf("_selected") > -1)
			{
				tempClass = tempClass.replace("_selected", "");
				anchors[i].className = tempClass;
			}
		}
		
		oAnchor.className = cssClass;
	};
}

//]]>