$(document).ready(function () {

	//Ventana modal
//	$.nyroModalSettings({width: 805, height: 445, overflow: 'hidden', modal: true});
	$.nyroModalSettings();
	$('.modal').nyroModal();

	//Ventana para imagenes
	$("a[rel^=lightbox]").colorbox({transition:"elastic"});
	
	//Top en flash
/*	$('#top').flash({
		swf: path+'flash/if/top.swf',	width: '100%',	height: '100%',		hasVersion: 8,
		params: { menu: 'false', wmode: 'transparent' ,scale: 'noscale' }
	});
*/	
	//Banners
/*	$('#banner1').flash({
		swf: path+'flash/banners/banner_menu_40viajes.swf',	width: '199',	height: '260',		hasVersion: 8,
		params: { menu: 'false', wmode: 'solid' ,scale: 'noscale' }
	});
*/
	//SexyLightbox.initialize({color:'black', dir: {/}+'img/sexyimages'});

	//Marquesina
	/*$('marquee').marquee().find('a').mouseover(function () {
		$(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	});*/
       	
	

	
//	$.sifr({
//		path: 'fonts/'		,save: true
//	});
	
//	$('h2').sifr({ font: 'mgopenmodatabold' });
//	$('h2').sifr({ font: 'cocktail' });
//	$('h2').sifr({ font: 'Gunmetal', sifrVersion: 3, zoom: 1 });

	
	//hover en menu
/*
	$("#menu li a").hover(function() {
//		$(this)
//		.animate({ paddingTop: '45'}, "fast")
//		.addClass('hover')
		$(this).animate({ paddingTop: '0'}, "fast");
	}, function() {
//		$(this).animate({ paddingTop: '45'}, "fast")
//		.removeClass('hover')
		$(this).animate({ paddingTop: '0'}, "fast");
	});
	//$("#menu li").css({lineHeight: '55'}, 1);
*/
/*	$("#menu li a").hover(function() {
		$(this).animate({ color: '#269AFF', paddingLeft: '10px' }, "fast");
	}, function() {
		$(this).animate({ color: '#444444', paddingLeft: '0' }, "slow");
	});
*/
//	$("#menu li a").css({paddingLeft: '0'}, 1);



		$('.boton').each( function(){
			var a = $(this).find('a').get(0);
			a.texto = a.innerText ? a.innerText : a.textContent;
	//		ancho = 46+(_mensaje.length*8);
	//		$(this).css({width: ancho});
	//		alert('Pongo boton con link a '+a.href+', y target '+a.target+', con el texto "'+a.texto+'"');
			$(this).flash({
				swf: path+'flash/if/boton.swf',	width: '100%',	height: '30',	hasVersion: 9,
				flashvars: { mensaje: a.texto, enlace: a.href, target: a.target },
				params: { menu: 'false', wmode: 'transparent' }
			});
		});



	//NEWSLETTER *********************************
	var newsFormReset = function(){
		$('#f_email').DefaultValue('E-mail');
		$('#f_sub').attr('disabled', false);
		$('#f_lista').attr('checked',false);
		$('#f_listagay').attr('checked',false);
		$('#f_condiciones').attr('checked',false);
	}

	$('#newsletterMsg').slideUp(0);
	newsFormReset();
	
	
	/*
	$("#prensa").click(function(){
		$("form#formlist").fadeOut('slow',function(){
			$("form#formprensa").fadeIn('slow');								   
		});		
	});
	$("#mailing").click(function(){
		$("form#formprensa").fadeOut('slow',function(){
			$("form#formlist").fadeIn('slow');										 
		});
	});
	*/
	$('#f_sub').click(function(e){

		$('#f_sub').attr('disabled','disabled');
		e.stopPropagation();
		e.preventDefault();

		//var listaVal = $("#newsletter #f_listas").val();
		var textos_es = {
			"OK": 			"<p>OK! Tu e-mail ha sido añadido correctamente!</p>",
			"ERR_CONFIRM":	"<p><b>Error</b>. No se pudo enviar confirmacion</p>",
			"ERR_SYSTEM":	"<p><b>Error</b>. Fallo conectando con el servidor de listas</p>",
			"ERR_ALREADY":	"<p><b>Error</b>. El e-mail ya está en la lista</p>",
			"ERR_ALREADY1":"<p><b>Error</b>. El e-mail ya está en la lista SuperMartXé</p>",
			"ERR_ALREADY2":"<p><b>Error</b>. El e-mail ya está en la lista Gay</p>",
			"ERR_ALREADY12":	"<b>Error</b>. El e-mail ya está en ambas listas</p>",
			"ERR_BADEMAIL":	"<p><b>Error</b>. El e-mail tiene un formato erroneo o invalido</p>",
			"ERR_BADLIST":	"<p><b>Error</b>. Lista erronea</p>",

			"ERR_NOLIST":	"<p><b>Error</b>. No has indicado ninguna lista a la que suscribirte</p>",
			"ERR_COND":		"<p><b>Error</b>. Debes aceptar y entender las condiciones de uso</p>",
			"ERR_NOEMAIL":	"<p><b>Error</b>. Debes rellenar tu e-mail</p>"
		};
        var textos_en = {
			"OK": 			"<p>OK! Your e-mail has been successfully added!</p>",
			"ERR_CONFIRM":	"<p><b>Error</b>. Could not send confirmation</p>",
			"ERR_SYSTEM":	"<p><b>Error</b>. Failed connecting to server list</p>",
			"ERR_ALREADY":	"<p><b>Error</b>. The e-mail is on the list</p>",
			"ERR_ALREADY1":"<p><b>Error</b>. The e-mail is on the list Supermartxé</p>",
			"ERR_ALREADY2":"<p><b>Error</b>. The e-mail is on the list Gay</p>",
			"ERR_ALREADY12":	"<b>Error</b>. The e-mail is on both lists</p>",
			"ERR_BADEMAIL":	"<p><b>Error</b>. The e-mail is badly formatted or invalid</p>",
			"ERR_BADLIST":	"<p><b>Error</b>. Erroneous List</p>",

			"ERR_NOLIST":	"<p><b>Error</b>. You have not indicated any list to which you subscribe</p>",
			"ERR_COND":		"<p><b>Error</b>. You must accept and understand the terms of use</p>",
			"ERR_NOEMAIL":	"<p><b>Error</b>. Please fill in your e-mail</p>"
		};
		var textos_asig = {
			'es': textos_es,
			'en': textos_en
		}
		var _ = textos_asig[ locale ];
		

		var hasError = false;
		var emailReg = /^[a-zA-Z0-9._-]+([+][a-zA-Z0-9._-]+){0,1}[@][a-zA-Z0-9._-]+[.][a-zA-Z]{2,6}$/;

		var emailVal = $("#f_email").val();
		var condicionesVal = $('#f_condiciones').attr('checked');
		var listaVal = $('#f_lista').attr('checked');
		var listagayVal = $('#f_listagay').attr('checked');
		if(condicionesVal != true) {
			$("#formlist").hide();
			$("#newsletterMsg").html(_['ERR_COND']).fadeIn('slow').animate({opacity: '+=0'}, 2000).fadeOut('slow', function(){
				$('#f_sub').attr('disabled', false);
				$("#formlist").fadeIn();
			});
			hasError = true;
		} else if(emailVal == 'E-Mail' || emailVal == '') {
			$("#formlist").hide();
			$("#newsletterMsg").html(_['ERR_NOEMAIL']).fadeIn('slow').animate({opacity: '+=0'}, 2000).fadeOut('slow', function(){
				$('#f_sub').attr('disabled', false);
				$("#formlist").fadeIn();
			});
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$("#formlist").hide();
			$("#newsletterMsg").html(_['ERR_BADEMAIL']).fadeIn('slow').animate({opacity: '+=0'}, 2000).fadeOut('slow', function(){
				$('#f_sub').attr('disabled', false);
				$("#formlist").fadeIn();
			});
			hasError = true;
		} else if ( !listagayVal && !listaVal ){
			$("#formlist").hide();
			$("#newsletterMsg").html(_['ERR_NOLIST']).fadeIn('slow').animate({opacity: '+=0'}, 2000).fadeOut('slow', function(){
				$('#f_sub').attr('disabled', false);
				$("#formlist").fadeIn();
			});
			hasError = true;
		}
		

		if(hasError == false) {
			//$("#maillist").append('<img src="loading.gif" alt="Loading" id="loading" />');
			$.post(
				path+locale+"/player/proxy",
				{ email: emailVal, lista: listaVal, listagay: listagayVal },
				function(data,status){
					switch(status){
						case 'success':
						case 'notmodified':
							texto = _[data];
							if(data=='OK'){ newsFormReset(); }
							break;
						case 'error':
						case 'timeout':
						case 'parsererror': 
						default:
							texto = 'Error de comunicación con el gestor de listas.'
							break;
					}
				/*	$("#newsletterMsg").html(texto);
					$("#newsletterMsg").slideDown('slow').animate({opacity: '+=0'}, 3000).slideUp('slow', function(){
						$('#f_sub').attr('disabled', false);
					});
				*/
					$("#formlist").hide();
					$("#newsletterMsg").html(texto).fadeIn('slow').animate({opacity: '+=0'}, 2000).fadeOut('slow', function(){
						$('#f_sub').attr('disabled', false);
						$("#formlist").fadeIn();
					});

				}
			);
		}
	});


});