﻿//some functions are got from http://ulan.en.cx/
// �������� ������
(function ($) {
    $.fn.countdown = function (date, options) {
        options = jQuery.extend({
            lang: {
                years: ['���', '����', '���'], months: ['�����', '������', '�������'], days: ['����', '���', '����'],
                hours: ['���', '����', '�����'], minutes: ['������', '������', '�����'], seconds: ['�������', '�������', '������'],
                plurar: function (n) { return (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); }
            },
            prefix: '�������� ', finish: '�������!'
        },
        options);
        var timeDifference = function (begin, end) {
            if (end < begin) { return false; }
            var diff = {
                seconds: [end.getSeconds() - begin.getSeconds(), 60],
                minutes: [end.getMinutes() - begin.getMinutes(), 60],
                hours: [end.getHours() - begin.getHours(), 24],
                days: [end.getDate() - begin.getDate(), new Date(begin.getYear(), begin.getMonth() + 1, 0).getDate() - 1],
                months: [end.getMonth() - begin.getMonth(), 12],
                years: [end.getYear() - begin.getYear(), 0]
            };
            var result = new Array();
            var flag = false;
            for (i in diff) {
                if (flag) { diff[i][0]--; flag = false; }
                if (diff[i][0] < 0) { flag = true; diff[i][0] += diff[i][1]; }
                if (!diff[i][0]) continue;
                result.push(diff[i][0] + '<small>' + options.lang[i][options.lang.plurar(diff[i][0])] + '</small>');
            }
            return result.reverse().join(' ');
        };
        var elem = $(this);
        var timeUpdate = function () {
            var s = timeDifference(new Date(), date);
            if (s.length) { elem.html(options.prefix + s); }
            else { clearInterval(timer); elem.html(options.finish); }
        };
        timeUpdate();
        var timer = setInterval(timeUpdate, 1000);
    };
})(jQuery);

// ���������� ������ "���������� �������" � ����� �� ������� ��������
function vk_like() {
    $('a#lnkGameTitle').each(function () {
        $(this).closest('table').after('<div class="vk-like">' + VK.Share.button(
            { url: 'http://' + location.hostname + $(this).attr('href'), title: $(this).text(), description: 'Encounter - ������������� ���� �������� ��������� ���', noparse: true },
            { type: 'button', text: '���������� �������' }
        ) + '</div><div class="clear"></div>');
    });
}

// ������ AddThis
function share_button() {
    $('a#lnkGameTitle').each(function () {
        $(this).closest('table').after('<div class="share-button">' +
        '<div class="addthis_toolbox addthis_default_style" addthis:url="http://' + location.hostname + $(this).attr('href') + '" addthis:title="' + $(this).text() + '" addthis:description="Encounter - ������������� ���� �������� ��������� ���">' +
            '<a class="addthis_button_facebook"></a>' +
            '<a class="addthis_button_twitter"></a>' +
            '<a class="addthis_button_vk"></a>' +
        '</div>' +
        '</div><div class="clear"></div>');
    });
}

//������������� ������� � jquery
(function ($) {
    $(function () {

        $('ul.tabs72').delegate('li:not(.current72)', 'click', function () {
            $(this).addClass('current72').siblings().removeClass('current72')
      .parents('div.section72').find('div.box72').hide().eq($(this).index()).fadeIn(350);
        })

    })
})(jQuery)
