$(document).ready(function() {

    $('.side .nav ul li a').hover(
            function() {
                $(this).parent().children('.popup').show();
            },
            function() {
                $(this).parent().children('.popup').hide();
            });

    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $('.selectfield .options').each(function(ind) {
            if ($(this).height() > 200) {
                $(this).height(200);
            }
        });
    }

    var SFl = $('.selectfield').get().length;

    $('.selectfield').each(function(ind) {
        $(this).css('z-index', SFl - ind);
    });

    $('.selectfield .options').css('display', 'none');

    $('.selectfield .box .inner').each(function(ind) {
        $(this).text(
                ( ( $(this).parent().parent().parent().children('.options').children('.optinner').children('.selected').text() == "" )
                        ? $(this).parent().parent().parent().children('.options').children('.optinner').children(':first').text()
                        : $(this).parent().parent().parent().children('.options').children('.optinner').children('.selected').text() )
                );
        $(this).parent().parent().parent().children('input').val(
                $(this).parent().parent().parent().children('.options').children('.optinner').children('.selected').children('input').val()
                );
    });

    $('.selectfield .box .inner').click(function() {
        if ($(this).parent().parent().parent().children('.options').css('display') == 'block') {
            $(this).parent().parent().parent().children('.options').stop(true, true).animate({
                height: 'toggle'
            }, 300);
        } else {
            $('.selectfield .box .inner').each(function() {
                if ($(this).parent().parent().parent().children('.options').stop(true, true).css('display') == 'block') {
                    $(this).parent().parent().parent().children('.options').stop(true, true).animate({
                        height: 'toggle'
                    }, 300);
                }
            });
            $(this).parent().parent().parent().children('.options').stop(true, true).animate({
                height: 'toggle'
            }, 300);
        }
    });

    $('.selectfield .options .optinner div').click(function() {
        $(this).parent().children('div.selected').removeClass('selected');
        $(this).addClass('selected');
        $(this).parent().parent().parent().find('.box .inner').text(
                $(this).text()
                );
        $(this).parent().parent().parent().children('input').val(
                $(this).children('input').val()
                );
        $(this).parent().parent().animate({
            height: 'toggle'
        }, 500);
    });

    //login forms
    var passwordField = $('input#smPassword');
    var loginField = $('input#smLogin');
    var loginFieldDefault = loginField.val();
    var textField = $('textarea#moreInfo');
    var textFieldDefault = textField.val();

    passwordField.after('<input id="passwordPlaceholder" type="text" value="Пароль" autocomplete="off" />');
    var passwordPlaceholder = $('#passwordPlaceholder');

    passwordPlaceholder.show();
    passwordField.hide();

    passwordPlaceholder.focus(function() {
        passwordPlaceholder.hide();
        passwordField.show().focus();
    });
    passwordField.blur(function() {
        if (passwordField.val() == '') {
            passwordPlaceholder.show();
            passwordField.hide();
        }
    });

    loginField.focus(function() {
        if (loginField.val() == loginFieldDefault) {
            loginField.val('');
        }
    });
    loginField.blur(function() {
        if (loginField.val() == '') {
            loginField.val(loginFieldDefault);
        }
    });
    textField.focus(function() {
        if (textField.val() == textFieldDefault) {
            textField.val('');
        }
    });
    textField.blur(function() {
        if (textField.val() == '') {
            textField.val(textFieldDefault);
        }
    });

 $('.close_item').click(
            function() {
                if (confirm('Удалить заказ из корзины?')) {
                    $(this).parent().remove();
                } else {
                    return false;
                }
            });

$('#test').click(function() {
  var error = '';
  var _width  = isNaN($("#num1").val() * 1) ? 0 : Math.abs($("#num1").val() * 1) ;
  var _height = isNaN($("#num2").val() * 1) ? 0 : Math.abs($("#num2").val() * 1) ;
  var checked_colors = $(".colors input[type=checkbox]:checked").length;
  
 
  if( (_width == 0) || (_height == 0) ) {
    error += "Неверно указаны размеры изделия. Введите корректные значения и повторите попытку.\n\n"
    }

  if (checked_colors == 0) {
    error += "Выберите цвет изделия и повторите попытку.\n"
    }

    if (error) {
       alert(error);
        return false;
      } 

  });

});


