// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var tabs = ["home","projects","bios","contact"];
var divHeight = 465;
var divWidth = 925;
var offset = 0;
var box;
var initialIndex = 0;

jQuery(document).ready(function() {

  box = document.getElementById("div_container");
  box.style.top = "0px";

});

function changeTab(index)
{
  if(index >= tabs.length)
    index = 0;
  
  initialIndex = index;
  $('BODY').attr('id', tabs[index]);
  
  $('#div_container').animate({
    top: '-' + divHeight*index  + 'px'
    }, 1000 
  );
}

function touchMove(e)
{
  var touch = e.touches[0];
  
  var newTop = (touch.pageY - offset);
  
  if(newTop < 0 && newTop > ((tabs.length-1) * divHeight * -1))
    box.style.top= newTop + "px";
  
  e.preventDefault();  
  return false;
}

function touchStart(e)
{
  var touch = e.touches[0];
  
  var currTop = parseInt(box.style.top);
  offset = (touch.pageY - currTop);
  
  e.preventDefault();
  return false;
}

function touchEnd(e)
{
  var touch = e.touches[0];
  
  var currTop = parseInt(box.style.top);
  var raw_index = ((currTop/divHeight) * -1);
  
  if (raw_index > (initialIndex + .2))
  {
    changeTab(Math.ceil(raw_index));
  }
  else if (raw_index < (initialIndex - .2))
  {
    changeTab(Math.floor(raw_index));
  }
  else
  {
    changeTab(initialIndex);
  }
  
  e.preventDefault();  
  return false;
}
