$(document).ready(function(){
 
// init cache
$.Tache.SetTimeout(1);
//$.Tache.SetTimeout(110);


//fck img align trick
$('p > img').each(function(){
  if ($(this).attr('hspace') == 10)
  {
   $(this).addClass('fl-left').css({'margin-right':'10px'}); 
  }
});

// init calendar
$.listen('mouseover', '#input_date', function(){
  $($.date_input.initialize);
  var lang = $('div.current_lang').attr('id');
  if (lang == 'ru')
  {
   $.extend(DateInput.DEFAULT_OPTS, {
      month_names: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
      short_month_names: ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
      short_day_names: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"]
    });
  }
  else if (lang == 'de')
  {
   $.extend(DateInput.DEFAULT_OPTS, {
      month_names: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
      short_month_names: ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
      short_day_names: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"]
    });
  }
  else
  {
   $.extend(DateInput.DEFAULT_OPTS, {
      month_names: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
      short_month_names: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
      short_day_names: ["Sn", "Mn", "Tu", "Wd", "Th", "Fr", "St"]
    });
  }
  
  $.extend(DateInput.DEFAULT_OPTS, {
  stringToDate: function(string) {
    var matches;
    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
      return new Date(matches[1], matches[2] - 1, matches[3]);
    } else {
      return null;
    };
  },

  dateToString: function(date) {
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return date.getFullYear() + "-" + month + "-" + dom;
  }
});
$("#input_date").date_input();
});

//captcha
$.listen('click', 'img.captcha_reload', function(){
  var uri = $(this).attr('id');
  $.ajax({
       type: 'POST',
       cache: false,
       url: uri,
       dataType: 'html',
       data: '',
       ajaxSend : function() { },
       success: function(response){
        var target = $('td#captcha_td');
        target.html(response);
      }
     });
});

//init www visits cpint
$('a#company_link').click(function(){
  //var lang = $('div#current_lang').text();
  var id = $(this).attr('rel');
  $.ajax({
       type: 'POST',
       cache: false,
       url: '/company/linker/'+id,
       dataType: 'html',
       data: 'company_id='+id,
       ajaxSend : function() { },
       success: function(response){
      }
     }); 
});

// btn effects
$.listen('mouseover', '.hd2-tab-gs, .btn, .button-cat-top, .button-cat-middle, .button-cat-bottom, .button-cat-alone, .button-cat-bottom-exp', function(){
  if (!$.browser.msie) { $(this).fadeTo('fast', 0.50); }
});
$.listen('mouseout', '.hd2-tab-gs, .btn, .button-cat-top, .button-cat-middle, .button-cat-bottom, .button-cat-alone, .button-cat-bottom-exp', function(){
  if (!$.browser.msie) { $(this).fadeTo('fast', 1.0); }
});

// translation order confirm
$.listen('click', 'div.order_button', function(){
  var order_box = $('div#'+$(this).attr('rel'));
  if ($(this).hasClass('order_deny')) { order_box.fadeOut('fast'); } else { order_box.fadeIn('fast'); }  
   
    
});


// exp
if ($('.expandable')) {
$('.expandable').click(
  function()
  {
   var sp = $('div#'+$(this).attr('rel')); 
   if ($(this).hasClass('button-generic-bottom-exp'))
   {
    $(this).removeClass('button-generic-bottom-exp');
    $(this).addClass('button-generic-bottom-coll');
    sp.slideDown('slow');
   }
   else
   {
    $(this).removeClass('button-generic-bottom-coll');
    $(this).toggleClass('button-generic-bottom-exp');
    sp.slideUp('slow');
   }
  });
}


//preview
$.listen('mouseover', 'a.preview', function(){
  $('a.preview').lightBox({
    imageLoading: '/resources/images/lightbox/lightbox-ico-loading.gif',
  	imageBtnClose: '/resources/images/lightbox/lightbox-btn-close.gif',
	  imageBtnPrev: '/resources/images/lightbox/lightbox-btn-prev.gif',
	  imageBtnNext: '/resources/images/lightbox/lightbox-btn-next.gif',
	  txtImage: '',
  	txtOf: '<>'
  });        
});

$('#country').change(function(){
    var country_id = '';
    country_id = $('#country option:selected').val();
    if (country_id != '') 
    { 
     $('div#regions').addClass('loading').html(' ');
     $.ajax({
       type: 'POST',
       cache: true,
       url: '/'+$('div#current_lang').text()+'/register/regions/'+country_id,
       dataType: 'html',
       data: '',
       ajaxSend : function() { },
       success: function(response){
       $('div#regions').removeClass('loading');
       $('div#regions').html(response);
       $('div#regions').fadeIn('fast');
      }
     });
    } 
  });

// init user forms
$.listen('click', '#user_save', function(){
    
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    $('#user_form').ajaxSubmit({ 
    target: '#user_preferences',
    type: 'post', 
    success: function() { 
        $('#user_options_load').hide();
        $('#user_preferences').fadeTo('fast', 1.0);
        return false; 
    } 
   }); 
});
$.listen('click', '#userkw_save', function(){
    
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    $('#users_form').ajaxSubmit({ 
    target: '#user_preferences',
    type: 'post', 
    success: function() { 
        $('#user_options_load').hide();
        $('#user_preferences').fadeTo('fast', 1.0);
        return false; 
    } 
   }); 
});

$.listen('click', '#user_save2', function(){
    
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    $('#user_form2').ajaxSubmit({ 
    target: '#user_preferences',
    type: 'post', 
    success: function() { 
        $('#user_options_load').hide();
        $('#user_preferences').fadeTo('fast', 1.0);
        return false; 
    } 
   }); 
});

$.listen('click', '#user_save3', function(){
    
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    $('#user_form3').ajaxSubmit({ 
    target: '#user_preferences',
    type: 'post', 
    success: function() { 
        $('#user_options_load').hide();
        $('#user_preferences').fadeTo('fast', 1.0);
        return false; 
    } 
   }); 
});

$.listen('click', '#user_reg', function(){
    
    $('#user_options_load').fadeIn();
    $('#user_reg_form').ajaxSubmit({ 
    target: '#error',
    type: 'post', 
    success: showResponse
   }); 
});

function showResponse(responseText)
{
  $('#user_options_load').fadeOut();
  if (responseText == '.') 
  { 
   var lang = $('div#lang').attr('rel');
   doSend('/'+lang+'/register/complete', '', $('div#main'), 1, null, site);
   document.location.href='/'+lang+'/user';
  }
  return false;
}

$.listen('click', '#user_cf', function(){
    
    $('#user_options_load').fadeIn();
    $('#user_cf_form').ajaxSubmit({ 
    target: '#error',
    type: 'post', 
    success: showResponse2
   }); 
});

function showResponse2(responseText)
{
  $('#user_options_load').fadeOut();
  if (responseText == '.') 
  { 
   var lang = $('div#lang').attr('rel');
   doSend('/'+lang+'/contact/complete', '', $('div#main'), 1, null, site);
  }
  return false;
}

$.listen('click', '#user_res', function(){
    
    $('#user_options_load').fadeIn();
    $('#user_res_form').ajaxSubmit({ 
    target: '#error',
    type: 'post', 
    success: showResponse3
   }); 
});

function showResponse3(responseText)
{
  $('#user_options_load').fadeOut();
  if (responseText == '.') 
  { 
   var lang = $('div#lang').attr('rel');
   doSend('/'+lang+'/restore/complete', '', $('div#main'), 1, null, site);
  }
  return false;
}


/*

*/

$.listen('click', '.button-new', function(){
    document.location.href=$(this).attr('id');
  });
   
// init user prefs
if ($('#user_prefs_options')) {
  $.listen('click', '.user_pr', function(){
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    doSend('/ajax_user/user/show/'+$(this).attr('id')+'/'+$('.current_lang').attr('id'), '', $('#user_preferences'), 1, $('#user_options_load'), site);
    
  });
  $.listen('click', '.user_del', function(){
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    doSend('/ajax_user/user/delete/'+$(this).attr('id')+'/'+$('.current_lang').attr('id'), '', $('#user_preferences'), 1, $('#user_options_load'), site);
    
  });
  $.listen('click', '.user_edit', function(){
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    doSend('/ajax_user/user/edit/'+$(this).attr('id')+'/'+$('.current_lang').attr('id'), '', $('#user_preferences'), 1, $('#user_options_load'), site);
    
  });
  $.listen('click', '.user_pr2', function(){
    if ($(this).attr('id') != 'none') {
    $('#user_options_load').fadeIn(); $('#user_preferences').fadeTo('fast', 0.4);
    doSend($(this).attr('id'), '', $('#user_preferences'), 1, $('#user_options_load'), site);
   }
  });
    
  $.listen('click', '.user_del2', function(){
      var id_ = $(this).attr('id'); var rel_ = $(this).attr('rel');
      var lang = $('div.current_lang').attr('id');
      if (lang == 'ru') { var title = 'Внимание!'; var msg = '<center>Это действие нельзя будет отменить.<br />Вы хорошо подумали?</center><br /><br /><div><div id="'+id_+'" rel="'+rel_+'" class="ctrl user_del2_confirmed" style="width: 50px; float: left; margin-right: 10px; margin-left: 136px" title="">Да</div><div id="none" class="ctrl user_del2_canceled" style="width: 50px; float: left;">Нет</div></div><br /><br />'; }
      else if (lang == 'de') { var title = 'Внимание!'; var msg = '<center>Это действие нельзя будет отменить.<br />Вы хорошо подумали?</center><br /><br /><div><div id="'+id_+'" rel="'+rel_+'" class="ctrl user_del2_confirmed" style="width: 50px; float: left; margin-right: 10px; margin-left: 136px" title="">Да</div><div id="none" class="ctrl user_del2_canceled" style="width: 50px; float: left;">Нет</div></div><br /><br />'; }
      else { var title = 'Attention!'; var msg = '<center>This action cannot be reversed. All data will be lost.<br />Are you sure?</center><br /><br /><div><div id="'+id_+'" rel="'+rel_+'" class="ctrl user_del2_confirmed" style="width: 50px; float: left; margin-right: 10px; margin-left: 136px" title="">Yes</div><div id="none" class="ctrl user_del2_canceled" style="width: 50px; float: left;">No</div></div><br /><br />'; }
      $.popup.show(title, msg);
  });
  $.listen('click', '.user_del2_confirmed', function(){
    $('#popup_close').trigger('click');
    $('#user_options_load').fadeIn('fast'); $('#user_preferences').fadeTo('fast', 0.4);
    doSend($(this).attr('id'), 'action=remove&verify='+$(this).attr('rel'), $('#user_preferences'), 1, $('#user_options_load'), site);
  });
  $.listen('click', '.user_del2_canceled', function(){
      $('#popup_close').trigger('click');
  });
  
  
  $.listen('click', '.admin-fck', function(){
    $('#admin_options_load').fadeIn('fast'); $('#admin_preferences').fadeTo('fast', 0.4);
    $('#fck-container').html('<input type="hidden" id="params" name="params" value="'+$(this).attr('id')+'" /><textarea class="in-text3" style="width: 600px; height: 100px" id="rte" name="rte"></textarea>'); $('div#admin_submit').hide();
    $.ajax({ url: $(this).attr('id'), type: 'POST', dataType: 'html', data: '', cache: false, async: false, success: function(msg) { 
        $('textarea#rte').append(document.createTextNode(msg)); 
        
        $(function(){ $('textarea#rte').fck({path: '/resources/js/fckeditor/',height:440,toolbar:'HARIS'}); });
        $('#admin_options_load').fadeOut('fast'); $('#admin_preferences').fadeTo('fast', 1.0); $('div#admin_submit').show(); }});
  });
  $.listen('click', 'div#fck_int', function(){
    $('#admin_options_load').fadeIn('fast'); $('#admin_preferences').fadeTo('fast', 0.4); var at = $(this).attr('rel');
    $(function(){ $('textarea#'+at).fck({path: '/resources/js/fckeditor/',height:440,toolbar:'MDV'}); });
    $('#admin_options_load').fadeOut('fast'); $('#admin_preferences').fadeTo('fast', 1.0); $(this).fadeOut('fast');     
        
  });
  
  // subcat
  if ($.browser.msie) { var ev = 'click'; } else { var ev = 'change'; }
  
   $.listen(ev, '#level_01', function(){
    var level1_id = $('#level_01 option:selected').val();
    if (level1_id > 0) 
    { 
     $('div#list_level_03').html('');
     $('#user_options_load').fadeIn('fast'); $('#user_preferences').fadeTo('fast', 0.4); 
     doSend('/ajax_user/user/show_special/cat_level_02-'+level1_id+'/'+$('.current_lang').attr('id'), '', $('div#list_level_02'), 1, $('#user_options_load'), site); 
    } 
  });
  $.listen(ev, '#level_02', function(){
    var level2_id = $('#level_02 option:selected').val();
    if (level2_id > 0) 
    { 
     $('#user_options_load').fadeIn('fast'); $('#user_preferences').fadeTo('fast', 0.4); 
     doSend('/ajax_user/user/show_special/cat_level_03-'+level2_id+'/'+$('.current_lang').attr('id'), '', $('div#list_level_03'), 1, $('#user_options_load'), site); 
    } 
  });
  $.listen(ev, '#country', function(){
    var country_id = $('#country option:selected').val();
    if (country_id > 0) 
    { 
     $('#user_options_load').fadeIn('fast'); $('#user_preferences').fadeTo('fast', 0.4); 
     doSend('/ajax_user/user/show_special/regions-'+country_id+'/'+$('.current_lang').attr('id'), '', $('div#regions'), 1, $('#user_options_load'), site); 
    } 
  });
  
  
  
  
} 


// init the menu
if ($.cookie('init1') == null) { $.cookie('init1', '100', {path:'/'}); }

// init pager & nav styles
$('div#pager a').addClass('link-1'); $('div#pager2 a').addClass('link-1');
$('div#nav a').addClass('link-1');
$('#btn_home2').mouseover(function(){
$(this).show();
});

// init tooltip
$('a.ttt').tooltip({ 
    position: ['top', 'center'],
    offset: [41, 10], 
    effect: 'fade', 
    
    delay: 30 
});

//init carousel
if ($('div.scrollable'))
{
$.easing.custom = function (x, t, b, c, d) { 
    var s = 1.70158;  
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; }
$('div.scrollable').scrollable({ 
    next: 'div.less', 
    prev: 'div.more',
    size: 3,
    easing: 'custom', 
    speed: 700
});
}

// init country select
if ($('div.comboboxValueContainer2')) { 
$('div.comboboxValueContainer2').click(function(){
  var pos = $('#all_countries').position();
  var c = $('#countries_id');
  c.fadeIn('slow').css('z-index', '4000');
  c.css('left', pos.left-630);
  c.css('top', pos.top);
  //$('body:not(#countries_main)').click(function(){ c.fadeOut('slow'); });
  return false;
});

$('*').keypress(function(){ 
$('#countries_id').fadeOut('slow'); 
});

// init basket_counter
if ($('.add_to_basket')) {
$('.add_to_basket').click(function(){
  var item_id = $(this).attr('title');
  //doSend('/ajax/basket_add/'+item_id, 'get=basket', $('#basket_counter'), 1, null);
  $.post('/ajax/basket_add/'+item_id, { get: 'basket' },
  function(data){
    $('#basket_counter').html(data);
  });
  $('#atb_wrapper').fadeOut('slow');
  if ($(this).hasClass('add_here')) { $('.box_'+item_id).fadeOut('slow'); }
  return false;
});
}

$('#prod_all').click(function(){
  if ($(this).attr('checked')) { $('.minor_checkboxes').attr('checked', 'checked'); }
  else { $('.minor_checkboxes').removeAttr('checked'); }
});


// init basket controls
/*if ($('td.tds span')) {
  $('td.tds span').click(function(){
  if ($(this).attr('title') == 'm') 
  { 
   var c_id = $(this).attr('id'); var c_name = $(this).attr('alt');
   $('#send_area').fadeOut('fast').fadeIn('slow'); 
   $('input#to').val(c_name);
   $('input#where_to').val(c_id); 
  }
  //doSend('/ajax/basket_check', 'get=basket', $('#basket_counter'), 1);
});
}*/

// init checks
$('#select_all_countries').click(function(){
  $('#countries_main :checkbox').attr('checked', 'checked');  
  return false;
});
$('#clear_countries_list').click(function(){
  $('#countries_main :checkbox').attr('checked', '');  
  return false;
});

$('#accept_countries').click(function(){
  $('#countries_id').fadeOut('slow');  
  return false;
});

}

var site = $('div#nav_rack').attr('rel');
if (site != '') { site = site+'/'; }

// init buttons
$('.hd2-btn, .hd2-btn-magazines').mouseover(function(){
  var img = 'middle'; 
  if ($(this).hasClass('hd2-btn-rt')) { img = 'right'; }
  if ($(this).hasClass('hd2-btn-lf')) { img = 'left'; }
  $(this).css({'background':'url(/resources/images/'+site+'hd-'+img+'-2.png)'});
});
$('.hd2-btn, .hd2-btn-magazines').mouseout(function(){
  var img = 'middle';
  if ($(this).hasClass('hd2-btn-rt')) { img = 'right'; }
  if ($(this).hasClass('hd2-btn-lf')) { img = 'left'; }
  if ((!$(this).hasClass('hd2-btn-pressed')) && (!$(this).hasClass('hd2-btn-pressed-lf'))&& (!$(this).hasClass('hd2-btn-pressed-magazines')) && (!$(this).hasClass('hd2-btn-pressed-lf-magazines')) && (!$(this).hasClass('hd2-btn-pressed-rt-magazines'))) 
  { 
   $(this).css({'background':'url(/resources/images/'+site+'hd-'+img+'-1.png)'}); 
  }
});

$('#lang_ru').mouseover(function() { $(this).attr('src', '/resources/images/'+site+'hd-ru-2.png'); });
if ($('#lang_ru').attr('src') != '/resources/images/'+site+'hd-ru-2.png') {$('#lang_ru').mouseout(function() { $(this).attr('src', '/resources/images/'+site+'hd-ru-1.png'); } ); }
$('#lang_en').mouseover(function() { $(this).attr('src', '/resources/images/'+site+'hd-en-2.png'); });
if ($('#lang_en').attr('src') != '/resources/images/'+site+'hd-en-2.png') {$('#lang_en').mouseout(function() { $(this).attr('src', '/resources/images/'+site+'hd-en-1.png'); } ); }
$('#lang_de').mouseover(function() { $(this).attr('src', '/resources/images/'+site+'hd-de-2.png'); });
if ($('#lang_de').attr('src') != '/resources/images/'+site+'hd-de-2.png') {$('#lang_de').mouseout(function() { $(this).attr('src', '/resources/images/'+site+'hd-de-1.png'); } ); }

// init search styling
if ($('#category_id')) {
$('#category_id,').combobox( 
{ 
 comboboxContainerClass: "comboboxContainer", 
 comboboxValueContainerClass: "comboboxValueContainer", 
 comboboxValueContentClass: "comboboxValueContent", 
 comboboxDropDownClass: "comboboxDropDownContainer", 
 comboboxDropDownButtonClass: "comboboxDropDownButton", 
 comboboxDropDownItemClass: "comboboxItem", 
 comboboxDropDownItemHoverClass: "comboboxItemHover", 
 comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", 
 comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", 
 animationType: "fade", width: "164px" 
 }); }

if ($('#cat_list')) {
doSend('/ajax/show_categories/'+$.cookie('init1'), 'get=cat1&lang='+$('#current_lang').text()+'&site='+site, $('#cat_list'), 1, $("#cat_load"), site);
}

// show the whole list of categories
/* if ($('#cat-expand-button')) {
$('#cat-expand-button').click(
  function()
  {
   var entries;
   if ($(this).hasClass('button-cat-bottom-exp'))
   {
    entries = 100; $.cookie('init1', '100', {path:'/'});
    $(this).removeClass('button-cat-bottom-exp');
    $(this).addClass('button-cat-bottom-coll');
   }
   else
   {
    entries = 100; $.cookie('init1', '100', {path:'/'});
    $(this).removeClass('button-cat-bottom-coll');
    $(this).toggleClass('button-cat-bottom-exp');
    $.cookie('init1', '100', {path:'/'});
   }
   doSend('/ajax/show_categories/'+entries, 'get=cat1&lang='+$('#current_lang').text(), $('#cat_list'), 1, null);
   $("#cat_list").append($("#cat_load"));
   $("#cat_load").show();
   return false;
  });
} */
  
/*if ($('#search-expand-button')) {
$('#search-expand-button').click(
  function()
  {
   if ($(this).hasClass('button-generic-bottom-exp'))
   {
    $(this).removeClass('button-generic-bottom-exp');
    $(this).addClass('button-generic-bottom-coll');
    $('#x_list').slideDown('slow');
   }
   else
   {
    $(this).removeClass('button-generic-bottom-coll');
    $(this).toggleClass('button-generic-bottom-exp');
    $('#x_list').slideUp('slow');
   }
  });
} */
 
}); 

