$(function() {
		   
		$(".catWrapper .card:nth-child(2n+1)").css("clear", "left"); 
/*		$(".headBanner").position({my: "top center", at: "top", of: $("body"), offset: "0 80"});*/
               
    $('#login-form .input-text, #search-form .input-textsearch')
        .each(function() {
            $(this).data('def', this.value);
        })
        .focus(function() {
            if(this.value == $(this).data('def')) this.value = '';
        })
        .blur(function() {
            if(this.value == '') this.value = $(this).data('def');
        })
    ;

    $('form').submit(function(e) {

        var flag = true;

        $('.required', this).each(function() {

            if(this.value == '' || this.value == '0') {

                flag = false;
                return false;

            }

        });

        if(!flag) {

            alert('Пожалуйста, заполните все поля, отмеченные звездочкой');

            e.preventDefault();
            return false;

        }

    });

    $('.confirm').click(function(e) {
        if(!confirm('Вы уверены?')) {
            e.preventDefault();
            return false;
        }
    });

    $('#captcha-reload').click(function() {

        var img = $('#captcha');

        if(!img.data('url')) img.data('url', img[0].src);

        img[0].src = img.data('url') + Math.random();

    });

    $('#idRole').change(function() {
        var obj = $('#idPidList');
        $(this).val() == 4 ? obj.show() : obj.hide();
    });

    if($.fn.rating) {

        var ratingCallback = function(value, link) {

            var form = $(this).parents('form');
            var obj  = $(':radio.star', form);
            var id   = $('input[name="id"]', form).val();

            $('#vote-my-'+ id).hide();

            $.post(
                'http://'+ location.hostname +'/?q=vote',
                {
                    id : id,
                    vote : value,
                    ajax : 1
                },
                function(data) {
                    $('#vote-total-'+ id).html(data.total);
                    $('#vote-my-'+ id).html('вы поставили оценку '+ value).fadeIn(300);
                    obj.data('rating').callback = null;
                    obj.rating('select', data.rate); //.rating('readOnly', true);
                    obj.data('rating').callback = ratingCallback;
                },
                'json'
            );
        }

        $(':radio.star').rating({
            callback: ratingCallback,
            required: true
        });
    }

    if($.fn.lightBox) {

        $('a.lightbox').lightBox({
            imageLoading:  root + 'images/lightbox-ico-loading.gif',
            imageBtnPrev:  root + 'images/lightbox-btn-prev.gif',
            imageBtnNext:  root + 'images/lightbox-btn-next.gif',
            imageBtnClose: root + 'images/lightbox-btn-close.gif',
            imageBlank:    root + 'images/lightbox-blank.gif'
        });

    }

});


generator = {

    digit : ['0','1','2','3','4','5','6','7','8','9'],
    halp  : ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','Y','Z'],
    lalp  : ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','y','z'],

    init : function(length) {

        if(!length) length = 8;

        var pass = '';
        var r;

        for(var i = 0; i < length; i++) {
          r = Math.random()
          if((r - 1.0/3.0) < 0.0) {
             r = Math.floor(Math.random() * 9);
             pass += generator.digit[r];
          } else if((r - 2.0/3.0) < 0.0) {
             r = Math.floor(Math.random() * 24);
             pass += generator.halp[r];
          } else {
             r = Math.floor(Math.random() * 24);
             pass += generator.lalp[r];
          }
        }
        return pass;
    }

}

deleteComment = function (id) {

    confirm('Удалить комментарий?') &&

    $.post(
        root + 'comments/delete',
        {id : id},
        function(data) {
            if(data) {
                alert(data);
                return false;
            }
            $('#comment-'+ id).slideUp(300);
        }
    );

}
function MailTo(LogIn,DoMain,LinkStyle,LinkText)
{
LinkImage=String.fromCharCode(60,97,32,115,116,121,108,101,61,34)
LinkImage+=LinkStyle
LinkImage+=String.fromCharCode(34,32,104,114,101,102,61,34,109,97,105,108,116,111,58)
LinkImage+=LogIn+String.fromCharCode(64)+DoMain+String.fromCharCode(34,62)
if (LinkText==undefined)
{
LinkImage+=LogIn+String.fromCharCode(64)+DoMain
}else{
LinkImage+=LinkText
}
LinkImage+=String.fromCharCode(60,47,97,62)
document.write(LinkImage)
}