// Tama�os m�nimos y m�ximos de fuente
var maxSize = 16;
var minSize = 12;

var tiebel = {

	Start: function ()
	{
		//tiebel.iniciarFuentes();
		tiebel.iniciarRollOver();
		//tiebel.iniciarMilkBox();
		//tiebel.iniciarMultiBox();
	},

	iniciarMultiBox: function ()
	{
		var multiboxArray = $$('a.multibox');
		if (multiboxArray.length > 0) {
			new MultiBox('multibox', {
				useOverlay: true,
				contentColor: '#E9E4E1'
			});
		}
	},

	iniciarEnlacesExternos: function () {
		if ($$('a.externo')) {
			$$('a.externo').each(function (el) {
				el.setAttribute('target', '_blank');
			});
		}
	},

	iniciarFuentes: function () {
		if(Cookie.get('fontSize') == false) {
			Cookie.set('fontSize', 12, 1);
		} else {
			Cookie.set('fontSize', Cookie.get('fontSize')-1, 1);
			tiebel.subirFuente();
		}

	},

	subirFuente: function ()
	{
		if(Cookie.get('fontSize') < maxSize) {
			var tam = Cookie.get('fontSize');
			tam++;
			$$('p').each(function (el){
				el.setStyle('font-size', tam +'px');
			});
			Cookie.set('fontSize', tam, 1);
		}
	},

	bajarFuente: function ()
	{
		if(Cookie.get('fontSize') > minSize) {
			var tam = Cookie.get('fontSize');
			tam--;
			$$('p').each(function (el){
				el.setStyle('font-size', tam +'px');
			});
			Cookie.set('fontSize', tam, 1);
		}
	},

	imprimir: function()
	{
		print();
	},

	mostrarImagenSubida: function (ruta, nombre, ancho, alto, size, error)
	{
		// Una vez subida la imagen mostramos la imagen y los datos de la misma
		$('imagen-subida').setStyle('display', 'block');
		new Fx.Style ('imagen-subida', 'opacity').set(0);
		//$('imagen-subida').innerHTML += '<img id="img-shape" src="' + ruta +'" alt="Imagen subida" />';
		$('imagen-shape').setStyle('background-image', 'url('+ruta+')');
		$('imagen-shape').setStyle('width', ancho +'px');
		$('imagen-shape').setStyle('height', alto +'px');
		new Fx.Style ('imagen-subida', 'opacity').start(0, 1);

		// Rellenamos los datos de la imagen
		$('datos-imagen').setStyle('display', 'block');
		$('img-nombre').setHTML(nombre);
		$('img-ancho').setHTML(ancho);
		$('img-alto').setHTML(alto);
		$('img-size').setHTML(size);
		new Fx.Style ('datos-imagen', 'opacity').set(0);
		new Fx.Style ('datos-imagen', 'opacity').start(0, 1);

		if(error != 'ok') {
			$('img-error').setHTML(error);
			$('cont-img-error').setStyle('display', 'block');
			$('contenedor-formulario-enlaces').setStyle('display', 'none');
		} else {
			// Mostramos el formulario para introducir los datos del enlace y ponemos el valor de la imagen
			$('cont-img-error').setStyle('display', 'none');
			$('contenedor-formulario-enlaces').setStyle('display', 'block');
			new Fx.Style ('contenedor-formulario-enlaces', 'opacity').set(0);
			new Fx.Style ('contenedor-formulario-enlaces', 'opacity').start(0, 1);
			$('imagen').setProperty('value', nombre);
		}

		if ($('dragShape')) {
			var posX;
			var posY;
			var contenedor = $('imagen-shape');
			var drag = new Drag.Move ('dragShape', {'container': contenedor});
			$('dragShape').setStyle('display', 'block');
			new Fx.Style ('dragShape', 'opacity').set(0.5);
			$('img-x').innerHTML = $('dragShape').getStyle('left');
			$('img-y').innerHTML = $('dragShape').getStyle('top');
			drag.addEvent('onDrag', function () {
				$('img-x').innerHTML = $('dragShape').getStyle('left');
				$('recorte-x').setProperty('value', $('img-x').innerHTML);
				$('img-y').innerHTML = $('dragShape').getStyle('top');
				$('recorte-y').setProperty('value', $('img-y').innerHTML);
			});
		}
	},

	iniciarRollOver: function ()
	{
 		$$("img.rollover").forEach (function(el) {
			el.addEvent("mouseenter", function() {
				var imgPath    = this.getProperty("src");
				var imgPath_on = imgPath.replace(/_0/g,"_1")
				this.setProperty("src", imgPath_on );
			});
			el.addEvent("mouseleave", function() {
				var imgPath    = this.getProperty("src");
				var imgPath_off = imgPath.replace(/_1/g,"_0")
				this.setProperty("src", imgPath_off );
			});
		});
	},

	confirmarBorrado: function ()
	{
		return confirm ('¿Está seguro que quiere eliminar el Registro? Esta operación no puede deshacerse.');
	}

}

window.addEvent('domready', tiebel.Start);