﻿var xm = -30;
var nx = 0;
var nw = 0;

function mousemove(e)
{
    if (window.event) e = window.event;
    xm = e.clientX - nx - nw * .5;
}

function resize()
{
	var o = id("sensor");
	nx = pxLeft(o);
}
onresize = resize;

pxLeft = function(o)
{
	for(var x = -document.documentElement.scrollLeft; o != null; o = o.offsetParent)
		x += o.offsetLeft;
	return x;
}

var ss = {
	dx  : 0, // Delta x (aka offset)
	b0  : 0, // First <span>
	b1  : 0, // Second <span>
	NW  : 0, // <span>'s width
	
	slide : function ()
	{
		ss.dx -= xm * .024;
		if(ss.dx > 0) ss.dx -= ss.NW; else if(ss.dx < -ss.NW) ss.dx += ss.NW;
		
		ss.b0.style.left = px(ss.dx);
		ss.b1.style.left = px(ss.dx + ss.NW);
		setTimeout(ss.slide, 16);
	},
	
	init : function (obj) // Setting the <a>s and she <span>'s size
	{
		var a = obj.getElementsByTagName("a");
		for(var i = 0; i < a.length; i++)
		{
			var o = a[i];
			o.style.left = px(i * o.offsetWidth);
		}
		obj.style.width = px(a[0].offsetWidth * a.length);
		obj.style.height = px(a[0].offsetHeight);
		obj.style.left = px(0);
	},
	
	load : function ()
	{
	    ss.b0 = id("b0")
	    ss.b1 = id("b1")
	    ss.init(ss.b0);
	    
	    // Duplicating the <span>
	    ss.b1.innerHTML = ss.b0.innerHTML;
	    ss.b1.style.width = ss.b0.style.width;
	    ss.b1.style.height = ss.b0.style.height;
	    ss.b1.style.left = px(ss.b1.offsetWidth);
	    
	    id("sensor").onmousemove = mousemove;
	    id("sensor").onmouseout = mouseout;
        nw = id("sensor").offsetWidth;
        ss.NW = ss.b0.offsetWidth;
        
        resize();
        ss.slide();
	}
}

function mouseout(e)
{
    if (window.event) e = window.event;
    var relTarg = (e.relatedTarget || e.toElement);
    if (!Contains(this, relTarg))
    {
        xm = -30;
    }
}

function ListPopUp()
{
    $(".ListPopUp").toggle();
}

