/*
© Umbrace 2011
L.R.Friesema, W.R.Wolters

Full custom slider for p2 homepage
*/

// initSlider : should be called on doc.ready
var selectedIndex = 0;
var maxIndex;

function initSlider() {
  // bind events
  $("#arrow-left").click(function() {
    slide(-1);
  });
  $("#arrow-right").click(function() {
    slide(1);
  });

  //hide all
  $(".slideitem").hide("fast");
  
  //set visible index
  selectedIndex = 0;
  maxIndex = $(".slideitem").length - 1;
  document.getElementById('headcontainer').style.display = 'block';
  $("#hs0").show("fast");
  //$("#headcontainer").show('fast');
}
function slide(movement) {
  allowHover = false;
  documentLoad = true;
  
  //$(".left").width(644);
  $('.quote').show();
  $('.quote-right').hide();

  var oriSelectedIndex = selectedIndex;
  selectedIndex += movement;
  if (selectedIndex < 0) {
    selectedIndex = maxIndex;
  }
  if (selectedIndex > maxIndex) {
    selectedIndex = 0;
  }
  $("#hs" + oriSelectedIndex).css("z-index","0");
  $("#hs" + selectedIndex).css("z-index","2");
  $("#hs" + selectedIndex).show("slide", { direction: (movement > 0 ? "right" : "left") }, 1000);
  $("#hs" + oriSelectedIndex).hide();
  setTimeout('setAllowHover()',2000);
}
function setAllowHover() {
  allowHover = true;
  if (isRightSide) {
    // is hovering? animate
    $(".left").delay(2000).animate({ width: "335px" }, 750);
    $('.quote-right').delay(2000).slideDown();
    $('.quote').delay(2000).fadeOut();
  }
}

