var foo = null;
var img = null;

function findPosX(obj) {
  var curleft = 0;
  if(obj.offsetParent)
  while(1) {
    curleft += obj.offsetLeft;
    if(!obj.offsetParent)
      break;
    obj = obj.offsetParent;
  }
  else if(obj.x)
    curleft += obj.x;
  return curleft;
}

function xpos2str(pos) {
	if (document.documentElement.clientWidth > 750)
		return String(document.documentElement.clientWidth/2+pos)+'px';
	return String(findPosX(img)+748/2+pos)+'px';
}

function start() {
  foo = document.getElementById('thought');
  img = document.getElementById('header');
  move();
}

function move() {
  if (cur == 0) {
    foo.style.visibility = 'visible';
  }
  if (cur < pos.length) {
    foo.style.left = xpos2str(pos[cur][0]);
    foo.style.top = String(pos[cur][1])+'px';
  }
  cur += 1
  if (cur == pos.length+1) {
    cur = 0;
    setTimeout(move,500);
    foo.style.visibility = 'hidden';
  } else {
    setTimeout(move,140);
  }
}
cur = 0;
pos = [
[-320, 155],
[-317, 145],
[-316, 135],
[-315, 125],
[-315, 115],
[-316, 105],
[-319, 95],
[-323, 85],
[-328, 75],
[-334, 65],
[-334, 55],
[-320, 55],
[-305, 50],
[-298, 60],
[-301, 70],
[-304, 83],
[-306, 95],
[-307, 105],
[-308, 115],
[-308, 125],
[-308, 135],
[-306, 145],
[-301, 155],
];
window.onload = start;

