$(function(){
	
	 // abre links en blank
	function externalLinks() {
		if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		   anchor.getAttribute("rel") == "external")
		 anchor.target = "_blank";
		}
		}
	window.onload = externalLinks;
	
	
	//funciones menu
	
	$("a#about").click(function () {
		$("#encabezado").animate({width:300},700,'easeInOutCirc');
		$(".imagenes").animate({width:650},800,'easeOutExpo');
		$(this).fadeTo(500,2.0);
		$("#cerrar_info").fadeIn();
	});
	
	$("#cerrar_info").click(function () {
		$("#encabezado").animate({width:0},700,'easeInOutCirc');
		$(".imagenes").animate({width:700},800,'easeOutExpo');
		$("a#about").fadeTo(500,0.6);
		$(this).css("display","none");
	});
	
	
	/*Efecto menu*/
	
	$("menu a").fadeTo(1200,1.0,function(){
		$("menu").animate({left:15},1000,'easeOutElastic',function(){
			$("menu a").fadeTo(500,0.6)
//			$(this).animate({left:-18})
		});
	});
	
	/*$("menu").mouseenter(function(){
		$(this).stop(true,true).animate({left:0},300);
	}).mouseleave(function () {
		$(this).stop(true,true).animate({left:-18},300);
	});*/
	
	$("menu a").mouseenter(function () {
		$(this).dequeue();
		$(this).stop();
		$(this).animate({left:-5});
		
	}).mouseleave(function () {
		$(this).dequeue();
		$(this).stop();
		$(this).animate({left:5});	
	});
	
	
	
	/*Tooltip*/
	//$("#twitter").attr('title',$("twitter_update_list li").html());
	
	$('#example-1').tipsy();
    
    $('.north').tipsy({gravity: 'n'});
    $('.south').tipsy({gravity: 's'});
    $('.east').tipsy({gravity: 'e'});
    $('.west').tipsy({gravity: 'w'});
	$('#twitter').tipsy({
		html:true,
		gravity:'w',
		fade:true,
		delayOut: 40000,
		fallback:function(){ 
				return $("#twitter_update_list li").html();
			}
		});
	
    /*$('#auto-gravity').tipsy({gravity: $.fn.tipsy.autoNS});
    
    $('#example-fade').tipsy({fade: true});
    
    $('#example-custom-attribute').tipsy({title: 'id'});
    $('#example-callback').tipsy({title: function() { return this.getAttribute('original-title').toUpperCase(); } });
    $('#example-fallback').tipsy({fallback: "Where's my tooltip yo'?" });
    
    $('#example-html').tipsy({html: true });*/
	
	
	/* Programado por Juan Andrés Melgarejo lord.guardian@gmail.com*/
	$("aside").css({
    "bottom": "auto",
    "left": "auto",
    "position": "absolute",
    "right": "0",
    "top": "0"
	})

	$(window).scroll(function(){
			$("article").each(function(){
				var desplazamiento=$(this).offset().top-10,
					altura=$(this).outerHeight(),
					totalscroll=$(window).scrollTop(),
					p=$(this).find("aside").outerHeight(true),
					q=$(this).find("aside").offset().left;
			
			if(desplazamiento-totalscroll<0&&desplazamiento-totalscroll>-altura&&
				desplazamiento-totalscroll<10+p-altura)
				$(this).find("aside").data("fixed","false").css({
					position:"absolute",
					right:"0px",
					left:"auto",
					bottom:"0px",
					top:"auto"
				});
			else desplazamiento-totalscroll<0&&desplazamiento-totalscroll>-altura?$(this).find("aside").data("fixed","true").css({
				position:"fixed",left:q+"px",
				bottom:"auto",top:"10px"}):$(this).find("aside").data("fixed","false").css({
					position:"absolute",
					right:"0px",
					left:"auto",
					bottom:"auto",top:"0px"});
		if($(this).find("aside").data("fixed")=="true"){
			desplazamiento=$(this).offset().left+$(this).find(".entry").outerWidth(false)-$(window).scrollLeft();
		}
		})
	});
	
});



