function cambia_cita()

{

	new Ajax.PeriodicalUpdater ($('cita'), 'citas.php',{frequency:10, decay:1});

}



function carga_texto(seccion)

{

	new Ajax.Request(seccion+'.ihtml',

	{

		method:'get',

		onSuccess: function(transport)

		{

			var data = transport.responseText;

			$('texto2').innerHTML = data;

			if ($('texto').scrollUpdate) $('texto').scrollUpdate();



			var lis = $('submenu_principal').childElements(); 

			for (var i=0; i<lis.length; i++)

			{

				elemento = lis[i];

				if (elemento.id == 'li-'+seccion)

				{

					elemento.setAttribute('class', 'selected');

					elemento.setAttribute('className', 'selected');

				}

				else {

					elemento.setAttribute('class', 'normal');

					elemento.setAttribute('className', 'normal');

				}

			}



		}

	});

}



function carga_texto2(seccion, url_imagen, texto, ocultasubmenu, div_padre, amplia_texto, muestra_cesta, enlace_imagen)

{

	if (typeof texto == 'undefined' ) texto = "";

	if (typeof ocultasubmenu == 'undefined' ) ocultasubmenu = true;

	if (typeof div_padre == 'undefined' ) div_padre = 'submenu_principal';

	if (typeof amplia_texto == 'undefined' ) amplia_texto = false;

	if (typeof muestra_cesta == 'undefined' ) muestra_cesta = false;



	if (ocultasubmenu)

	{

		oculta_submenu ();

	}



	$('col1').innerHTML = '<div id="fotos" class="fotos"><p id="cita" class="cita"></p></div>';

	if (muestra_cesta) {

		$('col1').innerHTML += '<div id="cesta"><img src="imagenes/cesta.jpg"/></div>';

	}



	new Ajax.Request(seccion+'.ihtml',

	{

		method:'get',

		onSuccess: function(transport)

		{

			var data = transport.responseText;

			$('texto2').innerHTML = data;

			if ($('texto').scrollUpdate) $('texto').scrollUpdate();



			if (typeof url_imagen == 'undefined')

			{

				$('fotos').innerHTML = '<p id="cita" class="cita"></p>';

				cambia_cita();

			}

			else

			{

				$('fotos').innerHTML = '<div id="imagen"></div>';

				var imagen = document.createElement('div');

				imagen.id = 'imagen';

				imagen.style.display = 'none';

				if (typeof enlace_imagen == 'undefined')

					imagen.innerHTML = '<img src="' + url_imagen + '" /><br/><h3>'+texto+'</h3>';

				else

					imagen.innerHTML = '<a href= "#" onclick="window.open(\'' + enlace_imagen +'\',\'imagen\', \'width=1000,height=325,toolbar=no,location=no,directories=no,status=no,menubar=no\');"><img src="' + url_imagen + '" /></a><br/><h3>'+texto+'</h3>';

				$('imagen').appendChild(imagen);

				Effect.Appear (imagen);

			}



			var lis = $(div_padre).childElements(); 

			for (var i=0; i<lis.length; i++)

			{

				elemento = lis[i];

				if (elemento.id == 'li-'+seccion)

				{

					elemento.setAttribute('class', 'selected');

					elemento.setAttribute('className', 'selected');

				}

				else {

					elemento.setAttribute('class', 'normal');

					elemento.setAttribute('className', 'normal');

				}

			}



			if (amplia_texto)

			{

				$('texto').setAttribute('class', 'textolargo');

				$('texto').setAttribute('className', 'textolargo');

			}

			else

			{

				$('texto').setAttribute('class', 'texto');

				$('texto').setAttribute('className', 'texto');

			}

		}

	});

}



function muestra_submenu(nombre, ocultatexto)

{

	if (typeof ocultatexto == 'undefined' ) ocultatexto = false;



	if ($('lista_imagenes')) $('lista_imagenes').innerHTML = '';

	$('fotos').innerHTML = '<p id="cita" class="cita"></p>';



	divs = $$('div.interior');

	for (var i=0; i<divs.length; i++)

	{

		elemento = divs[i];

		if (elemento.id == nombre)

		{

			elemento_aux = document.getElementById('li-'+nombre);

			elemento_aux.setAttribute('class', 'selected');

			elemento_aux.setAttribute('className', 'selected');



			$(elemento.id).style.display = 'inline';

		}

		else {

			elemento_aux = document.getElementById('li-'+elemento.id);

			elemento_aux.setAttribute('class', 'normal');

			elemento_aux.setAttribute('className', 'normal');



			$(elemento.id).style.display = 'none';

		}

	}



	if (ocultatexto)

	{

		$('texto2').innerHTML = '';

		$('texto').setAttribute('class', 'texto');

		$('texto').setAttribute('className', 'texto');

	}

}



function muestra_submenu2(nombre)

