var locate=true;

but1_0 = new Image();
but1_0.src = "/images/main_button_0.gif";
but1_1 = new Image();
but1_1.src = "/images/main_button_1.gif";

but2_0 = new Image();
but2_0.src = "/images/about_button_0.gif";
but2_1 = new Image();
but2_1.src = "/images/about_button_1.gif";

but3_0 = new Image();
but3_0.src = "/images/news_button_0.gif";
but3_1 = new Image();
but3_1.src = "/images/news_button_1.gif";

but4_0 = new Image();
but4_0.src = "/images/catalog_button_0.gif";
but4_1 = new Image();
but4_1.src = "/images/catalog_button_1.gif";

but5_0 = new Image();
but5_0.src = "/images/contacts_button_0.gif";
but5_1 = new Image();
but5_1.src = "/images/contacts_button_1.gif";

but6_0 = new Image();
but6_0.src = "/images/del_button_0.gif";
but6_1 = new Image();
but6_1.src = "/images/del_button_1.gif";

but7_0 = new Image();
but7_0.src = "/images/podbor_button_0.gif";
but7_1 = new Image();
but7_1.src = "/images/podbor_button_1.gif";

sbut_0 = new Image();
sbut_0.src = "/images/sbutton.gif";
sbut_1 = new Image();
sbut_1.src = "/images/sbutton_1.gif";

send_0 = new Image();
send_0.src = "/images/send_button.gif";
send_1 = new Image();
send_1.src = "/images/send_button_1.gif";

conf_0 = new Image();
conf_0.src = "/images/conf_button.gif";
conf_1 = new Image();
conf_1.src = "/images/conf_button_1.gif";

rec_0 = new Image();
rec_0.src = "/images/cbutton.gif";
rec_1 = new Image();
rec_1.src = "/images/cbutton_1.gif";

mbut_0 = new Image();
mbut_0.src = "/images/fbutton.gif";
mbut_1 = new Image();
mbut_1.src = "/images/fbutton1.gif";

make_0 = new Image();
make_0.src = "/images/make_button.gif";
make_1 = new Image();
make_1.src = "/images/make_button1.gif";

login_0 = new Image();
login_0.src = "/images/ebutton.gif";
login_1 = new Image();
login_1.src = "/images/ebutton_1.gif";

save_0 = new Image();
save_0.src = "/images/save_button.gif";
save_1 = new Image();
save_1.src = "/images/save_button_1.gif";


loader=new Image();
loader.src="/images/ajax-loader.gif";

loader_1=new Image();
loader_1.src="/images/ajax-loader_1.gif";

 $(function() {
        $('a.lightbox').lightBox();
    });


function AddCart(id) {
    locate=false;
    $.ajax({
                        url: 'ajax/addcart.php',
                        type:'post',
                        data: 'id='+id,
                        success: function (data, textStatus) {
                            //alert(data);
                            eval(data);
                            $('#cart_count').html(CartCount);
                            $('#cart_summ').html(CartSum+' руб.');
                             $('#cart_count2').html(CartCount);
                            $('#cart_summ2').html(CartSum+' руб.');
                            if (CartSum>0) {$('#cart_href1').html('<a href="/cart/">Оформить заказ</a>');}
                            if (CartSum>0) {$('#cart_href2').html('<a href="/cart/">Оформить заказ</a>');}
                            $('#cart_button_'+id).html('<div>В корзине</div>');
                            $('#cart_button_'+id).attr('class','pr_button3');
                            $('#cart_button_'+id).mouseout(function(){$(this).attr('class','pr_button3');});
                            $('#cart_button_'+id).mouseover(function(){$(this).attr('class','pr_button3');});                          
                            locate=true;
                     }
                });
}

Go=function(href) {  
  if (locate) {
   document.location=href;
  }
}


var Shown=1;
function Slide(id) {
    $('#tr_head_'+Shown).attr('class','border_top_inactive');
    $('#tr_head_'+id).attr('class','border_top_active');
    $('#tr_head_img_'+Shown).attr('src','/images/step'+Shown+'s.gif');
    $('#tr_head_img_'+id).attr('src','/images/step'+id+'.gif');
    $('#step'+Shown+'_content').hide("slide", { direction: "up" }, 500,function() {
        $('#step'+id+'_content').show("slide", { direction: "down" } );
        Shown=id;
    });

}

function SetDelivery(id) {
   if (id==1) {Delivery=RawDelivery;}
   else if (id==2) {Delivery=500;}
   else {Delivery=0;}
   if (BasketSumm>30000) {Delivery=0;}
   $('#delivery_count').html(Delivery+' руб.');
  $('#delivery_value').html(Delivery+' руб.');
  s=BasketSumm+Delivery;
  $('#summ_value').html(s+' руб.');
  $('#delivery_cost').val(Delivery);
}

