var full_w = screen.width - 230;
var spec_width = 350; // 370
var novs_width = 250; // 270
var spec_offs = 0;


function show_spec_fishki(num)
{
   if (document.getElementById('spec_cnt'))
   {
   var spec_cnt = document.getElementById('spec_cnt').value;
   var firstspec = num;
   //var spec_per_page = document.getElementById('spec_per_page').value;
   var spec_per_page = 2;

   // стираем все кнопки нафиг. потом выставим.
   for (var i=1; i<=spec_cnt; i++)
   {
      if (document.getElementById('spec_'+i+'but')) document.getElementById('spec_'+i+'but').src = "/new_d/pager/"+i+".gif";
      if (document.getElementById('spec_div_'+i)) {document.getElementById('spec_div_'+i).style.display = 'none';}
   }

   // первый-последний
   if (firstspec==spec_cnt) // последний
   {
     firstspec = parseInt(firstspec)-1;
   }
   if (firstspec==1 && spec_per_page>2) // первый
   {
     firstspec = 2;
   }

   if (firstspec)
   {
      // кнопки
      if (document.getElementById('spec_'+firstspec+'but')) document.getElementById('spec_'+firstspec+'but').src = "/new_d/pager/"+firstspec+"a.gif";
      if (document.getElementById('spec_'+(parseInt(firstspec)+1)+'but')) document.getElementById('spec_'+(parseInt(firstspec)+1)+'but').src = "/new_d/pager/"+(parseInt(firstspec)+1)+"a.gif";
      if (document.getElementById('spec_'+(parseInt(firstspec)-1)+'but') && spec_per_page>2) document.getElementById('spec_'+(parseInt(firstspec)-1)+'but').src = "/new_d/pager/"+(parseInt(firstspec)-1)+"a.gif";

      // дивы
      if (document.getElementById('spec_div_'+firstspec)) document.getElementById('spec_div_'+firstspec).style.display = 'block';
      if (document.getElementById('spec_div_'+(parseInt(firstspec)+1))) document.getElementById('spec_div_'+(parseInt(firstspec)+1)).style.display = 'block';
      if (document.getElementById('spec_div_'+(parseInt(firstspec)-1)) && spec_per_page>2) document.getElementById('spec_div_'+(parseInt(firstspec)-1)).style.display = 'block';
   }
   document.getElementById('firstspec').value=firstspec;
   }
}

function sub_menu(id,hide)
{
   if(hide)
   {
      document.getElementById('subm'+id).style.display='none';
   }
   else
   {
      document.getElementById('subm'+id).style.display='block';
      var itemX = document.getElementById('topm'+id).offsetParent.offsetLeft;
      if (document.getElementById('topm'+(id+1)))
      {
         var itemXn = document.getElementById('topm'+(id+1)).offsetParent.offsetLeft;
      }
      var totalX = document.getElementById('topm_main').offsetWidth;
      var tablX = document.getElementById('subm'+id).offsetWidth;

      if (itemX == 0) // первый
      {
         Xp = 15;
      }
      else if (itemX <= (totalX - tablX))  // до половины
      {
         Xp = itemX;
      }
      else if(itemXn && itemXn - tablX > 15) // половина
      {
         Xp = itemXn - tablX;
      }
      else  // после половины
      {
         Xp = totalX - tablX - 15;
      }
      document.getElementById('subm'+id).style.left = Xp + 'px';
      document.getElementById('subm'+id).style.display='block';
   }
}


///////// счетчик

CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%H%% : %%M%% : %%S%% ";

CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0) CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;


function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (LeadingZero && s.length < 2)
    s = "0" + s;
  return s;
}

function CountBack(secs, div_id) {

  var seconds = secs;
	
  if (secs < 0) {
    if (document.location.search)
    {
       var add_chr = '&';
    }
    else
    {
       var add_chr = '?';
    }
    document.location.href= document.location.href + add_chr + 'rnd=1';
    return;
  }
 
  // days
  var days  = Math.ceil(secs / 86400) - 1;
  secs -= days * 86400;
  
  // hours
  var hours = Math.ceil(secs / 3600) - 1;
  secs -= hours * 3600;
  
  // minutes
  var mins  = Math.ceil(secs / 60) - 1;
  secs -= mins * 60;
  
  var d_name = 'дней';
  if (days == 1) {
  	d_name = 'день';
  }
  if (days > 1 && days < 5) {
  	d_name = 'дня';
  }
  
  
  if (days > 0) {
  	secs  = '';
  	days = '<span>'+days+'</span>&nbsp;'+d_name;
  } else {
  	days = '';
  	secs = '<span>'+secs+'</span>&nbsp;сек.';
  }
  
  if (hours > 0) {
  	hours = '<span>'+hours+'</span>&nbsp;час.';
  } else {
  	hours = '';
  }
  
  if (mins > 0) {
  	mins = '<span>'+mins+'</span>&nbsp;мин.';
  } else {
  	mins = '';
  }
  
  document.getElementById(div_id).innerHTML = days+hours+mins+secs;
  
  
  if (CountActive) setTimeout("CountBack("+(seconds+CountStepper)+", '"+ div_id+"')", SetTimeOutPeriod);
}