$(document).ready(function() {
  $(".favorite_unfavorite").click(function () { 
    var link =  $(this);
    var href = $(this).attr('href');

    if (href == '/-login') {
    } else {
      $.get(href, {},
      function(data){
        var code = data.split(':')[0];
        if (code == "OK") {
          var count = data.split(':')[1];
          link.html(count);
          
          var where =href.indexOf('/-fav');
          if (where == 0) {
            href = href.replace("/-favorite", "/-unfavorite");
			link.addClass('favorited');
          } else {
            href = href.replace("/-unfavorite", "/-favorite");
			link.removeClass('favorited');
          }
          link.attr('href', href);
        }      
      });
  
      return false;
    }
  });
  
  $(".follow_unfollow").click(function () { 
    var link =  $(this);
    var href = $(this).attr('href');

    if (href == '/-login') {
    } else {
      $.get(href, {},
      function(data){
        var code = data.split(':')[0];
        if (code == "OK") {
          var where =href.indexOf('/-follow');
          if (where == 0) {
            href = href.replace("/-follow", "/-unfollow");
            link.html("Unfollow User");
          } else {
            href = href.replace("/-unfollow", "/-follow");
            link.html("Follow User");
          }
          link.attr('href', href);
        }      
      });
  
      return false;
    }
  });  
	
$(".fullsize img").lazyload({effect : "fadeIn" });

	function tooltip(){	
		/* CONFIG */		
			xOffset = 20;
			yOffset = 10;		
			// these 2 variable determine popup's distance from the cursor
			// you might want to adjust to get the right result		
		/* END CONFIG */		
		$("a.tooltip").hover(function(e){		
			this.t = $(this).find('.username').html();
			this.title = "";									  
			$("body").append("<p id='tooltip'>"+ this.t +"</p>");
			$("#tooltip")
				.css({"top":(e.pageY - xOffset) + "px", "left":(e.pageX + yOffset) + "px"})
				.fadeIn("fast");		
	    },
		function(){
			this.title = this.t;		
			$("#tooltip").remove();
	    });	
		$("a.tooltip").mousemove(function(e){
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});			
	};

	// starting the script on page load

	tooltip();



   	$(".thumbs a:nth-child(5n)").css("margin-right", "0");

	$(".images .thumbs a").live('click', function(){
		var src = $(this).find('img').attr('src');
		src = src.substring(src.indexOf('1:1/')+4)

		var imgholder = $(this).parents('.images').find(".fullsize");
		var img = $(this).parents('.images').find(".fullsize img");
		var h = img.height();
		imgholder.height(h)
		$(img).fadeOut('fast', function(){
			imgholder.height(h)
		})
		.load(function(){
			$(this).hide();
			$(imgholder).animate({'height':$(this).height()+'px'}, 'fast')
			$(this).fadeIn('fast');
		}).attr({'src':'/slir/w460/'+src});

		return false;
	});



});