var xmlhttp;
$('#loading').hide();

function showIndustry(industry, lang)
{
  document.getElementById("companies").innerHTML = '';
  $('#loading').show();
  xmlhttp = GetXmlHttpObject();
  if (xmlhttp == null) {
    alert ("Browser does not support HTTP Request");
    return;
  }
  var url="/industry.php";
  url = url+"?q="+industry;
  url = url+ "&lang=" + lang;
  url = url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET", url, true);
  xmlhttp.send(null);

}

function stateChanged()
{
  if (xmlhttp.readyState == 4) {
    document.getElementById("companies").innerHTML = xmlhttp.responseText;
    $('#loading').hide();
  }
}

function GetXmlHttpObject()
{
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject) {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

$(document).ready(function () {
  var $panels = $('#thumb .scrollContainer').find('.industry');
  var $container = $('#thumb .scrollContainer');

  $panels.css({
  'float' : 'left',
  'position' : 'relative' // IE fix to ensure overflow is hidden
  });
  // calculate a new width for the container (so it holds all panels)

  $container.css('width', $panels.length * 106).css('position', 'relative');

  // collect the scroll object, at the same time apply the hidden overflow
  // to remove the default scrollbars that will appear
  var $scroll = $('#thumb .indScroll').css('overflow', 'hidden').css('position', 'relative');
  // apply our left + right buttons
  $scroll.before('<img class="indScrollButtons left" src="/sites/default/files/industry/scroll/scroll_left.png" />').after('<img class="indScrollButtons right" src="/sites/default/files/industry/scroll/scroll_right.png" />');
  $('img.indScrollButtons.left').click(moveLeftInd);
  $('img.indScrollButtons.right').click(moveRightInd);
});

function moveLeftInd() {
  $('div.indScroll').scrollTo('-=100px', 300, {axis: 'x'});
}
function moveRightInd() {
  $('div.indScroll').scrollTo('+=100px', 300, {axis: 'x'});
} 
