$(function(){
	var posts = $('div.post-container');

	// $('a.connect, ins.close').click(function (){
	// 	$('div.home-pic').toggle();
	// 	$('div.connect-container').toggle();
	// 	return false;
	// });
	// 
	// $('#footer a.connect-box').click(function (){
	// 	$('div.home-pic').hide();
	// 	$('div.connect-container').show();
	// });
	// 
	// $('#TweetAddForm input').click(function () {
	// 		$('#TweetAddForm p.status').remove();
	// 		$('#TweetAddForm').ajaxSubmit(function () {
	// 			$('#TweetAddForm input').val('Another private tweet').after('<p class="status">Tweet sent successfully.</p>');
	// 			$('#TweetAddForm textrea').val('');
	// 		});
	// 		return false;
	// });
	
	$(window).scroll(function(){ animateDetailView(500); }).resize(function(){ animateDetailView(1); });

	function animateDetailView(time){
		posts.filter(':in-viewport').children('img').stop().animate({ opacity: "1" }, time);
		posts.not(':in-viewport').children('img').stop().animate({ opacity: "0.1" }, time);
	}
	
	  $('#content').infinitescroll({ 
	    navSelector  : ".navigation",            
	    nextSelector : ".navigation a:last",    
	    itemSelector : "div.post-container",
        loadingImg      : base + "/img/loading.gif",
        loadingText     : "",
        donetext        : "",
		debug: true     
  	}, function(){ posts = $('div.post-container'); });
});


/*
 * Viewport - jQuery selectors for finding elements in viewport
 *
 * Copyright (c) 2008-2009 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *  http://www.appelsiini.net/projects/viewport
 *
 */
(function($) {
    
    $.belowthefold = function(element, settings) {
        var fold = $(window).height() + $(window).scrollTop();
        return fold <= $(element).offset().top - settings.threshold;
    };

    $.abovethetop = function(element, settings) {
        var top = $(window).scrollTop();
        return top >= $(element).offset().top + $(element).height() - settings.threshold;
    };
    
    $.rightofscreen = function(element, settings) {
        var fold = $(window).width() + $(window).scrollLeft();
        return fold <= $(element).offset().left - settings.threshold;
    };
    
    $.leftofscreen = function(element, settings) {
        var left = $(window).scrollLeft();
        return left >= $(element).offset().left + $(element).width() - settings.threshold;
    };
    
    $.inviewport = function(element, settings) {
        return !$.rightofscreen(element, settings) && !$.leftofscreen(element, settings) && !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
    };
    
    $.extend($.expr[':'], {
        "below-the-fold": function(a, i, m) {
            return $.belowthefold(a, {threshold : 0});
        },
        "above-the-top": function(a, i, m) {
            return $.abovethetop(a, {threshold : 0});
        },
        "left-of-screen": function(a, i, m) {
            return $.leftofscreen(a, {threshold : 0});
        },
        "right-of-screen": function(a, i, m) {
            return $.rightofscreen(a, {threshold : 0});
        },
        "in-viewport": function(a, i, m) {
            return $.inviewport(a, {threshold : 0});
        }
    });
})(jQuery);