// --------------------------------------------------------------------------------------------------
          
// ajax routines
function doSend(url, data, target, level, progress_bar, site)
 {
  $.Tache.Get({
       type: 'POST',
       cache: true,
       url: url,
       dataType: 'html',
       data: data,
       ajaxSend : function() { },
       success: function(response){
       if (response == 'User ID missing. Please log in again.') { document.location.href='/'; }
       target.hide();
       target.html(response);
       target.fadeIn('fast'); $('#user_preferences').fadeTo('fast', 1.0);
       if (level == 1) {
         if (progress_bar != null) {
         progress_bar.hide();
         }
         $("#cat_list_container").append($("#cat_load"));
         expandMenu(site);
         // call the latest opened level2 menu (if any)
         $('#'+$.cookie('init2')).trigger('click');
         }
       else if (level == 2) {
         expandFinal(site);
		     // call the latest opened level3 menu (if any)
         $('#'+$.cookie('init3')).trigger('click');
       }
       else {
          
       }  
                  	      
      }
    });
 }
 
/*function doSend2(url, data, target, progress_bar)
{
  $.ajax({
       type: 'POST',
       cache: true,
       url: url,
       dataType: 'html',
       data: data,
       ajaxSend : function() { },
       success: function(response){
       target.html(response);
       if (progress_bar != null) {
         progress_bar.fadeOut('fast'); $('#user_preferences').fadeTo('fast', 1.0);
         }
      }
   });
} */

