$(document).ready(function() {
  
  var container = $('.tabs-container');
  container.each(function() {
    var container = $(this);
    var controls = $('.tabs-controls', container);
    var activeId = controls.find('.cur a').attr('href');
	controls.find('a').click(function() {
      var clickedId = $(this).attr('href');

	  //alert(controls.find('a').eq(2).text());
      
      if (activeId != clickedId) {
	  //alert($(this).attr('href'));
	   
        $('#in_88888').load('index_ajax1.php');
      	$('#sin_88888').load('index_ajax1.php?spec=1'); 


        $('#in_3').load('index_ajax2.php?pid=krasnodar');
      	$('#sin_3').load('index_ajax2.php?spec=1&pid=krasnodar');

	$('#in_34').load('index_ajax2.php?pid=rostov');
      	$('#sin_34').load('index_ajax2.php?spec=1&pid=rostov');

        if($(this).attr('href')=='http://www.avto25.ru/catalog/kmv/') {
                window.document.location.href = "http://www.avto25.ru/catalog/kmv/";
        }
        if($(this).attr('href')=='http://www.avto25.ru/catalog/stavropolskiy_kray/') {
                window.document.location.href = "http://www.avto25.ru/catalog/stavropolskiy_kray/";
        }
        if($(this).attr('href')=='http://www.avto25.ru/catalog/krasnodarskiy_kray/') {
                window.document.location.href = "http://www.avto25.ru/catalog/krasnodarskiy_kray/";
        }
        if($(this).attr('href')=='http://www.avto25.ru/catalog/rostovskay_oblast/') {
                window.document.location.href = "http://www.avto25.ru/catalog/rostovskay_oblast/";
        }
		
		  
	activeId = $(this).attr('href');
        container.find('.tabs-data.cur,.tabs-controls .cur').removeClass('cur');
        $(this).parent().addClass('cur');
        container.find(activeId).addClass('cur');
		
        if($(this).attr('href')=='#kmv') {
                $(this).attr('href', 'http://www.avto25.ru/catalog/kmv/');
                controls.find('a').eq(2).attr('href', '#krasnodar');
                controls.find('a').eq(1).attr('href', '#stavropol');
                controls.find('a').eq(3).attr('href', '#rostov');

                controls.find('a').eq(2).addClass('pseudo-link');
                controls.find('a').eq(1).addClass('pseudo-link');
                controls.find('a').eq(3).addClass('pseudo-link');
         }
        if($(this).attr('href')=='#stavropol') {
                $(this).attr('href', 'http://www.avto25.ru/catalog/stavropolskiy_kray/');
                controls.find('a').eq(0).attr('href', '#kmv');
                controls.find('a').eq(2).attr('href', '#krasnodar');
                controls.find('a').eq(3).attr('href', '#rostov');

                controls.find('a').eq(0).addClass('pseudo-link');
                controls.find('a').eq(2).addClass('pseudo-link');
                controls.find('a').eq(3).addClass('pseudo-link');
         }
        if($(this).attr('href')=='#krasnodar') {
                $(this).attr('href', 'http://www.avto25.ru/catalog/krasnodarskiy_kray/');

                controls.find('a').eq(0).attr('href', '#kmv');
                controls.find('a').eq(1).attr('href', '#stavropol');
                controls.find('a').eq(3).attr('href', '#rostov');

                controls.find('a').eq(0).addClass('pseudo-link');
                controls.find('a').eq(1).addClass('pseudo-link');
                controls.find('a').eq(3).addClass('pseudo-link');

         }
         if($(this).attr('href')=='#rostov') {
                $(this).attr('href', 'http://www.avto25.ru/catalog/rostovskay_oblast/');
                controls.find('a').eq(0).attr('href', '#kmv');
                controls.find('a').eq(1).attr('href', '#stavropol');
                controls.find('a').eq(2).attr('href', '#krasnodar');

                controls.find('a').eq(0).addClass('pseudo-link');
                controls.find('a').eq(1).addClass('pseudo-link');
                controls.find('a').eq(2).addClass('pseudo-link');
         }
                $(this).removeClass('pseudo-link');
      };
	  
      return false;
    }
	);
  });
});

