
//cookie	
	/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
//cookie	
	
	
	
$(document).ready(function(){	
	if((window.location.href) == "http://4winners.ru/ocenite-trenera/")
	{
	//получаем набор значений ректинга каждого тренера из скрипта
	$.post("http://4winners.ru/wp-content/themes/free_wp_premium/wp_premium/script/getscore.php",{act:"get"},function(data){
		
		var array = data.split(" ");
		$i=-1;
		array.forEach( function(item){ 
			$i = $i+1;
			$('#oceni_'+$i).html(item);
				if(item < 0) $('#oceni_'+$i).addClass('my_red');
		});
	});
	//получаем набор значений числа проголосовавших на сайте за каждого пользоваеля
	$.post("http://4winners.ru/wp-content/themes/free_wp_premium/wp_premium/script/getscore.php",{act:"get_count"},function(data){
		
		var array = data.split(" ");
		$i=-1;
		array.forEach( function(item){ 
			$i = $i+1;
			$('#rated_'+$i).html(item);
		});
	});


	}
});





	//плюсуем ректинг тренера
	function plus_one(id){
			//проверяем куки браузера с идентификатором тренера
			var $myCookie = $.cookie('id'+id);
			//если они установлены в проголосовал
			if($myCookie=='rate') 
			{
				$('#oceni_'+id).append("<p class='already_rate'>Вы уже голосовали за этого тренера.</p>").fadeIn('slow');
				setTimeout(function(){$('.already_rate').fadeOut('slow')},1000);
			}
			//если человек не голосовал, плюсуем
			else
			{
				$.post("http://4winners.ru/wp-content/themes/free_wp_premium/wp_premium/script/getscore.php",{act:"plus",id:id},function(data){
					if (data != 'nosuccess')
					{
						$('#oceni_'+id).html(data);
						$.cookie('id'+id, 'rate');
						if(data == '0') $('#oceni_'+id).removeClass('my_red');
						var $count = $('#rated_'+id).text();
						++$count;
						$('#rated_'+id).html($count);
					}
					else
					alert('Не удалось соединиться с сервером базы данных');
				});
			}
	}
	//минусуем рейтинг тренера
	function minus_one(id){
			//проверяем куки браузера с идентификатором тренера
			var $myCookie = $.cookie('id'+id);
			//если они установлены в проголосовал
			if($myCookie=='rate') 
			{
				$('#oceni_'+id).append("<p class='already_rate'>Вы уже голосовали за этого тренера.</p>").fadeIn('slow');
				setTimeout(function(){$('.already_rate').fadeOut('slow')},1000);
			}
			//если человек не голосовал, плюсуем
			else
			{
				$.post("http://4winners.ru/wp-content/themes/free_wp_premium/wp_premium/script/getscore.php",{act:"minus",id:id},function(data){
					if (data != 'nosuccess')
					{
						$('#oceni_'+id).html(data);
						$.cookie('id'+id, 'rate');
						if(data == '-1') $('#oceni_'+id).addClass('my_red');
						var $count = $('#rated_'+id).text();
						++$count;
						$('#rated_'+id).html($count);
					}
					else
					alert('Не удалось соединиться с сервером базы данных');
				});
			}
	}

	
