/*
 * Self built sliding menu for shuo-wang.com,
 * derived from http://www.dynamicdrive.com/
 *
 * @author Shuo Wang
 * @email shwang1386@gmail.com
 *
 */


var slide_width;var slide_reveal;var slide_top;
var leftBoundary;var RightBoundary;
var ns4;var ie4;var ns6;;

function setVars() {

  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      winW = window.innerWidth-16;
      winH = window.innerHeight-16;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth-20;
        winH = document.body.offsetHeight-20;
    }
  }

  slideW = winW * 0.15;
  slideR = slideW * 0.15;
  slide_width = slideW; // width of menu
  slide_reveal = slideR; // initial protrusion amount
  slide_top = '20'; //vertical offset
  rightBoundary = 0;
  leftBoundary = parseInt((slide_width - slide_reveal) * -1);

  ns4=document.layers?1:0
  ie4=document.all
  ns6=document.getElementById&&!document.all?1:0

}

setVars();

function updateMenu() {
  setVars();
  document.getElementById('menu').style.width = parseInt(slide_width) + 'px';
}

function drawMenu() {
  /* This is just the function that writes the text, called on window onload */
  document.write("<div id=\"menu\" class=\"border\" style=\"left: " + (parseInt((slide_width - slide_reveal) * -1)) + "px;top: " + slide_top + "px;width: " + slide_width + "px;\" onClick=\"slide();\">");

  var sitems=new Array()

  ///////////Edit below/////////////////////////////////

  //siteitems[x]=["Item Text::::ajax url link"]

  sitems.push("<strong>Site Home</strong>::::index.php")
  sitems.push("About Me::::about.php")
  sitems.push("Publications::::publications.php")
  sitems.push("Public Profiles::::profiles.php")
//  sitems.push("Blog::::blog.html");

  //If you want the links to load in another frame/window, specify name of target (ie: target="_new")
  var target=""

  /////////////////////////////////////////////////////////

  if (ie4||ns4||ns6){
    for (i=0;i<sitems.length;i++){
      sitems[i] = sitems[i].split("::::");
      if (sitems[i][1])
        document.write('<a href="javascript:void(0);" onclick="lastDir=\'blah\';ajaxURL(\'./pages/' + sitems[i][1] + '\');">')
      document.write(sitems[i][0])
      if (sitems[i][1])
        document.write('</a>')
      document.write('<br>\n')
    }
  }
  document.write("</div>");
}

lastDir = "in";

function slide() {
  if(lastDir == "out") {
    slideIn();
    lastDir = "in";
    lastLastDir = "in";
    $('menu').style.backgroundImage = "url(./images/menu-out.png)";
  } else if (lastDir = "out") {
    slideOut();
    lastDir = "out";
    lastLastDir = "out";
    $('menu').style.backgroundImage = "url(./images/menu-in.png)";
  } else {
    lastDir = lastLastDir;
  }
}

// initialize push and pull variables
var push;
var pull;

function slideOut() {
  this.pull = setInterval("pullEngine()", 1);
}

function slideIn() {
  push = setInterval("pushEngine()", 1);
}

function pullEngine() {
  if(undefined != push) {clearInterval(push);}
//  alert(parseInt($("menu").style.left) + " ... " + rightBoundary);
  if (parseInt($("menu").style.left) < rightBoundary) {
    $("menu").style.left = parseInt($("menu").style.left) + 4 + "px";
  } else {
    $("menu").style.left = rightBoundary + "px";
    clearInterval(pull);
  }
}

function pushEngine() {
  if(pull != undefined) {clearInterval(pull);}
//  alert(parseInt($("menu").style.left) + " ... " + leftBoundary);
  if (parseInt($("menu").style.left) > leftBoundary) {
    $("menu").style.left = parseInt($("menu").style.left) - 4 + "px";
  } else {
    $("menu").style.left = leftBoundary + "px";
    clearInterval(push);
  }
}

window.onload = drawMenu();
window.onload = ajaxURL("./pages/index.php");
