Toschi.Splash = function(imgElement, imgLinkElement, linkElement)
{
	this.interval = 10;

	this.imgElement = imgElement;
	this.imgLinkElement = imgLinkElement;
	this.linkElement = linkElement;
	
	this.lastMouseMove = 0;
	this.imgElement.onmousemove = this.mouseMoved.bind(this);
	
	this.update();
	
	new PeriodicalExecuter(this.update.bind(this), 1);
};

Toschi.Splash.prototype.items =
[
    {
        text: 'San Francisco',
        image: '/static/splash/store.jpg',
        link: '/news'
    },
    {
        text: 'F200',
        image: '/img/splash/f200.jpg',
        link: '/product/f200/8115'
    },
    {
        text: 'SL3W',
        image: '/img/splash/sl3w.jpg',
        link: '/product/sl3w/26152'
    },
    {
        text: 'Vela',
        image: '/img/splash/vela2.jpg',
        link: '/product/vela/21670'
    },
    {
        text: 'Vine',
        image: '/img/splash/vine-belt.jpg',
        link: '/product/vine-belt/9875'
        /*
    },
    {
        text: 'Frisco',
        image: '/img/splash/frisco.jpg',
        link: '/product/frisco/9382'
    },
    {
        text: 'Spur',
        image: '/img/splash/spur.jpg',
        link: '/product/spur/20574'
    },
	{
		text: 'Mara',
		image: '/img/splash/mara.jpg',
		link: '/product/mara/7387'
	},
	{
		text: 'SUV2',
		image: '/img/splash/suv2.jpg',
		link: '/product/suv2/17850'
	},
	{
		text: 'Vela',
		image: '/img/splash/vela.jpg',
		link: '/product/vela/21670'
    },
	{
		text: 'GX',
		image: '/img/shoes/banner-GX.jpg',
		link: '/product/golf-gx/20582?cat=/golf/footwear'
	},
	{
		text: 'SUV',
		image: '/img/shoes/banner-SUV.jpg',
		link: '/product/suv2/17850'
	},
	{
		text: 'Berta',
		image: '/img/shoes/banner-Berta.jpg',
		link: '/product/berta/17830'
	*/
	}
];

Toschi.Splash.prototype.update = function()
{
	var currentdate = new Date();
	
	if (!this.imgElement.src || ((currentdate.getSeconds() - this.lastMouseMove) >= this.interval))
	{
		var index = Math.floor(currentdate.getSeconds()/this.interval) % this.items.length;
		
		var item = this.items[index];
	
		this.imgElement.src = item.image;
		this.imgElement.alt = item.text;
		this.imgLinkElement.href = item.link;
		
		if (this.linkElement)
		{
			this.linkElement.href = item.link;
		}
	
		this.nextImage = new Image();
		this.nextImage.src = this.items[(index+1)%this.items.length].image;
	}
};

Toschi.Splash.prototype.mouseMoved = function()
{
	var currentdate = new Date();
	
	this.lastMouseMove = currentdate.getSeconds();
};
