$(document).ready(function(){

	$.facebox.settings.opacity = 0.4;

	$('a#aviso-leg').facebox();
	/*$('a#callback').facebox();
	$('a#mailsup').facebox();

	$.datepicker.regional['es'] = {
		closeText: 'Cerrar',
		prevText: '&#x3c;Ant',
		nextText: 'Sig&#x3e;',
		currentText: 'Hoy',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
		'Jul','Ago','Sep','Oct','Nov','Dic'],
		dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
		dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
		dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
		weekHeader: 'Sm',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['es']);

	$(document).bind('reveal.facebox', function() {
  		$('#facebox .datepicker').each( function(intIndex){
    		$(this).attr('id', $(this).attr('id') + '-2');
  		});
	});

	$(document).bind('reveal.facebox', function() {
		$('#datepicker-2').datepicker();
	})
	
	$(document).bind('close.facebox', function() {
		window.open('http://www.bmfn.com.mx/application.html', '_blank');
	});*/
			
	/*$(".social-media a").hover(function() {
		$(this).next("em").stop(true, true).animate({opacity: "show", top: ($(this).position().top - 40), left: ($(this).position().left - 32)}, "slow");
	}, function() {
		$(this).next("em").animate({opacity: "hide"}, "fast");
	});
	
	$('.abrir-slide').cycle({
		fx: 'fade',
		timeout: 6000
	});
	
	$('.home-slide').cycle({
		fx:			'uncover',
		direction:	'left',
		timeout:	6000,
		delay:		-2000
	});
	
	
	$("ul.demo1").ytplaylist({autoPlay: false, showRelated: false, holderId: 'video-place'});*/
	
	$("#tweets").tweet({
        username: "TraderMxNews",
        join_text: "auto",
        avatar_size: 0,
        count: 3,
        auto_join_text_default: "",
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "cargando tweets..."
    });
    
    $("ul.social li a").hover( 
    	function(){
    		$(this).stop().animate({ paddingLeft: "55px"});
    	}, 
    	function(){
    		$(this).animate({ paddingLeft: "45px"});
    	}
    );
    
    function validateEmail(elementValue){
    	/*var regEx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/; */
    	var regEx = /^([a-zA-Z]+([\.]?[\-_0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,5})$/
        return regEx.test(elementValue);  
    }
    
    function current_timestamp(){
    	var tiempo = new Date();
    	var dia = tiempo.getDate();
    	var mes = tiempo.getMonth() + 1;
    	var ano = tiempo.getFullYear();
    	var hora = tiempo.getHours();
    	var mins = tiempo.getMinutes();
    	var segs = tiempo.getSeconds();
    	
    	if(mins < 10){
    		mins = "0" + mins;
    	}
    	if(segs < 10){
    		segs = "0" + segs;
    	}
    	
    	return ""+ano+"-"+mes+"-"+dia+" "+hora+":"+mins+":"+segs+"";
    }
    
    $("#boletin").val("Escriba su email..");
    $("#boletin").focus(function(){
    	if($(this).val() == "Escriba su email.."){
    		$(this).val("");
    	}
    });
    
    var boletincont = 0;
    
    $("a.boletinb").click(function(){
		var email = $('#boletin').val();
		var timestamp = current_timestamp();
		if(validateEmail(email) && boletincont < 5){
			$.post('http://tradermx.com/ajax/boletin/',
					{emailboletin: ""+email+"", tiempoboletin: timestamp},
					function(data) { // Do an AJAX call
						if(data != ''){
			         	$('#mensajeboletin').html(data); // Fill the suggestions box
			         	$('#mensajeboletin').fadeIn().delay(2000).fadeOut(2000); // Show the suggestions box
			         	boletincont++;
					}
			});
		} else if(boletincont >= 5) {
			$('#mensajeboletin').html("Demasiados intentos. Vuelva a intentar mas tarde.");
			$('#mensajeboletin').fadeIn().delay(2000).fadeOut(); // Show the suggestions box
		} else {
			boletincont++;
			$('#mensajeboletin').html("Correo no valido, vuelva a intentar");
			$('#mensajeboletin').fadeIn().delay(2000).fadeOut(); // Show the suggestions box
		}
		return false;
	});

});
