
 $(document).ready(function(){
 var ArrayRaces,RacesForSale,Places,Race;
    var id_race=0,
    id_place=0; // Id  места(чекбокса)
     var name_place='',this_is=0;
     var cond=0; //  условие  установки чекбокса
     var id_checkbox=0; //id  выбранного чекбокса
     var race_type=0;// тип рейса : 1 -  международный
     
     var p,t;
    var id_race=0,
    C_X=0,С_Y=0;
     C_X_D=0,С_Y_D=0,
     cliked=0;
    //JQuery calendar for form Create User

 //ui-datepicker-div
 $('#href_races').click(function() {  reset_button();

$('#message_wait').show();
  $('#main_place').empty();
$('#main_place').load("shedule.php",{},function(){ $('#message_wait').hide();

 //-----------------------Общее расписане---------------------------------------------------------------
$('#button_general').click(function() {  reset_button();

$('#message_wait').show();
  $('#main_place').empty();
$('#main_place').load("races.php",{},function(){
	  $('#message_wait').hide();
	  $("#message").hide();
       $('#calendar').hide();
   $('#selected_st').keypress(function (e) {
             // alert("$('#selected_st').keypress");
               if(e.which==13) {
                                  $('#go').click();

                                }
        });

$('#go').click(function() {
var
 // date_in=$("#datepicker"),
  via_st_in = $('select[@name=selected_st] option:selected').val();
  via_st_name=$('select[@name=selected_st] option:selected').text();
  $("#wait_text").show();
  $("#message").hide();
  $("#stations").hide();
  $("#calendar").hide();

 $.post("get_shedule.php",{via_st_in:via_st_in,kesh:(new Date().getTime())},
  function(data)
  {
  		       	$("#back_shed").show();
  		       	$("#wait_text").hide();
  		       	$("#res_shed").empty();
			    $("#res_shed").show();

 $("#marshrut").text("ОБЩЕЕ РАСПИСАНИЕ.До станции "+via_st_name);
 $("#message").show();
 $("#res_shed").append("<tr>"+           // <td width=2>I</td>"+
                                        "<td width=150>Маршрут</td>"+   //1
                                        "<td width=70>Отправление</td>"+   //3
                                        "<td width=150>График</td >"+        //4
                                        "<td width=150>Автобус</td>"+  //5
                                        "<td width=200>Перевозчик</td>");     //6
   var id_button;

   for(var i=0;i<data.size_row;i++)
    {        id_button=data.res[i][0];
            $("#res_shed").append("<tr>"+
              /*<td width=2><button id="+id_button+" class='pic_button ui-button ui-state-default ui-corner-all' width=1 value="+data.res[i][0]+" title='Посмотреть подробную информацию'>Инф</button></td>"+  */



                                            "<td width=150>"+data.res[i][1]+"</td>"+
							                "<td width=70>"+data.res[i][2]+"</td>"+
									           "<td width=150>"+data.res[i][3]+"</td>"+
									           "<td width=150>"+data.res[i][4]+"</td>"+
									           "<td width=200>"+data.res[i][5]+"</td>");

    id_button="#"+id_button;
   $(id_button).bind('click',function(event) {

                                                id_race=$(this).attr("id");

                                               $("#n_race").attr('value',$(this).attr("id"));

                                              // alert($("#n_race").val());
                                              C_X=event.pageX;
                                              C_Y=event.pageY;
                                             init_dialog();
                                             $('#dialog_race').dialog('open');

                                         }); // end  $(id_button).bind




   }
    //end for
 
   $("#table_races").show();
   $("#back_shed").bind("click",function() {   	$("#back_shed").hide();
                                               $("#table_races").hide();
                                               $("#res_shed").hide();
                                               $("#stations").show();
   								    	    });
              },
    "json" );//end $.post

    }); //end  #go.click
  });
 }) //end  $('#button_general').click
 	.hover(	function(){	$(this).addClass("href-state-hover");},
      function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

//---------------------Точное расписание-----------------------------------------------------------
$('#button_exact').click(function() {
    reset_button();
   $('#message_wait').show();
   $("#message").hide();
   $('#main_place').empty();
   $('#main_place').load("races2.php",{},function(){
   $('#message_wait').hide();
   $('#message_wait2').hide();
   $("#message").hide();
//this.foo1 = function(){ alert('here public function call'); }

//$("#dialog_sale").hide(); //скрыть окно продажи
$("#races").hide(); //
$("#datepicker2").datepicker({
               showOn: 'button',
               buttonImage: 'images/calendar.gif',
               buttonImageOnly: true,
               dateFormat: 'dd.mm.yy',
               maxDate: '+20',
               minDate: '0',
               firstDay: '1',
               dayNamesMin: [ 'Вс','Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
               monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
                           'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь']
               //setDate:'0',

});

$("#datepicker2").datepicker('setDate','0');
$('#selected_st').keypress(function (e)
{
             // alert("$('#selected_st').keypress");
  if(e.which==13) {$('#go2').click();
                  }
});

function init_dialog2()//получение информации о рейсе
{

$('#dialog_race2').dialog({stackfix: true,autoOpen: false,width: 600,modal: true,buttons: {  },//end buttons
  close: function(event, ui){
  $('#dialog_race2').dialog('destroy'); //убили диалог и обработчики и т.п.
  $('#razmetka').remove(); //удалили разметку
  },
  open: function(event, ui) {
    st_disp_val=$("#st_disp option:selected").val();
    st_disp_name=$("#st_disp option:selected").text();
    st_arrive_val = $("#selected_st option:selected").val();
    st_arrive_name=$("#selected_st option:selected").text();
    $("#id1").empty();
    $("#id2").empty();
    $("#id1").hide();
    $("#id2").hide();
    $(".ui-dialog").css("left",C_X);
    $(".ui-dialog").css("top",C_Y);
    $("#race_info2").text("Идет загрузка данных, подождите немного");

    $.post("race_info2.php",{id_race:$("#n_race").val(),st_disp_val:st_disp_val,st_arrive_val:st_arrive_val,kesh:(new Date().getTime())},
      function(data){
        if(data.err==1)
       {
           $("#race_info2").text("Нет информации по выбранному рейсу");

       }else{Race=data.Race;
        $("#race_info2").text("Информация по рейсу :");

        $("#dialog_race2").append("<div id=razmetka>"+
        "<table align=center  border=1 bordercolor=black cellspacing=1 >"+
        "<tbody id=id1 align=center>"+
        "</tbody>"+
        "</table>"+
        "<BR>"+
        "<table align=center  border=1 bordercolor=black cellspacing=1>"+
        "<tbody id=id2 align=center>"+
        "</tbody></table></div>");
       $("#id1").append("<tr><td>АТП</td><td>"+Race.company+"</td></tr>");
       $("#id1").append("<tr><td>Рейс</td><td>"+Race.name+"</td></tr>");
       $("#id1").append("<tr><td>Станция отправления</td><td>"+Race.dispatchStation+"</td></tr>");
       $("#id1").append("<tr><td>Время отправления</td><td>"+Race.dispatchTime+"</td></tr>");
       $("#id1").append("<tr><td>Станция прибытия</td><td>"+Race.arrivalStation+"</td></tr>");
       //$("#id1").append("<tr><td>Время прибытия</td><td>"+Race.arrivalTime+"</td></tr>");
       $("#id1").append("<tr><td>Автобус</td><td>"+Race.busInfo+"</td></tr>");
       $("#id1").append("<tr><td>Тариф полного билета</td><td>"+Race.ticketCost+"</td></tr>");
       //$("#id1").append("<tr><td>Тариф детского билета</td><td>"+Race.childTicketCost +"</td></tr>");
       //$("#id1").append("<tr><td>Тариф багажа</td><td>"+Race.cargoCost+"</td></tr>");
      // $("#id2").append("<tr><td>Ст.Отправл</td><td>Ст.Назн.</td><td>Расстояние</td><td>Тариф</td></tr>");

     /* for (i=0;i<data.size_row_1;i++) {
          $("#id2").append("<tr><td>"+data.res_1[i][0]+"</td><td>"+data.res_1[i][1]+"</td><td>"+data.res_1[i][2]+"</td><td>"+data.res_1[i][3]+"</td></tr>");
       }
              */

   $("#id1").show();
   $("#id2").show();
     }// end  if else
     }, "json");   //end $.post
                        }  //end function  open
			 });//end dialog
} //  end init_dialog


  $('#go2').click(function() {
 date_in=$("#datepicker2");
 st_disp_val=$("#st_disp option:selected").val();
 st_disp_name=$("#st_disp option:selected").text();

 st_arrive_val = $("#selected_st option:selected").val();
 st_arrive_name=$("#selected_st option:selected").text();
  $('#message_wait2').show();
   $("#races").hide();

 $.post("get_races2.php",{date_in:date_in.val(),st_arrive_val:st_arrive_val,st_disp_val:st_disp_val,kesh:(new Date().getTime())},
  function(data)
  {ArrayRaces=data.Races;
   $('#message_wait2').hide();
   try {
  
   $("#res_shed").empty();// очистка слоя  с рейсами
   $("#marshrut").empty();//очистка слоя отображения названия рейса
  		       //	$("#wait_text").hide();
 if (data.err ==1)  throw "Рейсов нет";
 
 $("#marshrut").text(st_disp_name+"-"+st_arrive_name);
 $("#res_shed").append("<tr>           <td width=2>I</td>"+
                                        "<td width=150>Маршрут</td>"+   //1
                                        "<td width=70>Отправление</td>"+   //3
                                        "<td width=80>Тариф</td >"+        //4
                                        "<td width=60>Свободные места</td>"+  //5
                                        /*"<td width=50>Статус</td>"+          //6
                                        "<td width=70>Вместимость автобуса</td >"+ //7
                                         "<td width=130>Перевозчик</td>"+     //8   */
                                       //  "<td width=4>Купить билет</td >\n\
                              "</tr></tr>"); //7
   var id_button,id_sale;

   for(var i=0;i<ArrayRaces.length;i++)
    {
     if (ArrayRaces[i].freePlaceCount<1) continue;
      //обращение к слою res_shed через jquery
    $("#res_shed").append("<tr><td width=2><button id="+ArrayRaces[i].id+
    " class='pic_button ui-button ui-state-default ui-corner-all' width=1 value="+
    ArrayRaces[i].id+" title='Посмотреть подробную информацию'>Инф</button></td>"+
    "<td width=150>"+ArrayRaces[i].name+"</td>"+
    "<td width=70>"+ArrayRaces[i].dispatchTime+"</td>"+
    "<td width=80>"+ArrayRaces[i].ticketCost+"</td>"+
    "<td width=60>"+ArrayRaces[i].freePlaceCount+"</td>"+
    /*"<td width=2><button id="+ArrayRaces[i].id+"-sale"+
    " class='pic_button ui-button ui-state-default ui-corner-all' width=1 value="+
    ArrayRaces[i].id+" title='Купить билет' >Купить билет</button></td>*/
                  "</tr>") ;
   //Обработчик (кнопка получения инф-ии о рейсе)
   $("#"+ArrayRaces[i].id).bind('click',function(event)
    {
      id_race=$(this).attr("value");
      
      $("#n_race").attr('value',id_race);
     // alert($("#n_race").val());
     C_X=event.pageX;
     C_Y=event.pageY-50;
     init_dialog2();
    $('#dialog_race2').dialog('open');

    }); // end  $(id_button).bind    */

   }  //end for
$("#table_races").show();
$("#races").show();
 
}
  catch(e)
  {
    alert ("Подходящие рейсы отсутствуют!Измените параметры поиска!");
    //throw "Конец";
  }

 },
   "json" );//end $.post

    }); //end  #go2.click

$(function(){
        $('#res_shed').selectable({
            filter:'td,th',
            selected: function(event, ui){
              //  console.log(event);
               // console.log(ui);
                var s=$(this).find('.ui-selected');
              //  console.log(s);
            }
        })
    });

  
  });// end load("races2.php")
 })  //end #button_exact
 	.hover(	function(){$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

}); // end $('#main_place').load(
});	 //end $('#href_races')
/*--------------------------Карта-----------------------------------------------------*/
$('#map').click(function() { reset_button();
	$('#message_wait').show();
	$("#id1").show();
    $('#main_place').empty();
     $('#main_place').empty();
     $('#main_place').load("map.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
/*-------------------------------------------------------------------------------*/

  $('#href_info').click(function() {reset_button();
     $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("info.php",{},function(){
      $('#message_wait').hide();
      $('#gallery a').lightBox();

     });
     }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
/*--------------------------новости-----------------------------------------------------*/
  $('#novosti').click(function() { reset_button();
  	 $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("novosti.php",{},function(){ $('#message_wait').hide();

//---------------------------------------------Объявление Ордынка
	$('#adver').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("adver.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
//------------КОНЕЦ---------------------------------Объявление Ордынка
//---------------------------------------------Новые тарифы на услуги
	$('#uslug').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d3.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
     //------------КОНЕЦ---------------------------------Новые тарифы на услуги
 	//---------------------------------------------Конкурс
	$('#conc').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("conc.php",{},function(){$('#message_wait').hide();$('#ph a').lightBox();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
    //--------------КОНЕЦ-------------------------------Конкурс

     }); //end function
     }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});


//---------------------------------------------Объявление Ордынка
	$('#adver').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("adver.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
//------------КОНЕЦ---------------------------------Объявление Ордынка
//---------------------------------------------Конкурс
	$('#conc').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("conc.php",{},function(){$('#message_wait').hide();$('#ph a').lightBox();});
      }) //end

     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

//---------------------------------------------Новые тарифы на услуги
	$('#uslug').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d3.php",{},function(){$('#message_wait').hide();});
      }) //end

     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});


/*--------------------------АВТОБУС картинка КАК ССЫЛКА НА ГЛАВНУЮ страницу сайта
-----------------------------------------------------*/
  $('#tomain').click(function() { reset_button();
  	 $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("novosti.php",{},function(){ $('#message_wait').hide();
	$('#uslug').click(function() { reset_button();
	    $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("d3.php",{},function(){$('#message_wait').hide();});
	      }) //end
	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});
	$('#conc').click(function() { reset_button();
	    $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("conc.php",{},function(){$('#message_wait').hide();$('#ph a').lightBox();});
	      }) //end
	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});
	$('#adver').click(function() { reset_button();
	    $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("adver.php",{},function(){$('#message_wait').hide();});
	      }) //end
	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});
     }); //end function
     }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});


	$('#conc').click(function() { reset_button();
	    $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("conc.php",{},function(){$('#message_wait').hide();$('#ph a').lightBox();});
	      }) //end
	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});

	$('#uslug').click(function() { reset_button();
	    $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("d3.php",{},function(){$('#message_wait').hide();});
	      }) //end

	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});

	$('#adver').click(function() { reset_button();
	    $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("adver.php",{},function(){$('#message_wait').hide();});
	      }) //end
	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});
