/**
 * Core Design Ajax Vote plugin for Joomla! 1.7
 * @author		Daniel Rataj, <info@greatjoomla.com>
 * @package		Joomla
 * @subpackage	Content
 * @category	Plugin
 * @version		2.0.2
 * @copyright	Copyright (C) 2007 - 2011 Great Joomla!, http://www.greatjoomla.com
 * @license		http://www.gnu.org/copyleft/gpl.html GNU/GPL 3
 * 
 * This file is part of Great Joomla! extension.   
 * This extension is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This extension is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

if (typeof(jQuery) === 'function') {
	(function($) {
		$.cdajaxvote = {
			
			// Vote function
			vote: function(element, action) {
				var num = element.next('div.rating_count').children('span');
				
				switch(action) {
					case '+':
						num.text((num.text() * 1) + 1);
						break;
					case '-':
						num.text((num.text() * 1) - 1);
						break;
					case 'reset':
						num.text(0);
						break;
					default:
						break;
				}
			},
			
			// Loading image
			loading: function(element) {
				var text = element.next('div.rating_count');
				if (text.next('div.loading').length > 0) {
					text.next('div.loading').remove();
				} else {
					text.after('<div class="loading"></div>');
				}
			}
		};
	})(jQuery);
}
