
cur_p = 'all';

function change_advert(img,type)
{
    var url = "/ajax/advert.php";
    var pars = "op=change_advert&img="+img+"&type="+type;

    new Ajax.Request(url,
      {
        parameters: pars,
        onCreate: function(){},
        onComplete: function(transport) {
        var text = transport.responseText;
        var json = text.evalJSON();
        if (!json.er)
        {
            if (cur_p == 'main' && json.time && json.time != 0 && json.time != '0')
            {
                tm = parseInt(json.time);
                img_timing[type] = json.img;
                setTimeout("change_banner('"+type+"')",tm*1000);
            }
            if (type == 'main')
            {
                ids = 'main-banner';
            }
            if (type == 'top')
            {
                ids = 'top-banner';
            }
            if (type == 'right')
            {
                ids = 'ban-right';
            }
            if (type == 'right2')
            {
                ids = 'ban-right2';
            }
            $(ids).innerHTML = json.data;
        }
        }
      });    
    return false;
}

function rand_prod()
{
    var url = "/ajax/products.php";
    var pars = "op=rand_prod";

    new Ajax.Request(url,
      {
        parameters: pars,
        onCreate: function(){$('blocker').style.visibility = 'visible';},
        onComplete: function(transport) {
        $('blocker').style.visibility = 'hidden';
        var text = transport.responseText;
        var json = text.evalJSON();
        if (!json.er)
        {   
            $('rand-prod').innerHTML = json.data;
        }
        }
      });    
    return false;
}

function correct_fixed_by_id(cid,e)
{
    if (f_scrollTop() > 75)
    {
        p_top = f_scrollTop() + 50;
    }
    else
    {
        p_top = 150 + f_scrollTop();
    }
    $(cid).style.top = p_top + 'px';
}

function f_clientWidth() {
    return f_filterResults (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
    );
}
function f_clientHeight() {
    return f_filterResults (
        window.innerHeight ? window.innerHeight : 0,
        document.documentElement ? document.documentElement.clientHeight : 0,
        document.body ? document.body.clientHeight : 0
    );
}
function f_scrollLeft() {
    return f_filterResults (
        window.pageXOffset ? window.pageXOffset : 0,
        document.documentElement ? document.documentElement.scrollLeft : 0,
        document.body ? document.body.scrollLeft : 0
    );
}
function f_scrollTop() {
    return f_filterResults (
        window.pageYOffset ? window.pageYOffset : 0,
        document.documentElement ? document.documentElement.scrollTop : 0,
        document.body ? document.body.scrollTop : 0
    );
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


function setElementOpacity(sElemId, nOpacity)
{
  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);

  if (!elem || !opacityProp) return; // Если не существует элемент с указанным id или браузер не поддерживает ни один из известных функции способов управления прозрачностью
  
  if (opacityProp=="filter")  // Internet Exploder 5.5+
  {
    nOpacity *= 100;
    
    // Если уже установлена прозрачность, то меняем её через коллекцию filters, иначе добавляем прозрачность через style.filter
    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")"; // Для того чтобы не затереть другие фильтры используем "+="
  }
  else // Другие браузеры
    elem.style[opacityProp] = nOpacity;
}

function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string') // CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
    return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string') // Mozilla 1.6 и младше, Firefox 0.8 
    return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string') // Konqueror 3.1, Safari 1.1
    return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) // Internet Exploder 5.5+
    return 'filter';

  return false; //нет прозрачности
}

blClickable = false;

function changeBlockWindow()
{
    if (blClickable == true)
    {                                         
        if (unBlockWindowId != '')
        {
            $('blocker-op').style.visibility = 'hidden';
            $(unBlockWindowId).style.display = 'none';
        }
    }
}

function show_popup(ids)
{
    dim = $('page').getDimensions();
    $('blocker-op').style.height = dim.height + 'px';
    $('blocker-op').style.visibility = 'visible';
    setElementOpacity('blocker-op',0.25);
    unBlockWindowId = ids+'-form-wrap';
    h = $('page').getHeight();
    $(unBlockWindowId).style.height = h + 150 + 'px';
    $('blocker').style.height = h + 150 + 'px'; 
    $('blocker-op').style.height = h + 150 + 'px';
    
    blClickable = true;
    $(unBlockWindowId).style.display = 'block';
    $(ids+'-wrap').style.display = 'none';
    $(ids+'-wrap').style.display = 'block';
    return false;
}

function show_photo(el)
{
    ids = 'full-pict';
    dim = $('page').getDimensions();
    $('blocker-op').style.height = dim.height + 200 + 'px';
    $('blocker-op').style.visibility = 'visible';
    setElementOpacity('blocker-op',0.25);
    unBlockWindowId = ids+'-form-wrap';
    
    $(unBlockWindowId).style.height = dim.height - f_scrollTop() + 'px';
    $(unBlockWindowId).style.top = '-' + f_scrollTop() + 'px';
    $(unBlockWindowId).style.padding = f_scrollTop()*2 + 20 + 'px 0 0 0';
    $(unBlockWindowId).style.bottom = dim.height  + 'px';
    blClickable = true;
    
    $(ids).innerHTML = '<a href="" onclick="return close_pic();"><img src="'+el.href+'" id="temp-pict" /></a><br /><a href="" onclick="return close_pic();" class="close"><span>Закрыть </span>X</a>';
    $(unBlockWindowId).style.display = 'block';
    //$(ids+'-wrap').style.display = 'none';
    $(ids+'-wrap').style.display = 'block';
    //setTimeout("t = $('temp-pict').getDimensions();$('full-pict-wrap').style.width = t.width;",3500)
    return false;
}

function close_pic()
{
    if (blClickable == true)
    {                                         
        if (unBlockWindowId != '')
        {
            $('blocker-op').style.visibility = 'hidden';
            $(unBlockWindowId).style.display = 'none';
        }
    }
    
    return false;
}

function close_blocker()
{
    $('blocker').style.visibility = 'hidden'; 
    $('blocker').style.height = 'auto'; 
}

function show_blocker()
{
    dim = $('page').getDimensions();
    $('blocker').style.height = dim.height + 'px';
    $('blocker').style.visibility = 'visible';
    setElementOpacity('blocker',0.25);
    h = $('page').getHeight();
    $('blocker').style.height = h + 200 + 'px'; 
    
    $('blocker').setStyle({background:'#000 url("/i/loading.gif") 50% '+(f_scrollTop()+300)+'px no-repeat'});

    return false;    
}

function fixBlockerBug()
{
    blClickable = false;
    setTimeout('blClickable = true;',200);
}

