var fact = fact||{};
fact.search={
    init:function(){
        $('.txt-people').click(function(){
            var val = this.value;
            if(val=='Type a name'){
                $(this).val('');
                $(this).removeClass('shade');
            }else if(val==''){
                $(this).val('Type a name');
                $(this).addClass('shade');                
            }
        });
        $('.txt-people').blur(function(){
            var val = this.value;
            if(val==''){
                $(this).val('Type a name');
                $(this).addClass('shade');                
            }
        });
    }
}
fact.interesting={    
    factBtn:null,
    init:function(){
        var that = this;
        that.factBtn = $('.btn-interesting');
        that.factBtn.click(function(){            
            that.mark(this);
        });
    },
    mark:function(obj){
        var id=$(obj).attr('id');
        var tp=$(obj).attr('title');
        var val=$(obj).val();
        var msg = '';
        if(tp=='photo'){
            msg = '<p class="interesting-msg">Added to your interesting pictures</p>';
        }else{
            msg = '<p class="interesting-msg">Added to your interesting facts</p>';
        }
        
        if(val=='Interesting'){
            $.ajax({
                type:'post',
                url:'ajax/mark-interesting',
                data:{'id':id,'type':tp},
                success:function(){
                    $(obj).addClass('interesting-sel');
                    $(obj).val('Remove');
                    $(msg).insertAfter($(obj));
                }
            });
        }
        if(val=='Remove'){
            $.ajax({
                type:'post',
                url:'ajax/remove-interesting',
                data:{'id':id,'type':tp},
                success:function(){
                    $(obj).removeClass('interesting-sel');
                    $(obj).val('Interesting');
                    $(msg).insertAfter($(obj));                    
                }
            });
        }
    }
}
fact.user={
    init:function(){
        var that = this;
        $('.btn-follow').click(function(){
            that.follow(this);
        });
    },
    follow:function(obj){
        var id = $(obj).attr('id');
        var value = $(obj).val();
        if(value=='Follow'){
            $.ajax({
                type:'post',
                url:'ajax/follow',
                data:{'id':id},
                success:function(){
                    $(obj).val('Unfollow').addClass('follow-sel');
                }
            });
        }
        if(value=='Unfollow'){
            $.ajax({
                type:'post',
                url:'ajax/unfollow',
                data:{'id':id},
                success:function(){
                    $(obj).val('Follow').removeClass('follow-sel');                    
                }
            });
        }
    }
}
fact.update={
    init:function(){
        var that = this;
        $('.btn-delete').click(function(){
            var del = confirm('Are you sure you want to delete?');
            if(!del){return true;}
            that.del(this); 
        });
    },
    del:function(obj){
        var id = $(obj).attr('id');
        $.ajax({
            type:'post',
            url:'ajax/delete-update',
            data:{'id':id},
            success:function(resp){                
                $(obj).parent('.fact-item').fadeOut('fast');                   
            }
        })
    }
}
