
/* Gestión del slideshow de la página inicial ***************/
function slideSwitch() {
    
	var $active = $('#slide DIV.activo');
    if ( $active.length == 0 ) {
        $active = $('#slide DIV:last');
    }
	
    var $next =  $active.next().length ? $active.next():$('#slide DIV:first');
    $active.removeClass('inactivo');
	$active.addClass('ultimo-activo');
	$active.animate({
        opacity: 0.0
    },100);
	
	$next.addClass('activo');
    
	$next.css({
        opacity: 0.3
    })
	.animate({
        opacity: 1.0
    }, 100, function() {
        $active.removeClass('activo ultimo-activo');
		$active.addClass('inactivo');
    });
	
	var $active_c = $('#marco DIV.rec_activo');
	
	if ( $active_c.length == 0 ) {
        $active_c = $('#marco DIV:last');
    }
	
	var $next_c =  $active_c.next().length ? $active_c.next():$('#marco DIV:first');
	$active_c.removeClass('rec_activo');
	$next_c.addClass('rec_activo');
	
}
/**********************************************************/

/* Funcion para hacer desplegable el menu superior ********/
function mainmenu(){

    $(" #nav ul ").css({
        display: "none"
    }); // Opera Fix
    $(" #nav li").hover(function(){
        $(this).find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).show(200);
    },function(){
        $(this).find('ul:first').css({
            visibility: "hidden"
        });
    });
    $('.submenu ul li ul').hide();
	
    $('.submenu ul li a').click( function() {
        var checkElement = $(this).next();
		
        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            checkElement.slideUp('normal');
            return false;
        }
        if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            checkElement.slideDown('normal');
            return false;
        }
    });
	
	$('.recuadro_noticia').hover(function(){
        clearInterval(intval);
        intval = setInterval( "slideSwitch()", 15000 );
		var id = $(this).attr('id').substring($(this).attr('id').length - 1, $(this).attr('id').length);
        var elemento = "#not_"+id;
		//alert();
        var $active = $('#slide DIV.activo'); //Identifica cual es el div activo
		
        var $next = $(elemento);
		
		// Comprobamos si el elemento ya es activo
		var $clase = $next.attr('class').split(' ');
		//alert($clase.length);
		if($clase.length == 1){
			$active.removeClass('inactivo');
			$active.addClass('ultimo-activo');
			$active.animate({
				opacity: 0.0
			},100);
			$next.addClass('activo');
			$next.css({
				opacity: 0.3
			})
			.animate({
				opacity: 1.0
			}, 100, function() {
				$active.removeClass('activo ultimo-activo');
				$active.addClass('inactivo');
			});
			
			var $active_c = $('#marco DIV.rec_activo');
			$active_c.removeClass('rec_activo');
			$(this).addClass('rec_activo');
		}
    });
	
	
    //$(".mallorca_b_pp").hide();
    //$(".mallorca_b_up").hide();
    //$(".mallorca_b_c").hide();
    //$(".mallorca_b_cl").hide();
	
    intval = setInterval( "slideSwitch()", 10000 );
    //intval2 = setInterval( "comprobarIntVal()", 2000);
	
	
    //$('.textofondo').hide();
    /*
	$('#slideshow a').mouseover(function(){
		$('.textofondo').show("slow");
    });
	$('#slideshow a').mouseout(function(){
		$('.textofondo').hide("slow");
    });
	*/

    $("#tab_contenidos").tabs({
        fx: {
            opacity: 'toggle'
        }
    });
$('#tab_contenidos').tabs({
    select: function(event, ui) {
    //alert(ui.tab);
    }
});
$('#tab_contenidos').bind('tabsselect',
    function(event, ui) {
    //ui.index();
    //alert(ui.index);
    });
$("#tab_contenidos_2").tabs({
    fx: {
        opacity: 'toggle'
    }
});


//clasificacion
$(".cl1").addClass('clselected');

$(".cl1").click(function(){
    $(".mallorca_b_cl").hide("slow");
    $(".mallorca_cl").show("slow");
    $(".cl1").addClass('clselected');
    $(".cl3").removeClass('clselected');
    $(".cl1").css("background","url('../img/fondo_pestanya_rojo.jpg') top left repeat-x");
    $(".cl3").css("background","url('../img/barra_titulo.jpg') center left repeat-x");
    mallorcaB = false;
});

$(".cl3").click(function(){
    $(".mallorca_cl").hide("slow");
    $(".mallorca_b_cl").show("slow");
    $(".cl1").removeClass('clselected');
    $(".cl3").addClass('clselected');
    $(".cl1").css("background","url('../img/barra_titulo.jpg') center left repeat-x");
    $(".cl3").css("background","url('../img/fondo_pestanya_rojo.jpg') top left repeat-x");
    mallorcaB = true;
});


//proximo partido
$(".pp1").addClass('ppselected');

$(".pp1").click(function(){
    $(".mallorca_b_pp").hide("slow");
    $(".mallorca_pp").show("slow");
    $(".pp1").addClass('ppselected');
    $(".pp3").removeClass('ppselected');
    $(".pp1").css("background","url('../img/fondo_pestanya_rojo.jpg') top left repeat-x");
    $(".pp3").css("background","url('../img/barra_titulo.jpg') center left repeat-x");
    mallorcaB = false;
});
	
