olga.articles = {
    dom: {},
    
    init: function() {
        var self = this;
        
        /*
        this.dom.tabComments = $('#tab-comments');
        this.dom.tabStories = $('#tab-stories');
                
        this.dom.tabComments.click(function() {
            self.dom.tabStories.removeClass('on');            
            self.stories.close()
            
            self.dom.tabComments.addClass('on');
            self.comments.open()
        });
        
        if(!this.dom.tabStories.is('.disabled')) {
            this.dom.tabStories.click(function() {
                self.dom.tabComments.removeClass('on');            
                self.comments.close()
                
                self.dom.tabStories.addClass('on');
                self.stories.open()
            });
        }
        */

        this.comments.init();        
        //this.stories.init();
        this.actions.init();
        //this.polls.init();
	},
	
	comments: {
	    data: {
	        open: false
	    },
	    
	    dom: {},
	    
	    init: function() {
            this.dom.core = $('#comments');
	    },
	    
	    open: function() {
	        var self = this;

    	    this.dom.core.load(olga.settings.commentsUrl, function() {
    	        self.dom.core.show();
    	        self.init();
    	        
    	        self.data.open = true;
    	    });
	    },
	    
	    close: function() {
	        this.dom.core.hide();
	        
            this.data.open = false;
	    }
	},
	
	/*stories: {
	    data: {
	        open: false
	    },
	
	    dom: {},
	    
	    init: function() {
            this.dom.core = $('#stories');
	    },
	    
	    open: function() {
	        var self = this;

    	    this.dom.core.load(olga.settings.storiesUrl, function() {
    	        self.dom.core.show();
    	        self.init();
    	        
    	        self.data.open = true;
    	    });
	    },
	    
	    close: function() {
	        this.dom.core.hide();
	        
            this.data.open = false;
	    }
	},*/
	
	actions: {
	    init: function() {
	        this.thumb.init();
	    },
	    
	    thumb: {
	        dom: {},
	        
	        init: function() {
	            var self = this;
	            
	            this.dom.core = $('.case-actions .thumb');
	            this.dom.count = $('strong', this.dom.core);
	            
	            this.dom.core.click(function() {
	                self.vote(this.id.split('-')[1]);
	            });
	        },
	        
	        vote: function(id) {
	            var self = this;
	            
	            $.post(olga.settings.thumbUrl, {id:id}, function(data) {
	                if(parseInt(data)==1) {
        	            self.dom.count.html(parseInt(self.dom.count.html())+1);
        	        }
        	        else {
        	            alert("Tyyppi yrittää huijata. Hyvä piirre sussa mut just nyt ei onnistu.");
        	        }
    	        });
	        }
	    }
	}
}

jQuery(document).ready(function() {
    olga.articles.init();
});
