/*
  [XiaoYeMen.Com JavaScript Library](C)2006-2009
  Author @ msn:liujian@xiaoyemen.com QQ:250560973
  $Id: V1.0 Des 12, 2008 00:15:00 by Jensen $
*/
function addLoadEvent(func){
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
    window.onload = func;
  }else{
    window.onload = function(){
      oldonload();
      func();
    }
  }
}
function insertAfter(newElement,targetElement){
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement){
    parent.appendChild(newElement);
  }else{
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}
function addClass(element,value){
  if(!element.className){
    element.className=value;
  }else{
    newClassName=element.className;
    newClassName+="";
    newClassName+=value;
    element.className=newClassName;
  }
}
function moveElement(elementID,final_x,final_y,interval){
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement){
    clearTimeout(elem.movement);
  }
  if (!elem.style.left){
    elem.style.left = "0px";
  }
  if (!elem.style.top){
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (xpos == final_x && ypos == final_y){
    return true;
  }
  if (xpos < final_x){
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x){
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y){
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y){
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}
function navSliderShow(){
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("nav")) return false;
  var nav = document.getElementById("nav");
  var slidershow = document.createElement("li");
  slidershow.setAttribute("id","navslidershow");
  var preview = document.createElement("img");
  preview.setAttribute("src","template/images/nav_bg.jpg");
  preview.setAttribute("alt","Silicon Valley School of Nursing");
  preview.setAttribute("id","preview");
  slidershow.appendChild(preview);
  nav.appendChild(slidershow);
  var currenturl = document.location.href;
  if (currenturl.indexOf("home.htm") != -1){
    moveElement("preview",0,0,5);
  }
  if (currenturl.indexOf("certified-nursing-assistant.htm") != -1){
    moveElement("preview",-220,0,5);
  }
  if (currenturl.indexOf("testimonies.htm") != -1){
    moveElement("preview",-440,0,5);
  }
  if (currenturl.indexOf("class-schedule.htm") != -1){
    moveElement("preview",-660,0,5);
  }
  if (currenturl.indexOf("registration-form.htm") != -1){
    moveElement("preview",-880,0,5);
  }
  if (currenturl.indexOf("contact.htm") != -1){
    moveElement("preview",-1100,0,5);
  }

  if (currenturl.indexOf("referral-program.htm") != -1){
    moveElement("preview",-220,0,5);
  }
  if (currenturl.indexOf("scholarship.htm") != -1){
    moveElement("preview",-440,0,5);
  }
  if (currenturl.indexOf("career-opportunities.htm") != -1){
    moveElement("preview",-660,0,5);
  }
  if (currenturl.indexOf("financial-aid.htm") != -1){
    moveElement("preview",-880,0,5);
  }
}
function navSliderMove(){
  var nav = document.getElementById("nav");
  var links = nav.getElementsByTagName("a");
  var currenturl = document.location.href;
  for (var i=0; i<links.length;i++){
    links[i].onmouseover = function(){
      var linkurl = this.getAttribute("href");
      if (linkurl.indexOf("home.htm") != -1){
        moveElement("preview",0,0,5);
      }
      if (linkurl.indexOf("certified-nursing-assistant.htm") != -1){
        moveElement("preview",-220,0,5);
      }
      if (linkurl.indexOf("testimonies.htm") != -1){
        moveElement("preview",-440,0,5);
      }
      if (linkurl.indexOf("class-schedule.htm") != -1){
        moveElement("preview",-660,0,5);
      }
      if (linkurl.indexOf("registration-form.htm") != -1){
        moveElement("preview",-880,0,5);
      }
      if (linkurl.indexOf("contact.htm") != -1){
        moveElement("preview",-1100,0,5);
      }

      if (linkurl.indexOf("referral-program.htm") != -1){
        moveElement("preview",-220,0,5);
      }
      if (linkurl.indexOf("scholarship.htm") != -1){
        moveElement("preview",-440,0,5);
      }
      if (linkurl.indexOf("career-opportunities.htm") != -1){
        moveElement("preview",-660,0,5);
      }
      if (linkurl.indexOf("financial-aid.htm") != -1){
        moveElement("preview",-880,0,5);
      }
    }
    links[i].onmouseout = function(){
      if (currenturl.indexOf("home.htm") != -1){
        moveElement("preview",0,0,5);
      }
      if (currenturl.indexOf("certified-nursing-assistant.htm") != -1){
        moveElement("preview",-220,0,5);
      }
      if (currenturl.indexOf("testimonies.htm") != -1){
        moveElement("preview",-440,0,5);
      }
      if (currenturl.indexOf("class-schedule.htm") != -1){
        moveElement("preview",-660,0,5);
      }
      if (currenturl.indexOf("registration-form.htm") != -1){
        moveElement("preview",-880,0,5);
      }
      if (currenturl.indexOf("contact.htm") != -1){
        moveElement("preview",-1100,0,5);
      }

      if (currenturl.indexOf("referral-program.htm") != -1){
        moveElement("preview",-220,0,5);
      }
      if (currenturl.indexOf("scholarship.htm") != -1){
        moveElement("preview",-440,0,5);
      }
      if (currenturl.indexOf("career-opportunities.htm") != -1){
        moveElement("preview",-660,0,5);
      }
      if (currenturl.indexOf("financial-aid.htm") != -1){
        moveElement("preview",-880,0,5);
      }
    }
  }
}
addLoadEvent(navSliderMove);
addLoadEvent(navSliderShow);