//-------------- КОНЕЦ ССЫЛКИ НА ГЛАВНУЮ-------------------------------

/*--------------------------нормативные документы-----------------------------------------------------*/
  $('#href_norm_doc').click(function() { reset_button();
  		$('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("norm.php",{ },function(){
 /*--------------------------нормативные документы d0-----------------------------------------------------*/
    $('#d0').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d0.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
 /*--------------------------нормативные документы d1-----------------------------------------------------*/
     $('#message_wait').hide();
     $('#d1').click(function() {   reset_button();
     $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d1.php",{},function(){
         $('#message_wait').hide();
	     $('#d1p').click(function() {  reset_button();
	     $('#message_wait').show();
	     $('#main_place').empty();
	     $('#main_place').load("d1p.php",{},function(){$('#message_wait').hide();});
	      }) //end
	     .hover(function(){	$(this).addClass("href-state-hover");},
	 	        function(){$(this).removeClass("href-state-hover");})
	    .mousedown(function(){$(this).addClass("href-state-active");})
		.mouseup(function(){$(this).removeClass("href-state-active");});

     });//end  $('#main_place').load("d1.php",{},function(){
      }) //end $('#d1').click(function() {
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
/*--------------------------нормативные документы d2-----------------------------------------------------*/
    $('#d2').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d2.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

/*--------------------------нормативные документы d3-----------------------------------------------------*/
     $('#d3').click(function() { reset_button();
     $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d3.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
/*--------------------------нормативные документы d4-----------------------------------------------------*/
    $('#d4').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d4.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
/*--------------------------нормативные документы d5-----------------------------------------------------*/
    $('#d5').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d5.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});
/*--------------------------нормативные документы d6-----------------------------------------------------*/
    $('#d6').click(function() { reset_button();
    $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d6.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

      });    //end function


     }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