{

	$('texto2').innerHTML = '';

	$('fotos').innerHTML = '';

	if ($('lista_imagenes')) $('lista_imagenes').innerHTML = '';

	$('texto').setAttribute('class', 'texto');

	$('texto').setAttribute('className', 'texto');

	divs = $$('div.interior');

	for (var i=0; i<divs.length; i++)

	{

		if (divs[i].style.display != 'none')

			divs[i].style.display = 'none';

	}



	divs = $$('div.submenu_secundario');

	for (var i=0; i<divs.length; i++)

	{

		div = divs[i];

		if (div.style.display != 'none')

		{

			div.style.display = 'none';

		}

	}



	if (nombre == 'otros')

	{

		muestra_submenu(nombre, true);

	}

	else

	{

		$("menu_"+nombre).style.display = 'inline';

	}



	lista = $('submenu_principal').getElementsByTagName('li');

	for (var i=0; i < lista.length; i++)

	{

		elemento = lista[i];



		if (elemento.id == 'li-'+nombre)

		{

			elemento.setAttribute('class', 'selected');

			elemento.setAttribute('className', 'selected');

		}

		else

		{

			elemento.setAttribute('class', 'normal');

			elemento.setAttribute('className', 'normal');

		}

	}

}



function texto_portfolio (fichero, textolargo)

{

	new Ajax.Request(fichero,

	{

		method:'get',

		onSuccess: function(transport)

		{

			if (typeof textolargo == 'undefined' ) textolargo = false;



			if (textolargo)

			{

				$('texto').setAttribute('class', 'textolargo');

				$('texto').setAttribute('className', 'textolargo');

			}

			else

			{

				$('texto').setAttribute('class', 'texto');

				$('texto').setAttribute('className', 'texto');

			}





			var data = transport.responseText;

			$('texto2').innerHTML = data;

		}

	});

}



function oculta_submenu ()

{

	Effect.Fade ('menu_herramientas');

}



function muestra_producto (id)

{

	new Ajax.Request('imagenes.json',

	{

		method:'get',

		onSuccess: function(transport)

		{

			var data = transport.responseText.evalJSON();

			for (var i = 0; i < data.productos.length; i++)

			{

				if (data.productos[i].id == id)

				{

						$('fotos').innerHTML = '<div id="imagen"></div>';

						$('imagen').style.display = 'none';



					$('texto2').innerHTML = data.productos[i].texto;

					



					if (data.productos[i].archivos.length > 0)

					{

						var contador = 0;



						if ($('lista_imagenes')) $('col1').removeChild($('lista_imagenes'));

						var div_lista = document.createElement('DIV');

						div_lista.id="lista_imagenes";

						div_lista.setAttribute("class", "lista_imagenes");

						div_lista.setAttribute('className', 'lista_imagenes');



						for (var x = 0; x < data.productos[i].archivos.length; x++)

						{

							var imagen = document.createElement('div');

							imagen.id = 'imagen' + (x+1);

							imagen.setAttribute("class", "imagen");

							imagen.setAttribute('className', 'imagen');



							var imagen_aux = new Image();

							imagen_aux.src = data.productos[i].archivos[x].nombre;



							imagen.innerHTML = '<img src="' + data.productos[i].archivos[x].nombre + '" />';

							if (contador > 0)

							{

								imagen.style.display = 'none';

							}

							$('imagen').appendChild(imagen);



							var enlace = document.createElement('a');

							enlace.id = 'enlace'+(x+1);

							enlace.href= "javascript:Effect.divSwap('enlace"+(x+1)+"', 'imagen"+(x+1)+"','imagen');";

							enlace.innerHTML = x+1;

							enlace.style.color = contador > 0?'#a6a6a6':'red';

							enlace.style.fontWeight = contador > 0?'normal':'bold';

							div_lista.appendChild(enlace);



							contador++;

						}



						$('col1').appendChild(div_lista)

					}

					Effect.Appear ($('imagen'));

				}

			}



			enlaces = $$('.producto');

			for (var i = 0; i < enlaces.length; i++)

			{

				if (enlaces[i].id == id)

				{

					enlaces[i].childElements()[0].style.fontWeight = 'bold';

					enlaces[i].childElements()[0].style.color = '#58595b';

				}

				else

				{

					enlaces[i].childElements()[0].style.fontWeight = 'normal';

					enlaces[i].childElements()[0].style.color = '#a6a6a6';

				}

			}

		}

	});

}



Effect.divSwap = function(enlace, element,container)

{

	var lista_enlaces = $('lista_imagenes').childElements();

	for (var i = 0; i < lista_enlaces.length; i++) {

		if (lista_enlaces[i].id == enlace) {

			lista_enlaces[i].style.color = "red";

			lista_enlaces[i].style.fontWeight = "bold";

		}

		else {

			lista_enlaces[i].style.color = "#a6a6a6";

			lista_enlaces[i].style.fontWeight = "normal";

		}

	}



	var div = document.getElementById(container);

	var nodeList = div.childNodes;

	if($(element).visible()==false)

	{

		for(i=0;i<nodeList.length;i++)

		{

			if(nodeList.item(i).nodeName=="DIV" && nodeList.item(i).id!=element)

			{

				if($(nodeList.item(i).id).visible()==true)

				{

					Effect.Fade(nodeList.item(i),{queue:'front'});

				}

			}

		}

		Effect.Appear(element,{queue:'end'});

	}

}



function comprueba_envio ()

{

	if(document.referrer == 'http://www.brandsession.com/formulario_contacto.php')

	{

		alert ('Gracias por ponerse en contacto con nosotros.');

	}

}


