function getChildNodes(id, key){
  var pNode = document.getElementById(id);
  var nodes = pNode.childNodes;

  var buff = [];

  for(var i=0,n=nodes.length; i<n; i++){
    var node = nodes[i];
    var atts = node.attributes;
    if(atts != null && atts[key] != null){
      buff[buff.length] = node.cloneNode(true);
    }
  }

  if(0 == buff.length){
    return null;
  }
  return buff;
}

function initBanner(id){
  var pNode = document.getElementById(id);
  var nodes = getChildNodes(id, 'title');
  while(pNode.hasChildNodes()){
    pNode.removeChild(pNode.lastChild);
  }

  while(nodes.length != 0){
    pNode.insertBefore(nodes.pop(), pNode.firstChild);
  }
}

function incomBannerMove(id, num){
  var pNode = document.getElementById(id);

  if(num == 0){
    pNode.appendChild(pNode.firstChild.cloneNode(true));
    pNode.removeChild(pNode.firstChild);
  }else{
    pNode.insertBefore(pNode.lastChild.cloneNode(true), pNode.firstChild);
    pNode.removeChild(pNode.lastChild);
  }
}

function pageLoad(){
  initBanner('movBox');
}

if (typeof window.addEventListener != 'undefined') {
  window.addEventListener("load", pageLoad, false);
} else if (typeof window.attachEvent != 'undefined') {
  window.attachEvent("onload", pageLoad);
}
