/**
 * Image scroller.
 * Allows multiple image to be contained in one div and then scrolled so that a large number of images can be seen in a small container.
 *
 * Changelog
 * 1.0.0 - 16/06/2008 - Luke Henderson - Initial release
 *
 *
 * @copyright drivebusiness
 * @package horizontalScroller
 * @class horizontalScrollerClass
 * @version 1.0.0
 */
var horizontalScrollerClass = Class.create({
	/**
	 * Dom elements
	 */
	attached : false, //Actual DOM element we are scrolling
	template : false,

	/**
	 * Strings
	 */
	attached_id : '', //Id of the div we are scrolling

	/**
	 * Objects
	 */
	options : {
		mode : 'standard' //Which scroller should we use as standard
	},
	template_options : { //Empty container for template options
	},

	/**
	 * @constructor
	 * @param {String} The id of the element we want to scroll'ify
	 * @param {Object} An object containing configuration values for the horizontalScrollerClass
	 * @param {Object} An object containing configuration values for the template loaded by the class
	 */
	initialize : function(id)
	{
		this.attached_id = arguments[0] || false;
		this.attached = $(this.attached_id);
		//Make sure the container exists
		if(this.attached == false || this.attached == null)
		{
			return ;
		}

		//See if we have provided any overwriting options
		Object.extend(this.options, arguments[1] || {});
		Object.extend(this.template_options, arguments[2] || {});

		//Load the style sheet for the basket
		var style = new Element('link');
		style.rel = 'stylesheet';
		style.media = 'screen';
		style.type = 'text/css';
		style.href = script_url + 'horizontalScroller/' + this.options.mode + '.css';;
		head_el.insert({bottom: style});

		//Load the script template
		var script = new Element('script');
		script.src = script_url + 'horizontalScroller/' + this.options.mode + '.js';
		//IE has a different way of doing things (as always!)
		if(Prototype.Browser.IE)
		{
			script.onreadystatechange = this.templateLoadedIE.bindAsEventListener(this);
		}
		else
		{
            Event.observe(script, 'load', this.templateLoaded.bindAsEventListener(this));
		}
		head_el.insert({bottom: script});
	},

	/**
	 * See if the template loaded successfully
	 * @ignore
	 */
	templateLoaded : function()
	{
		if(horizontalScrollerTemplate != undefined && !this.template_loaded)
		{
			//Sometimes the browser reports two loads so make sure we don't load it twice
			this.template_loaded = true;
			this.template = new horizontalScrollerTemplate(this, this.template_options);
		}
	},

	/**
	 * IE specific function. Refers back to the normal templateLoaded function when we have confirmed it does indeed exist
	 * @ignore
	 */
	templateLoadedIE : function(e)
	{
		try {
			if(horizontalScrollerTemplate != undefined && horizontalScrollerTemplate != null)
			{
				this.templateLoaded();
				return;
			}
		}catch(err) {
			return;
		}
	}
});