function expandMenu(site)
{
    
       $('#cat_list h3').click(function(){
	     $(this).next('p').html('<div id="level2"><div id="cat_load" class="loading"></div></div>').toggle().siblings('p:visible').slideUp('fast').empty();
         if ($.cookie('init2') != null) { $.cookie('init2', null, {path:'/'}) }
         $.cookie('init2', $(this).attr('id'), {path:'/'});
                  
         //$.post('/ajax/show_categories/5', {get: 'cat2', 'pid': $(this).attr('id')}, function(data){
		     //$('#level2').html(''+data);
		     
		     doSend('/ajax/show_categories/5', 'get=cat2&pid='+$(this).attr('id')+'&lang='+$('#current_lang').text()+'&site='+site, $('#level2'), 2, $('#cat_load'), site);
		    
		     
   });  
}
           
function expandFinal(site)
{
$('#level2 div').hide();
$('#level2 h2.valid').click(function(){
          $(this).next('div').html('<div id="level3"><div id="cat_load" class="loading"></div></div>').toggle().siblings('div:visible').slideUp('fast').empty();
          if ($.cookie('init3') != null) { $.cookie('init3', null, {path:'/'}) }
          $.cookie('init3', $(this).attr('id'), {path:'/'});
          //$.post('/ajax/show_categories/1', {get: 'cat3', 'pid': $(this).attr('id')}, function(data){
		      //$('#level3').html(''+data);
          //});
          doSend('/ajax/show_categories/1', 'get=cat3&pid='+$(this).attr('id')+'&lang='+$('#current_lang').text()+'&site='+site, $('#level3'), 3, $('#cat_load'), site);
          
   });
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
    return sa ? s : s[0];
}