function NameFilter(word) {
    $('#products_content_div').html('Загрузка данных... <img src="/images/ajax-loader.gif">');
    $.ajax({
                        url: 'ajax/namefilter.php',
                        type:'post',
                        data: 'gid='+GroupId+'&bid='+BrandId+'&word='+word+'&view='+ViewId,
                        success: function (data, textStatus) {
                            $('#products_content_div').html(data);
                            $('.product').mouseover(function(){$(this).addClass('product_hover');});
                             $('.product').mouseout(function(){$(this).removeClass('product_hover');});
                             $('.product').tooltip({
                                delay: 0,
                                showURL: false,
                                bodyHandler: function() {
                                    return $('#add_'+$(this).attr('id')).html();
                                }
                            });
                            $('.pr_button1').mouseover(function(){$(this).attr('class','pr_button2');});
                            $('.pr_button1').mouseout(function(){$(this).attr('class','pr_button1');});

                            $('.product_wide').mouseover(function(){$(this).addClass('product_hover');});
                            $('.product_wide').mouseout(function(){$(this).removeClass('product_hover');});
                            
                     }
                });
}

function HoverTab(el,flag,type) {
  if (type=='gray') {h='TabHoverGray';t='TabGray';} else {h='TabHover';t='Tab';}
  if (flag) {
    ActiveTab=el.className;
    el.className=h;
  }
  else {
    if (ActiveTab!='') {
      el.className=ActiveTab;
    }
    else {
      el.className=t;
    }
  }
}

function ChangeTab(id) {
   if (id==1) {
        $('#product_response_div').style('display','none');
         $('#product_addtext_div').style('display','');
   }
   if (id==2) {
        $('#product_addtext_div').style('display','none');
         $('#product_response_div').style('display','');
   }
}


required = new Array("username","usermail","review_content");
required_show = new Array("Имя","E-mail","Текст отзыва");

function CheckReview () {
    var i, j;
    ret=true;
    for(j=0; j<required.length; j++) {
        for (i=0; i<document.forms['add_review_form'].length; i++) {           
            if (document.forms['add_review_form'].elements[i].name == required[j] && document.forms['add_review_form'].elements[i].value == "" ) {
                alert('Пожалуйста, заполните поле "' + required_show[j]+'"');
                document.forms['add_review_form'].elements[i].focus();
                ret=false
            }
        }
    }
    if (ret) {
        $('#add_review_form').submit();
    }
}


var shown='';
function ShowMenu(step,id,flag) {
   if (step==1) {pref='br';}
   else if (step==2) {pref='gr';}
   cl=$('#li'+step+'_'+id).attr('class');     
   if (cl=='out') {
       $('#li'+step+'_'+id+'_loader').html('&nbsp;&nbsp;&nbsp;<img id="current_load">');
       $('#current_load').attr('src',loader_1.src);
                $.ajax({
                        url: 'ajax/podbor.php',
                        type: 'post',
                        data: 'step='+step+'&ids='+id,
                        success: function (data, textStatus) {
                            $('#'+pref+'_'+id).html(data);
                            $('#li'+step+'_'+id).attr('class','in');
                            $('#li'+step+'_'+id+'_loader').html('');
                        }
                });
   }
   else {
      $('#'+pref+'_'+id).html('');
      $('#li'+step+'_'+id).attr('class','out');
   }
}

var selEq='';
function ShowEquipment(id) {
      if (selEq>0) { if ($('#last_'+selEq)) { $('#last_'+selEq).attr('class','last'); } }
      $('#last_'+id).attr('class','last_sel');
      $('#last_'+id+'_loader').html('&nbsp;&nbsp;&nbsp;<img id="current_load">');
      $('#current_load').attr('src',loader_1.src);
      selEq=id;
      $.ajax({
                        url: 'ajax/podbor.php',
                        type: 'post',
                        data: 'step=3&ids='+id,
                        success: function (data, textStatus) {
                            if ($.browser.msie) {document.location.href="#result_href";}
                            else {document.location="podbor/#result_href";}
                            $('#podbor_results').html(data);
                            $('#last_'+id+'_loader').html('');
                        }
                });
}

function ModelSearch() {
      var model=$('#podbor_model').val();
      var type=$('#podbor_search_type').val();
      $('#podbor_results').html('<center><img id="current_load"></center>');
      $('#current_load').attr('src',loader.src);
      $.ajax({
                        url: 'ajax/podbor.php',
                        type: 'post',
                        data: 'step=4&model='+model+'&ids='+type,
                        success: function (data, textStatus) {
                            $('#podbor_results').html(data);
                        }
                });
}
