$(function(){
    //Get our elements for faster access and set overlay width
    var div = $('div.sc_menu'),
        ul = $('ul.sc_menu'),
        ulPadding = 15;
    
    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars 
    div.css({overflow: 'hidden'});
    
    //Find last image container
    var lastLi = ul.find('li:last-child');
    
    //When user move mouse over menu
    div.mousemove(function(e){
        //As images are loaded ul width increases,
        //so we recalculate it each time
        var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;   
        var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
        div.scrollLeft(left);
    });
});

function addToBasket(id) {
    name = "cnt"+id;
    count = document.getElementById(name).value;
//    alert();
    jQuery.post(
        '/code.php',
        {
            id: id,
            action: 'addBask',
            count: count
        },
        returnFuncB
    );
}

function returnFuncB(data) {
  //  alert(data);
    if(data == 'no') alert('Данного количества нет на складе');
    else if(data) {
        jQuery('#bskCnt').html(data);
        alert('Товар успешно добавлен в корзину!');
    }
}


/*
function retFB(data) {
    alert('2');
}

function deleteEmpty(sel) {
    if(sel.options[0].value == 0) sel.options[0] = null;
}

function changeSelect(sel) {
   selOpt = sel.options[sel.selectedIndex].value;
   divL = document.getElementById('scriptLeft');
   divR = document.getElementById('scriptRight');

    JsHttpRequest.query(
        '/adm.in/.front/backpage.php',
        {
            'id': selOpt,
            'action': 'changeSel'
        },
        function(result,errors) {
//            alert(result.right);
//            document.getElementById("view_links"+retId).innerHTML = errors;
            divL.innerHTML = result.left;
            divR.innerHTML = result.right;
        },
        true  // do not disable caching
    );

    deleteEmpty(sel);

}

function showCatElements(sel) {
   selOpt = sel.options[sel.selectedIndex].value;
   divL = document.getElementById('scriptLeft');
   divR = document.getElementById('elementsList');
   JsHttpRequest.query( 
        '/adm.in/.front/backpage.php',
        {
            'id': selOpt,
            'action': 'showCatElements'
        },

        function(result,errors) {    
//            document.getElementById("view_links"+retId).innerHTML = errors; 
            divR.innerHTML = result.right;
        },
        true  // do not disable caching
    );
    deleteEmpty(sel);
}


function doLoad(value,retId) {
   var req = new JsHttpRequest();
   req.caching = false;
   req.onreadystatechange = function() {
       if (req.readyState == 4) {   
           document.getElementById('content'+retId).innerHTML = req.responseText;
       }
   }
   req.open('POST', '/adm.in/.front/backpage.php', true);
   req.send( { q: value } );
   if(document.getElementById('view_links'+retId).style.display != 'none') show_hide('view_links'+retId);
}

function doit(action,id,retId) {   
    JsHttpRequest.query(
        '/adm.in/.front/backpage.php',
        {
            'id': id, // document.getElementById("id").value,  
            'action': action, //document.getElementById("action").value
            'retId': retId //document.getElementById("action").value
        },

        function(result,errors) {  
            document.getElementById('ccat'+retId).innerHTML = errors; 
        },
        true  // do not disable caching
    );
    if(document.getElementById('view_links'+retId).style.display != 'none') show_hide('view_links'+retId);
}

function dodel(action,id,retId) {
    JsHttpRequest.query( 
        '/adm.in/.front/backpage.php',
        {
            'id': id,
            'action': action 
        },

        function(result,errors) {    
            document.getElementById("view_links"+retId).innerHTML = errors; 
  //                document.getElementById("ccat").innerHTML = result.ccat; 
        },
        true  // do not disable caching
    );
}

function doview(id,elmid,action,retId) {    
     if(document.getElementById('view_links'+retId).style.display == 'none') {
        JsHttpRequest.query( 
          '/adm.in/.front/backpage.php',
          {
               'id': id,
               'elmid': elmid,
               'action': action
          },

          function(result,errors) {     
              document.getElementById("view_links"+retId).innerHTML = errors;
          },
          true  // do not disable caching
       );
    }
    show_hide('view_links'+retId);
}




function list_check(msg_alert,msg_congfirm,elems_id)  {
   var numchecked = getNumChecked(document.getElementById(elems_id)); 
   if(numchecked < 1) 
      {
      alert(msg_alert); 
      return false;
      }
   if(confirm(msg_congfirm)) return true;
   else return false;
}

function open_window(link,w,h) {
    var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
    newWin = window.open(link,'newWin',win);
}

function showDiv(id) {
    jQuery("#"+id).css({display:""});
//    var leftP = (window.event.clientX)+"px";
  //  var topP = (window.event.clientY)+"px";
    jQuery("#"+id).css({left:"50px"});
}

         */
function show_hide(id) {
    if(document.getElementById(id).style.display=='block') {
        document.getElementById(id).style.display='none';
    } else {
        document.getElementById(id).style.display='block';
    }
}
  /*
var typeForm = 2;

function changeType(type) {
//  alert('2');
    if (type == 2) {
        jQuery("#predl").attr({style:"background:url('/img/d/plashkaBigAct.png') 0 0 no-repeat;"});
        jQuery("#predl a").attr({style:"color:#558dbb"});
        jQuery("#spros").attr({style:"background:url('/img/d/plashkaSmInact.png') 0 0 no-repeat;"});
        jQuery("#spros a").attr({style:"color:#fff"});
        typeForm = 2;
    } else {
        jQuery("#predl").attr({style:"background:url('/img/d/plashkaBigInact.png') 0 0 no-repeat;"});
        jQuery("#spros").attr({style:"background:url('/img/d/plashkaSmAct.png') 0 0 no-repeat;"});
        jQuery("#predl a").attr({style:"color:#fff"});
        jQuery("#spros a").attr({style:"color:#558dbb"});
        typeForm = 3;
    }
//alert(typeForm);


}

function goToCat(url) {
//    url += "&type="+typeForm;
    jQuery("#goForm").attr({action:url});
    jQuery("#goForm input").attr({value:typeForm});
    document.getElementById("goForm").submit();
//    alert(url);
}


function checkAllReverse(form){
    for (i = 0, n = form.elements.length; i < n; i++) {
            if(form.elements[i].type == "checkbox") {
                    if(form.elements[i].checked == true)
                            form.elements[i].checked = false;
                    else
                            form.elements[i].checked = true;
            }
    }
}

function checkAll(form,value){
//alert(value);
  // if(value)value=false;
   //else value=true;
    for (i = 0, n = form.elements.length; i < n; i++) {
            if(form.elements[i].type == "checkbox") {
//                    if(form.elements[i].checked == true)
  //                          form.elements[i].checked = false;
    //                else
                            form.elements[i].checked = value;
            }
    }
}

function getNumChecked(form){
    var num = 0;
    for (i = 0, n = form.elements.length; i < n; i++) {
            if(form.elements[i].type == "checkbox") {
                    if(form.elements[i].checked == true)
                            num++;
            }
    }
    return num;
}

function change(elm) {
    jQuery(elm).attr({class:'imageAuthAct'});
}
function change2(elm) {
    jQuery(elm).attr({class:'imageAuth'});
}
function change3(elm) {
    jQuery(elm).attr({class:'imageSearchAct'});
}
function change4(elm) {
    jQuery(elm).attr({class:'imageSearch'});
}
*/