jQuery(document).ready(
	function() {
		var $ = jQuery;

       // $('.activities_attch').hide();
        $('.each_activity .activities_info').hide();
        $('.activities_attch .tooltip').hide();

        $('.each_activity .activities_info').each(function(i){

            var $this = $(this);
            var content = $this.text();
            var this_rel = $this.attr("rel");
            if($.trim(content)!=""){
                $this.parent().append('<div class="show_info" rel="'+this_rel+'" style="cursor:pointer;"></div>');
            }
                    });

            $('.each_activity .show_info').click( function(){
            var $this = $(this);
            var this_rel = $this.attr("rel");
            var these_docs = ".doc_"+this_rel;
            var isHidden = $this.prev().is(':hidden');
            if(isHidden){
            $this.prev().fadeIn(600);
            $(these_docs).fadeIn(600);
            $this.css('background','url(/iberius-theme/images/custom/hide.png) no-repeat');
            }else{
            $this.prev().fadeOut(300);
            $(these_docs).fadeOut(300);
            $this.css('background','url(/iberius-theme/images/custom/info.png) no-repeat');
            }
            });

        /*$('.activities_clip').click( function(){

            var this_clip = $(this).attr('rel');
            var attach_to_show = '.show'+this_clip;
            var isHidden = $(attach_to_show).is(':hidden');
            if(isHidden){
            $('.activities_attch').fadeOut(400);
            $(attach_to_show).slideDown(1000);
            }else{
            $(attach_to_show).slideUp(1000);
            }
        })*/

        function showTooltip(x, y, contents) {
            $('<div id="tooltip">' + contents + '</div>').css( {
                position: 'absolute',
                display: 'none',
                top: y + 25,
                left: x - 105,
                border: '1px solid #CCC',
                width: '100px',
                padding: '2px',
                'background-color': '#F7F7F7',
                opacity: 0.80
            }).appendTo("body").fadeIn(200);
        }


		$('.activities_attch img').hoverIntent(
				{
					interval: 25,
					timeout: 0,
					over: function () {
                        var $this = $(this);
                        var posX = $(this).offset().left;
                        var posY = $(this).offset().top;
                        var content = $this.parent().next('.tooltip').text();
                        if(content!=""){
                    showTooltip(posX, posY,content);
                        }
					},
					out: function (){
					$("#tooltip").remove();
					}

                }

		);
            //aportación usuarios web form

        $('.portlet-web-form').hide();
        var isHidden = $('.portlet-web-form').is(':hidden');
        $('#p_p_id_PltPub_WAR_es_INSTANCE_yNsY_ #listados_wrapper').append('<div id="show_hide" class="show_hide">Aportar Nuevo Documento</div>')
        $('#p_p_id_PltPub_WAR_es_INSTANCE_yNsY_ #listados_wrapper .show_hide').css({
                color:'#555',
                height:'50px',
                paddingLeft:'21px',
                fontSize:'1.1em',
                fontWeight:'bold',
                cursor:'pointer',
                background:'url(/iberius-theme/images/arrows/02_down.png) no-repeat'
            });
        $('#p_p_id_PltPub_WAR_es_INSTANCE_yNsY_ #listados_wrapper .show_hide').click (function(){


        if(isHidden){
        $('.portlet-web-form').slideDown(1000);
        $('#p_p_id_PltPub_WAR_es_INSTANCE_yNsY_ #listados_wrapper .show_hide')
        .text('Oculte Formulario')
        .css('background','url(/iberius-theme/images/arrows/02_up.png) no-repeat');
        isHidden=false;
        }else{
        $('.portlet-web-form').slideUp(1000);
        $('#p_p_id_PltPub_WAR_es_INSTANCE_yNsY_ #listados_wrapper .show_hide').text('Oculte Formulario');
        $('#p_p_id_PltPub_WAR_es_INSTANCE_yNsY_ #listados_wrapper .show_hide')
        .text('Aportar Nuevo Documento')
        .css('background','url(/iberius-theme/images/arrows/02_down.png) no-repeat');
        isHidden=true;
        }

        })

    });

