/*
 *	Panoramic image animator
 *	------------------------
 *	Copyright (c) 2011 Wabbit Web Works.
 *	All Rights Reserved.
 *
 *	This programme is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public Licence as published by
 *	the Free Software Foundation, either version 3 of the Licence, or
 *	(at your option) any later version.
 *
 *	This programme is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public Licence for more details.
 *
 *	You should have received a copy of the GNU General Public Licence
 *	along with this programme.  If not, see <http://www.gnu.org/licenses/>.
 */
var panorama = {
    interval: 50,
    scrollby: 3,

    initialise: function(element) {
	var el = document.getElementById(element);

	if (!el) {
	    alert("No '" + element + "' ID defined");
	    return;
	}

	this.current = 0;
	this.style = el.style;
	this.reset = -el.offsetWidth / 2;
	this.timer = setInterval(this.animate,this.interval);

	el.onmouseover = function() {
	    if (panorama.timer) {
		clearInterval(panorama.timer);
		panorama.timer = null;
	    }
	};
	el.onmouseout = function() {
	    if (!panorama.timer)
		panorama.timer = setInterval(panorama.animate,panorama.interval);
	};
    },

    animate: function()
    {
	panorama.current -= panorama.scrollby;

	if (panorama.current <= panorama.reset)
	    panorama.current = 0;

	panorama.style.left = panorama.current + 'px';
    },
};

/*
 *	initialise the panorama when the page has loaded
 *	and unload when the page closes
 */
add_load_event(function() {
    panorama.initialise('panorama');
});
add_unload_event(function() {
    if (panorama.timer)
	clearInterval(panorama.timer);
});

