 $(document).ready(function(){
    $( "#tabs" ).tabs();
    $(".price_item .compare").css('display','none');

    if($.browser.msie){
            var ie_ver=parseInt($.browser.version,10);
            item_class='price_item_sel_ie';
            if(ie_ver>7){
                    var h_offset=27; var v_offset=13;
            }else{
                    var h_offset=17; var v_offset=14;
            }
    }else{
            item_class='price_item_sel';
            var h_offset=27; var v_offset=15;
    }
    $("body").append('<div class="'+item_class+'" id="item_selected"></div>');

    $(".price_item").mouseenter(function() {
        var this_item = $(this);
        if ($("span.no_div", this_item).length== 0){

                var id_ = this.id;

                var divhtml=this_item.html();
                var p = this_item.offset();
    p.top = this.offsetTop;

                var new_div = $("#item_selected");
                new_div.hide().html(divhtml);

                if ($(".color_var", new_div).length){
                        $(".color_var", new_div).show();
                        $(".price_block", new_div).css('display','none');
                }
                $('.compare', new_div).css('display','block');
                $('.label_new', new_div).css("left",183).css("top",24);
                $("#item_selected").css("left",p.left - h_offset).css("top",p.top - v_offset).fadeIn(250);

                $(".price_1_str", new_div).click(function() {
                        if($(this).find('a').length>0){
                           var curr_link = $(this).find('a').attr('href');
                           var curr_img = $(this).find('.img_str').val();

                           if(curr_img.length>0){
                              var s = curr_link.split('/',5);
                              var img_src = 'http://'+s[2]+'/img/'+s[3]+'/_'+curr_img+'_1.jpg';
                              $(".image img", new_div).attr("src",img_src);
                           }
                           $(".image a, .desc a", new_div).attr("href",curr_link);
                        }
                        $(".price_1_str_sel", new_div).each(function(el) {
                            $(this).attr('class','price_1_str');
                        });
                        $(this).attr('class','price_1_str_sel');
                });
                $("#item_selected").mouseleave(function(){
                        $("#item_selected").hide();
                });

        }
    });


    $('form.tocart').submit(function(e) {
            e.preventDefault();
                    var flds = '';
                    var fields=$(this).serializeArray();
                    jQuery.each(fields, function(i, field){
                            flds+=field.name + '=' + field.value + '&';
                    });
            flds+='ajax=1';
            $.ajax({
                    url: '../../cart/cart.php',
                    type: 'POST',
                    cache: false,
                    data: flds,
                    success: function(html){
                            if(html=='added'){
                                    $("#cart_info").load("../../cart/cart_info.php?ajax=1");
                                    //alert('Товар добавлен в корзину');
                            }
                    },
                    error: function(){
                            alert('Ошибка при добавлении в корзину');
                    }
            });

    });

    $('a.compare_link').live('click', function(e) {
            e.preventDefault();
                    var href = $(this).attr('href');
            href+='&ajax=1';
            $.ajax({
                    url: href,
                    type: 'GET',
                    cache: false,
                    success: function(html){
                            $("#cmp_info").load("../../compare/cmp_info.php?ajax=1");
                            alert('Товар добавлен к списку сравнения');
                    },
                    error: function(){
                            alert('Ошибка при добавлении к списку сравнения');
                    }
            });

    });

    $(".price_item img, .price_2_item img").error(function(){
      $(this).attr('src', 'http://www.naviburg.ru/img/no_img.jpg');
    });


    $(".price_2_str").click(function(){
       var price_group = $(this).parents('.price_2_item');
       var init_title = price_group.find('.price_2_img a').attr('title');
       var curr_link = $(this).find('.model_link').attr('href');
       var curr_img = $(this).find('.img_str').val();
       var s = curr_link.split('/',5);
       var img_src = 'http://'+s[2]+'/img/'+s[3]+'/_'+curr_img+'_1.jpg';

       if($(this).attr('class')!='price_2_str_sel'){
          $(".price_2_img img", price_group).attr("src",img_src);
          $(".price_2_img a", price_group).attr("href",curr_link);

          $(".price_2_str_sel", price_group).each(function(el) {
              $(this).attr('class','price_2_str');
          });
          $(this).attr('class','price_2_str_sel');

          var part_name = price_group.find('.group_part_name').val();
          var curr_model = part_name + ' ' + $(this).find('.model_link').text();
          price_group.find('h3.price_2').text(curr_model);

          var a = $(this).find('.shortdesc').val();
          price_group.find('.curr_model_desc').text(a);

       }else{
        $(this).attr('class','price_2_str');

          price_group.find('h3.price_2').text(init_title);
          price_group.find('.curr_model_desc').text('');
       }
    });

  });

function searchcheck(){
         if (document.frmsearch.query.value == " что искать..."||document.frmsearch.query.value == "") {
                 alert("Что искать?");
                 return false;
         }
}
