﻿function getPosition(e) {
  /*if (!e) {
    e = window.Event;
    document.captureEvents(Event.MOUSEMOVE);
  }
  
  var cursor = {x:0, y:0}
  
  if (e.pageX || e.pageY) {
    cursor.x = e.pageX;
    cursor.y = e.pageY;
  } else {
    var de = document.documentElement;
    var b = document.body;
    cursor.x = e.clientX + 
    (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
    cursor.y = e.clientY + 
    (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
  }
  
  return cursor;*/
}

var clienti = new Clienti();
var body = document.body;
var alertit = true;

function dobackgroundstuff(e) {
  if (!e) {
    var e = window.event||window.Event;
  }
  
  if('undefined'!=typeof e.pageX) {
    mouseX = e.pageX;
    mouseY = e.pageY;
  } else {
    mouseX = e.clientX + document.body.scrollLeft;
    mouseY = e.clientY + document.body.scrollTop;
  }

  var width = document.body.offsetWidth;
  var height = document.body.offsetHeight;
  
  var cwidth = width/2;
  var cheight = height/2;
  var cursor = getPosition();  
  
  var overflowx = 2400 - width;
  var overflowy = 1600 - height;
  
  var l1 = document.getElementById('layer1_funone');
  var l2 = document.getElementById('layer2_funone');
  var l3 = document.getElementById('layer3_funone');
  
  /*var posleft = cwidth - cursor.x;
  var postop = cheight - cursor.y;
  
  l1.style.left = (0.2 * posleft) + 'px';
  l2.style.left = (0.4 * posleft) + 'px';
  l3.style.left = (0.8 * posleft) + 'px';
  
  l1.style.top = (0.2 * postop) + 'px';
  l2.style.top = (0.4 * postop) + 'px';
  l3.style.top = (0.8 * postop) + 'px';*/
  
  var fullWidth = 2400;
  var fullHeight = 1600;
  var fullWidthOverflow = fullWidth - width;
  var fullHeightOverflow = fullHeight - height;
  
  var bgWPrPx = fullWidthOverflow / width;
  var bgHPrPx = fullHeightOverflow / height;
  
  var bgPosLeft = (mouseX * bgWPrPx) * -1;
  var bgPosTop = (mouseY * bgHPrPx) * -1;
  
  var bgPos1 = bgPosLeft + 'px ' + bgPosTop + 'px';
  var bgPos2 = (bgPosLeft/1.5) + 'px ' + (bgPosTop/1.5) + 'px';
  var bgPos3 = (bgPosLeft/3) + 'px ' + (bgPosTop/3) + 'px';
  
  l1.style.backgroundPosition = bgPos1;
  l2.style.backgroundPosition = bgPos2;
  l3.style.backgroundPosition = bgPos3;
  
  /*document.body.style.backgroundPosition = bgPos;*/
}

if(window.Event && document.captureEvents) {
  document.captureEvents(Event.MOUSEMOVE);
}

// Then assign the mouse handler
document.onmousemove = dobackgroundstuff;
// Then your mouseover function can just read mouseX and mouseY directly.
