jQuery.recargarTodo = function() {

    $(".anclaje").unbind('click');

    $.cargarTodo();
}

jQuery.cargarTodo = function() {

    $(".anclaje").click(function() {
        etiqueta = $(this).attr("title");
        pos = $("#" + etiqueta).position();
        $(document).scrollTo(pos.top,500);
    });


}

jQuery.cargarProgressBar = function() {
    
    $(".progressBar").each(function(){

        $(this).progressBar($(this).attr("title"), {
            showText: false,
            barImage: 'images/progressbg_black.gif'
        } );
         
    });

}




jQuery.cargaRoll= function(){
     $(".roll").each(function() {
        rollsrc = $(this).attr("src");
        rollON = rollsrc.replace(/\.(png|jpg|gif)$/ig, "_over.$1");
        $("<img>").attr("src", rollON);
    });

    $(".roll").mouseover(function() {
        imgsrc = $(this).attr("src");
        matches = imgsrc.match(/_over/);
        if (!matches) {
            imgsrcON = imgsrc.replace(/\.(png|jpg|gif)$/ig, "_over.$1");
            $(this).attr("src", imgsrcON);
        }
    });

    $(".roll").mouseout(function() {
        $(this).attr("src", imgsrc);
    });
}

    

$(document).ready(function() {

    $("#rememberPass").click(function() {
        
        jQuery.facebox(
            { 
                ajax: './newpass/formPass.php' 
            }
        );
        
    });
    
    $("a.user_login").click(function() {
            
        message=$(this).attr('title');
        
        if ($(this).attr('href')!=undefined){
            path_redirect=$(this).attr('href');
        }
        
        $(this).removeAttr('href');
        
        $(this).attr('style', 'cursor:pointer;');


        $(document).bind('loading.facebox', function() {
            $(document).unbind('keydown.facebox');
            $('#facebox_overlay').unbind('click');
        });
        
        $(document).bind('close.facebox', function() {
           $("select").each(function(){

             $(this).attr('style','visibility: visible;');

            });
        });    

        $("select").each(function(){

           $(this).attr('style','visibility: hidden;');

        });
        
        jQuery.facebox(
            { 
                ajax: './autologin/formLogin.php' 
            }
        );
            
        
    });

    $("#slider").easySlider({
        auto: true,
        continuous: true,
        speed:1000,
        pause:5000,
        controlsShow: false

    });


    $().piroBox({
      my_speed: 400, //animation speed
        bg_alpha: 0.5, //background opacity
        slideShow : true, // true == slideshow on, false == slideshow off
        slideSpeed : 4, //slideshow duration in seconds(3 to 6 Recommended)
        close_all : '.piro_close,.piro_overlay' // add class .piro_overlay(with comma)if you want overlay click close piroBox
      });

       
    
     



    /* jQuery.url.setUrl("http://allmarkedup.com/category/about/javascript?itemID=2");
     * jQuery.url.attr("protocol") //devuelve 'http'
     * jQuery.url.attr("host") //devuelve 'allmarkedup.com'
     * jQuery.url.param("itemID") //devuelve 2
     * jQuery.url.segment(2) //devuelve 'about'
     */

    jQuery.cargaRoll();

    selectedMenu = null;


    if (jQuery.url.segment(0) != null) {

        selectedMenu = $("#menu" + jQuery.url.segment(0));
        
        if (selectedMenu.attr("src")!=undefined){
            selectedMenu.addClass("noChange");
            
            selectedMenu.attr("src", selectedMenu.attr("src").replace(/\.(png|jpg|gif)$/ig, "_over.$1"));
        }
        
    } 


   $("li.principal").each(function() {
        rollsrcMenu = $(this).children("a").children("img").attr("src");

        rollONMenu = rollsrcMenu.replace(/\.(png|jpg|gif)$/ig, "_over.$1");

        $("<img>").attr("src", rollONMenu);
    });

    $("li.principal").mouseover(function() {
        imgsrcMenu = $(this).children("a").children("img").attr("src");
        matches = imgsrcMenu.match(/_over/);
        if (!matches) {
            imgsrcONMenu = imgsrcMenu.replace(/\.(png|jpg|gif)$/ig, "_over.$1");
            $(this).children("a").children("img").attr("src", imgsrcONMenu);
        }
    });

    $("li.principal").mouseout(function() {
        if ($(this).children("a").children("img").attr("class") != 'noChange') {
            imgsrcMenu = $(this).children("a").children("img").attr("src");
            matches = imgsrcMenu.match(/_over/);
            if (matches) {
                imgsrcONMenu = imgsrcMenu.replace(/_over\.(png|jpg|gif)$/ig, ".$1");
                $(this).children("a").children("img").attr("src", imgsrcONMenu);
            }
        }

    });

    $('.contenidocompartir').mouseover(function() {
        $(this).children('ul.iconoscompartir').show();
    });

    $('.contenidocompartir').mouseout(function() {
        $(this).children('ul.iconoscompartir').hide();
    });

    $("ul.iconoscompartir li").click(function() {
            document.location.href = $(this).attr('title');
    });

     $("ul.iconoscompartirficha li").click(function() {
         if ($(this).attr("id")!="mail")
            window.open ($(this).attr('title'));
        else
            document.location.href = $(this).attr('title');
    });
    
    
     $(".my-button").click(function() {
        if ($(this).attr("id")!="mail")
            window.open ($(this).attr('title'));
        else
            document.location.href = $(this).attr('title');
    });


    $("ul.iconoscompartirnovedades li").click(function() {
      
            document.location.href = $(this).attr('title');
    });

    $('.imgToZoom').resizeOnApproach({
        'elementDefault' : 283,
        'elementClosest' :  310,
        'triggerDistance': 1,
        'setWidthAndHeight' : false
    });

    $.cargarTodo();
    $("div#receta_dia").hide();
    
    $("a#recibir_receta_dia").click(function() {
            $("div#receta_dia").load('http://www.pescanova.es/web/public/components/RecetasPortada/recibe_receta_dia.html');
            $("div#receta_dia").center();      
            $("div#receta_dia").show();
    });

    $("a#recibir_receta_dia").click(function() {
            $("div#recetaDia").hide();
    });


    $("div#boton_omega3").mouseover(function() {
        $("div#capa_omega3").css("visibility","visible");
    });
    

    $("div#boton_omega3").mouseout(function() {
        $("div#capa_omega3").css("visibility","hidden");
    });
    
});