/*--------------------------Услуги-----------------------------------------------------*/
 $('#href_uslugi').click(function() {  reset_button();
 	 $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("d3.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});

/*--------------------------БРОНИВАРОНИЕ-----------------------------------------------------*/
 $('#href_armor').click(function() {  reset_button();
 	 $('#message_wait').show();
     $('#main_place').empty();
     $('#main_place').load("armor.php",{},function(){$('#message_wait').hide();});
      }) //end
     .hover(function(){	$(this).addClass("href-state-hover");},
 	        function(){$(this).removeClass("href-state-hover");})
    .mousedown(function(){$(this).addClass("href-state-active");})
	.mouseup(function(){$(this).removeClass("href-state-active");});


/*--------------------------Группы кнопок-----------------------------------------------------*/
  var src0,src1,src2,id_im='',src_im='', was_click1,was_click2,was_click3,was_click4,was_click5,was_click6,was_click7,was_click8,was_click9;

 var src12='images/but12.jpg',
  src11='images/but11.jpg',

  src22='images/but22.jpg',
  src21='images/but21.jpg',

  src32='images/but32.jpg',
  src31='images/but31.jpg',

  src42='images/but42.jpg',
  src41='images/but41.jpg',

  src52='images/but52.jpg',
  src51='images/but51.jpg',

  src62='images/but62.jpg',
  src61='images/but61.jpg',

  src72='images/but72.jpg',
  src71='images/but71.jpg',

  src82='images/but82.jpg',
  src81='images/but81.jpg';

  src92='images/nav2.png',
  src91='images/nav1.png';



  function reset_button() {
  		$('#but1').attr({ src:src11});
  		$('#but2').attr({ src:src21});
  		$('#but3').attr({ src:src31});
  		$('#but4').attr({ src:src41});
  		$('#but5').attr({ src:src51});
  		$('#but6').attr({ src:src61});
  		$('#but7').attr({ src:src71});
		$('#but8').attr({ src:src81});
		$('#navbut').attr({ src:src91});
	    was_click1=0;
	    was_click2=0;
	    was_click3=0;
	    was_click4=0;
	    was_click5=0;
	    was_click6=0;
	    was_click7=0;
	    was_click8=0;
	    was_click9=0;
  }
  $('#but1').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("b_times.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src12});
            },function(){
                          if (!was_click1){
            	                           $(this).attr({ src :src11});
            	                         }
        	         })
         .mousedown(function(){reset_button(); was_click1=1; $(this).attr({ src :src12});})
         .mouseup(function(){reset_button(); was_click1=1;$(this).attr({ src :src12});});

  $('#but2').click(function(){ // Change the input image's source when we "roll on"
                $('#message_wait').show();
                $('#main_place').empty();

                $('#main_place').load("b_bugs.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src22});
            },function(){
                          if (!was_click2){
            	                           $(this).attr({ src :src21});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click2=1;$(this).attr({ src :src22});})
         .mouseup(function(){reset_button();was_click2=1;$(this).attr({ src :src22});});

$('#but3').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("b_child.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src32});
            },function(){
                          if (!was_click3){
            	                           $(this).attr({ src :src31});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click3=1;$(this).attr({ src :src32});})
         .mouseup(function(){reset_button();was_click3=1;$(this).attr({ src :src32});});

$('#but4').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                 $('#message_wait').show();
                $('#main_place').load("b_lgot.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src42});
            },function(){
                          if (!was_click4){
            	                           $(this).attr({ src :src41});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click4=1;$(this).attr({ src :src42});})
         .mouseup(function(){reset_button();was_click4=1;$(this).attr({ src :src42});});

$('#but5').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("b_back.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src52});
            },function(){
                          if (!was_click5){
            	                           $(this).attr({ src :src51});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click5=1;$(this).attr({ src :src52});})
         .mouseup(function(){reset_button();was_click5=1;$(this).attr({ src :src52});});
$('#but6').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("b_univers.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src62});
            },function(){
                          if (!was_click6){
            	                           $(this).attr({ src :src61});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click6=1;$(this).attr({ src :src62});})
         .mouseup(function(){reset_button();was_click6=1;$(this).attr({ src :src62});});
$('#but7').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("b_store.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src72});
            },function(){
                          if (!was_click7){
            	                           $(this).attr({ src :src71});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click7=1;$(this).attr({ src :src72});})
         .mouseup(function(){reset_button();was_click7=1;$(this).attr({ src :src72});});
$('#but8').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("b_how_to_go.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src82});
            },function(){
                          if (!was_click8){
            	                           $(this).attr({ src :src81});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click8=1;$(this).attr({ src :src82});})
         .mouseup(function(){reset_button();was_click8=1;$(this).attr({ src :src82});});

$('#navbut').click(function(){ // Change the input image's source when we "roll on"
                $('#main_place').empty();
                $('#message_wait').show();
                $('#main_place').load("navi.php",{},function(){$('#message_wait').hide();});

            })
         .hover(function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src :src92});
            },function(){
                          if (!was_click9){
            	                           $(this).attr({ src :src91});
            	                          }
           	         })
         .mousedown(function(){reset_button();was_click9=1;$(this).attr({ src :src92});})
         .mouseup(function(){reset_button();was_click9=1;$(this).attr({ src :src92});});


});  // end $(function()