$(".pp3").click(function(){
    $(".mallorca_pp").hide("slow");
    $(".mallorca_b_pp").show("slow");
    $(".pp1").removeClass('ppselected');
    $(".pp3").addClass('ppselected');
    $(".pp1").css("background","url('../img/barra_titulo.jpg') center left repeat-x");
    $(".pp3").css("background","url('../img/fondo_pestanya_rojo.jpg') top left repeat-x");
    mallorcaB = true;
});


//ultimo partido
$(".up1").addClass('upselected');

$(".up1").click(function(){
    $(".mallorca_b_up").hide("slow");
    $(".mallorca_up").show("slow");
    $(".up1").addClass('upselected');
    $(".up3").removeClass('upselected');
    $(".up1").css("background","url('../img/fondo_pestanya_rojo.jpg') top left repeat-x");
    $(".up3").css("background","url('../img/barra_titulo.jpg') center left repeat-x");
    mallorcaB = false;
});

$(".up3").click(function(){
    $(".mallorca_up").hide("slow");
    $(".mallorca_b_up").show("slow");
    $(".up1").removeClass('upselected');
    $(".up3").addClass('upselected');
    $(".up1").css("background","url('../img/barra_titulo.jpg') center left repeat-x");
    $(".up3").css("background","url('../img/fondo_pestanya_rojo.jpg') top left repeat-x");
    mallorcaB = true;
});



}


$(document).ready(function(){
    var identificadorvideo = 0;
    var mallorcaB = false;
	
    mainmenu();
	
    if(!$('.active').is(':visible')){
        var desplegar = $('.active').parent();
        if(desplegar.is('ul')){
            var desplegar1 = desplegar.parent();
            if(desplegar1.is('li')){
                var desplegar2 = desplegar1.parent();
                desplegar2.slideDown('normal');
                desplegar.slideDown('normal');
            }else{
                desplegar.slideDown('normal');
            }
        }
    }
	
    $(".prevPage").click(function(){
        if(identificadorvideo != 0){
            identificadorvideo--;
        }else{
            identificadorvideo = 0;
        }
        $("#videos"+identificadorvideo).show('slow');
        $("#videos"+identificadorvideo+3).hide('slow');
    });
    $(".nextPage").click(function(){
        $("#videos"+identificadorvideo).hide('slow');
        $("#videos"+identificadorvideo+3).show('slow');
        if(identificadorvideo != 5){
            identificadorvideo++;
        }
    });
    //$(".player").hide();
    //$(".container").show();
    $("img[name*='imagenvideo']").hover(function(){
        //var video = $("#videos"+$(this).attr("id"));
        var elemento = $(".descripcionvideo"+$(this).attr("id"));
        var elemento2 = $(".contenidovideo"+$(this).attr("id"));
        var elemento3 = $(".source"+$(this).attr("id"));

        //$(".container").css("background-image","url("+$(this).attr("src")+")");
        $("#textovideo").html(elemento.val());
        $("#descripcion").html(elemento2.val());
        //$f().getControls().css({backgroundImage: 'url('+$(this).attr("src")+')'});
        //alert($f().getConfig(false).canvas.background);
        //$f().getPlugin(false).canvas.backgroundImage = 'url('+$(this).attr("src")+')';
        $f().getPlugin("canvas").css({
            //backgroundImage:'url('+$(this).attr("src")+')'
            backgroundImage:'url('+elemento3.val()+')'
        });
    //$f().css({backgroundImage: 'url('+$(this).attr("src")+')'});
    //$(".player").hide("slow");
    //$(".container").show("slow");
    //$(".player").hide("href",video.attr("href"));
    });
	
    $("img[name*='imagenvideo']").click(function(){
        var video = $("#videos"+$(this).attr("id"));
		
        //$(".player").show("slow");
        //$(".container").hide("slow");
        $(".player").attr("href",video.attr("href"));
    //alert($(".player").attr("href"));
    });
	
});

/**********************************************************/

// Función para la validación de correos
function validarCorreo(emailStr) {
    /* Patrón que deben seguir las direcciones de correo */
    var emailPat=/^(.+)@(.+)$/
    /* Carácteres especiales que no queremos en la dirección */
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    /* carácteres válidos en la dirección */
    var validChars="\[^\\s" + specialChars + "\]"
    /* Adoptamos medidas para las cuentas con comillas:
	Ej. "jiminy cricket"@disney.com es una dirección legal */
    var quotedUser="(\"[^\"]*\")"
    /* Dominios como dirección ip. Ej. joe@[123.124.233.4] .
	NOTA: los corchetes son obligatorios */
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    /* un átomo es una serie de carácteres no especiales. */
    var atom=validChars + '+'
    /* Con la definición anterior montamos las palabras. Un usuario será un átomo
	o un nombre entre comillas */
    var word="(" + atom + "|" + quotedUser + ")"
    // En definitiva, este es el patrón para los usuarios válidos
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    /* Patrón de un dominio "simbólico" */
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
    /* Comprobamos si la cuenta existe realmente */
    var matchArray=emailStr.match(emailPat)
    if (matchArray==null) {
        return false	// eti_errorcorreo
    }
	
    var user=matchArray[1]
    var domain=matchArray[2]
	
    if (user.match(userPat)==null) {
        return false	// eti_errorusuario
    }
	
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) {
        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                return false	//	errorip
            }
        }
        return true
    }
	
    var domainArray=domain.match(domainPat)
    if (domainArray==null) {
        return false	//	errordominio
    }
	
    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 ||
        domArr[domArr.length-1].length>3) {
        return false	// errordominiopais
    }
	
    if (len<2) {
        return false		// errorip
    }
	
    return true
}
