jQuery(document).ready(
	function() {
		var $ = jQuery;
        $('.each_news_container .brief').hide(); //hide brief section
        $('#galeria_imagenes').cycle({  //galería imágenes noticias
                                fx:      'custom',
                                cssBefore: {
                                    left: 115,
                                    top:  115,
                                    width: 0,
                                    height: 0,
                                    opacity: 1,
                                    zIndex: 1
                                },
                                animOut: {
                                    opacity: 0
                                },
                                animIn: {
                                    left: 0,
                                    top: 0,
                                    width: 300,
                                    height: 200
                                },
                                cssAfter: {
                                    zIndex: 0
                                },
                                delay: -3000
                            });

//body noticia sample

        var noticia_body = $('.each_news_container .body_noticia');
        noticia_body.show();
        var noticia_titulo = $('.each_news_container .titulopublicacion a');
        $(noticia_body).each(function(){
            var $this = $(this);
            $this.text($.trim($this.text().substr(0,200))+"...");
        })
        //shortening news title, just in case...

        $(noticia_titulo).each(function(){
            var $this = $(this);
            var this_href = $this.attr("href");
            if($this.text().length > 35){
            $this.html("<a href='"+this_href+"'>"+$this.text().substr(0,35)+"</a>...").css({color:"maroon", fontSize:"1.2em",fontWeight:"normal"});
        }
                    
        })

        //brief info

        if($('.each_news_container .brief').text()){
            $('.each_news_container .show_brief').text("Ver Info");
        }
        $('.each_news_container .show_brief').click( function(){
            $('.each_news_container .brief').fadeOut(200);
            var $this = $(this);
            var index = $(this).attr('rel');
            var div_to_show = ".each_news_container #brief_"+index;
            var isHidden = $(div_to_show).is(':hidden');

            if(isHidden){
            $(div_to_show)
                .css({opacity:0.9})
                .slideDown(600);
            $($this).text("Ocultar");
            }else{
                $(div_to_show).fadeOut(200)
                $($this).text("Ver Info");
            }

        })

//hiding adjuntos in case no content, for styling sake

        if(!$(".full_noticia_container .adjuntos a").length){ //checking if a element exists in adjuntos
            //$(".full_noticia_container .roundedcornr_content").css({height:"450px"});
            $(".full_noticia_container .adjuntos").remove();
        }
//tooltip for adjuntos description

        $('.adjuntos .tooltip').hide();

        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'
            }).appendTo("body").fadeIn(200);
        }
		$('.adjuntos 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('div').text();
                        if(content!=""){
                    showTooltip(posX, posY,content);
                        }
					},
					out: function (){
					$("#tooltip").remove();
					}

				}

		);

    });

