
function shMenuLeftClass(id_site,lm_extern_time){

  var lm_time;
  var checksum;
  var js_cookie_support;
  var obj_cookie;
  var cookie_name='LMGUBKIN';
  var max_sites = 3;
  var str_triades;
  var blank = id_site + '_' + 0 + '_' + lm_extern_time + ';';
  var max_power = 50;


  //---------------------------------------------------
  // Procedures of process line with triades
  //---------------------------------------------------

  // Accessuares procedures
  function str_replace(str,pos,length,what){

   return str.substr(0,pos) + what + str.substr(pos+length);
  }


  // This procedure prepare str_triades to 
  function triades_change(){

    obj_cookie = new shCookieClass();
    js_cookie_support = obj_cookie.jsCookieSupport;
    if(!js_cookie_support){ // if cookie is disabled to do return
       return; 
    }
    
    str_triades = obj_cookie.getCookie(cookie_name);
    //alert('triades_change (str_triades):' + str_triades);
    
    if(str_triades == null || str_triades == ''){
      // if cookie not exists or if there are no triades.
      str_triades = blank;
      set_params();
      return;
    }

    if( str_triades.indexOf(id_site) == 0){ 
      // if required triade on the forward position
      // We use this triade 
      set_params();
      return;
    };

    var pos_start_triade = str_triades.indexOf(';' + id_site + '_');
    var pos_end_triade,triade,len_triade;
   

    if( pos_start_triade > 0){
      // if required triade not on the forward position.
      // We must replace found triade to the start position.
      pos_start_triade++;
      pos_end_triade = str_triades.indexOf(';',pos_start_triade);
      if(pos_end_triade == -1){
        str_triades = str_triades + ';';
        pos_end_triade = str_triades.length;
      }
      len_triade = pos_end_triade - pos_start_triade + 1;
      triade = str_triades.substr(pos_start_triade,len_triade);
      str_triades = str_replace(str_triades,pos_start_triade,len_triade,'');
      str_triades = str_replace(str_triades,0,0,triade);
      set_params();
      return;
    }
    
    if(str_triades.indexOf(';' + id_site + '_') == -1){
      // if required triade does not exist
      // We must create this triade on the forward position

      // Count number of sites
      var p = -1;
      for( i = 0 ;i < max_sites - 1; i++ ){
        // i - number of existing triades (number of sites).
        p = str_triades.indexOf(';',p + 1);
        if(p == -1){ break;};
      }

      if( i == max_sites - 1){
        // In this case last triade must be deleted 
        str_triades = str_triades.substr(0,p + 1);
      }

      // New triade must be inserted on the forward position.
      str_triades = str_replace(str_triades,0,0, blank);
      set_params();
      return;
    }
  }
  this.triades_change = triades_change;  

  // Get checksum from first triade
  function get_checksum(){

    //alert('get_checksum triade:' + str_triades);
    var p1 = str_triades.indexOf('_');
    if(p1 == -1){ str_triades = blank;return 0;};
    var p2 = str_triades.indexOf('_',p1 + 1);
    if(p2 == -1){ str_triades = blank;return 0;};
    var str_checksum = str_triades.substr(p1 + 1,p2 - p1 - 1);
    return parseInt(str_checksum);
    
  } 
  
  // Get lm_time from first triade
  function get_lm_time(){

    var p1 = str_triades.indexOf('_');
    if(p1 == -1){ str_triades = blank;return lm_extern_time;};
    var p2 = str_triades.indexOf('_',p1 + 1);
    if(p2 == -1){ str_triades = blank;return lm_extern_time;};
    var p3 = str_triades.indexOf(';',p2 + 1);
    if(p3 == -1){ str_triades = blank;return lm_extern_time;};
    var str_lm_cookie_time = str_triades.substr(p2 + 1,p3 - p2 - 1);
    return parseInt(str_lm_cookie_time);
  }
  
  // set params checksum and lm_time
  function set_params(){

    var cookie_time = get_lm_time();
    if(cookie_time < lm_extern_time){
      lm_time = lm_extern_time;
      checksum = 0;
    }else{
      lm_time = cookie_time;
      checksum = get_checksum();
    }
  }

  // Save new checksum value to first triade in str_triades
  function checksum_to_triade(){

    //alert('checksum_to_triade (checksum):' + checksum);
    var p1 = str_triades.indexOf('_');
    if(p1 == -1){ str_triades = blank;return 0;};
    var p2 = str_triades.indexOf('_',p1 + 1);
    if(p2 == -1){ str_triades = blank;return 0;};
    str_triades = str_replace(str_triades,p1 + 1,p2 - p1 - 1,checksum + '');
    //alert('checksum_to_triade (str_triades):' + str_triades);
    return checksum;    
  }


  // Save new lm_time to first triade of str_triades 
  function lm_time_to_triade(){

    var p1 = str_triades.indexOf('_');
    if(p1 == -1){ str_triades = blank;return lm_extern_time;};
    var p2 = str_triades.indexOf('_',p1 + 1);
    if(p2 == -1){ str_triades = blank;return lm_extern_time;};
    var p3 = str_triades.indexOf(';',p2 + 1);
    if(p3 == -1){ str_triades = blank;return lm_extern_time;};
    str_triades = str_replace(str_triades,p2 + 1,p3 - p2 - 1,lm_time + '');
    return lm_time;
  }


  //-----------------------------------------------------
  // Procedures of processing a view of link`s section
  //-----------------------------------------------------
  
  // Get element by its id
  function get_element_obj(divId){

    var emptyObj;
    if(typeof(document.all) != 'undefined'){
      if(typeof(document.all[divId]) != 'undefined'){
        return document.all[divId];
      }else{
        return emptyObj;
      }
    }

    if(typeof(document.getElementById) != 'undefined'){
      if(typeof(document.getElementById(divId)) != 'undefined'){
        return document.getElementById(divId);
      }else{
        return emptyObj;
      }
    }
	
    return emptyObj;
  }


  // Get style of element`s display  
  function get_display(objElement){

    var emptyObj;
    if(typeof(objElement) == 'undefined'){
      return emptyObj;
    }
    if(typeof(objElement.style) == 'undefined'){
      return emptyObj;
    }
    if(typeof(objElement.style.display) == 'undefined'){
      return emptyObj;
    }
    return objElement.style.display;
  }


  // Set style of element`s display
  function set_display(objElement,display,id){

    var emptyObj;
    if(typeof(objElement) == 'undefined'){
      return emptyObj;
    }
    if(typeof(objElement.style) == 'undefined'){
      return emptyObj;
    }
    if(typeof(objElement.style.display) == 'undefined'){
      return emptyObj;
    }

    //var img='/bitrix/templates/gubkin_template/images/arrowToRight';	
    objElement.style.display = display;

    /*if(objElement.style.display == 'none'){
      img+='01.gif';
    }
    if(objElement.style.display == 'block'){
      img+='02.gif';
    }*/

    //eval('document.images.img'+id+'.src='+'"'+img+'"');
    return objElement.style.display;
  } 


  //-----------------------------------------------------
  // Procedures of processing of checksum
  //----------------------------------------------------- 
  
  // Split checksum to array
  function split_checksum(v_checksum){

    var i;
    var display = new Array();

    while(v_checksum > 1){
      display[display.length] = v_checksum & 1;
      v_checksum = v_checksum >> 1;
    }
    display[display.length] = v_checksum & 1;
    return display;
  }

  // Merge checksum from array to integer value
  function combine_checksum(aChecksum){

    var v_checksum = 0;
    var order = 1;
    for(i=0;i<aChecksum.length;i++){
      v_checksum+=order*aChecksum[i];
      order*=2;
    }
    return v_checksum;
  }

  //-----------------------------------------------------
  // Interface procedures to web-page
  //-----------------------------------------------------

  function show(){
	//alert('show (checksum):' + checksum);
    if(!js_cookie_support) {return;};
    var arr_checksum = split_checksum(checksum);
	
    var id=0;
    while(1){
      divId = 'div' + id;
      obj_element = get_element_obj(divId);
		
      if(typeof(obj_element) == 'undefined'){break;};
		
      if(arr_checksum.length <= id){
        display = 'none';
      }else{
        if(arr_checksum[id] == 0){
          display = 'none';
        }else{
          display = 'block';
        }
      }
      display = set_display(obj_element,display,id);
      if(typeof(display) == 'undefined') {break;};
        id++;
      }
  }
  this.show = show;


  function clicked(id){

    // Open or close menu section
    divId = 'div' + id;
    var obj_element = get_element_obj(divId);
    if(typeof(obj_element) == 'undefined'){return;};

    display = get_display(obj_element);
    if(typeof(display) == 'undefined') {return;};

    if(display == 'none'){
      display = 'block';
    }else{
      display = 'none';
    }

    display = set_display(obj_element,display,id);

    if(typeof(display) == 'undefined') {return;};

    // Calculate new checksum
    var add = 1;
    if(id > max_power){
      add = 0;
    }else{
      for(i=0;i<id;i++) {add*=2;};
      if(display == 'none') {add = -add;};
    }

    checksum = checksum + add;
    if(checksum < 0){checksum = 0;};
    //alert('clicked_id (checksum):' + checksum);
    // Set new value for str_triades
    checksum_to_triade();
    lm_time_to_triade();

    if(!js_cookie_support) {return;};

    if(id > max_power) {return;};
	//alert('clicked_id (str_triades):' + str_triades);
    today = new Date();
    obj_cookie.setCookie(cookie_name,str_triades,today.getTime() + 365*24*60*60*1000,'/','','');

    return; 
  }
  this.clicked = clicked;

}