/*
	copyright 2009 getconfused.net
*/
var Cocopit = function ()  
{
    
}
var a = Cocopit;

Cocopit.moving = false;

a.prototype.init = function(){
    var _self = this;
    this.currPost = 0;
    $('#nextLink').click(function() {
        _self.next();
        return false;        
    });    
    $('#prevLink').click(function() {
        _self.prev();
        return false;
    });    
    $('#prevLink').hide();
    
    $('#navigator')
		.mousewheel(function(event, delta) {
			if (delta > 0 && !Cocopit.moving) {
			    
                _self.prev();
			} else if (delta < 0 && !Cocopit.moving) {
                _self.next();
			}
		});
    
}

a.prototype.next = function() {

    var _self = this;
    var curr = $(".post");
    var w;
    
    $('#prevLink').show();
    if (_self.currPost < $(".post").size()) {
        
        $(".post").each(function(index) {
            if (index==_self.currPost && index < $(".post").size()-1) {
                w = $(this).width();
                return;
            }
        });
        w+=10;

        _self.currPost++;
        Cocopit.moving = true;
        $("#navigator").animate({ 
            marginLeft: "-="+w+"px"
        }, 1500, function(){
            Cocopit.moving = false;
        } );
        if (_self.currPost == $(".post").size()-1) { 
            $('#nextLink').hide();        
        }
    }
}

a.prototype.prev = function() {

    var _self = this;
    var curr = $(".post");
    var w;
    
    $('#nextLink').show();
    if (_self.currPost > 0) {
        
        $(".post").each(function(index) {
            if (index==_self.currPost-1 && _self.currPost >= 0) {
                w = $(this).width();
                return;
            }
        });
        w+=10;


        _self.currPost--;
        Cocopit.moving = true;
        $("#navigator").animate({ 
            marginLeft: "+="+w+"px"
        }, 1500, function(){
            Cocopit.moving = false;            
        } );
        
        if (_self.currPost == 0) {
            $('#prevLink').hide();
        }
        
    } 
}

$(document).ready(
	function() {
      myCoco = new Cocopit();
      myCoco.init();
	}
);
