/**
 * Main script.
 * Initialize hover effect on <tr>
 * Confirmation window when clicking on link with class .icon-delete.
 *
 * @author Nikita Vershinin <me@endeveit.net>
 */
(function($) {
    $(document).ready(function() {
        // 
        $('#userlog').click(function(){
                $('#register').slideToggle(400);
        }
        );
		$('#reg').click(function(){
                $('#registrat').slideToggle(400);
        }
        );
        $('#all_themes').click(function(){
                $('#all_themes_show').slideToggle(400);
        }
        );
        
        // Input placeholders
    var cls = 'placeholded';
    $('input[alt]').each(function () {
      $(this).bind('focus', function() {
        var o = $(this);
        o.removeClass(cls);

        if (o.val() == o.attr('alt')) {
          o.val('');
        }
      }).bind('blur', function() {
        var o = $(this);

        if (o.val() == '' || o.val() == o.attr('alt')) {
          o.val(o.attr('alt')).addClass(cls);
        }
      }).addClass(cls).val($(this).attr('alt')); // init field
    });
    // /Input placeholders
    
    var cls = 'placeholded';
    $('textarea[alt]').each(function () {
      $(this).bind('focus', function() {
        var o = $(this);
        o.removeClass(cls);

        if (o.val() == o.attr('alt')) {
          o.val('');
        }
      }).bind('blur', function() {
        var o = $(this);

        if (o.val() == '' || o.val() == o.attr('alt')) {
          o.val(o.attr('alt')).addClass(cls);
        }
      }).addClass(cls).val($(this).attr('alt')); // init field
    });
    // /Input placeholders

        $('a.add-good').click(function() {
            var
                input = $(this).parent().next().children('input').get(0),
                id = $(this).attr('id').split('-')[1],
                quantity = 0;
            
            try {
                quantity = parseInt($(input).val());
            } catch (e) {
            }
            
            if (isNaN(quantity) || quantity <= 0) {
                alert('Вы должны указать количество товаров');
                $(input).focus();
            } else {
                $.post('/goodcatalog/add/', { good_id : id, quantity : quantity }, function(data) {
                    $('.korz').html(data);
                });
                alert('Заказ принят');
            }

            return false;
        });
        // /
    })
})(jQuery);
