
/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("SmartSoftLine.SmartWebTech.WebControls");

SmartSoftLine.SmartWebTech.WebControls.ScrollGallery = function(element) {

	SmartSoftLine.SmartWebTech.WebControls.ScrollGallery.initializeBase(this, [element]);
	
	this._scroller = null;
	this._infoLabel = null;
	this._actualWidth = null;
	this._scrollerBounds = null;
	this._scrollPercent = null;

}

SmartSoftLine.SmartWebTech.WebControls.ScrollGallery.prototype = {
	initialize : function() {  
        
        this._scrollerBounds = Sys.UI.DomElement.getBounds(this._scroller);
	    this._scrollerBounds.x += 5;
	    this._scrollerBounds.width -= 10;   
	    this._actualWidth = parseFloat(this._actualWidth);    
	    this._scrollPercent = (this._actualWidth / this._scrollerBounds.width - 1);
              
        for (var i = 0; i < this._scroller.childNodes.length ; i++)
        {
            if (this._scroller.childNodes[i].nodeName == 'A')
            {
                $addHandlers(this._scroller.childNodes[i], {'mouseover':this._onItemMouseOver, 'mouseout':this._onItemMouseLeft}, this);  
            }
        }
        
        $addHandlers(this._scroller, {'mousemove':this._onScrollerMouseMove}, this);  
        
		SmartSoftLine.SmartWebTech.WebControls.ScrollGallery.callBaseMethod(this, 'initialize');

		
	
	},
	
	dispose : function() {

        for (var i = 0; i < this._scroller.childNodes.length ; i++)
        {
            if (this._scroller.childNodes[i].nodeName == 'A')
            {
                $clearHandlers(this._scroller.childNodes[i]);  
            }
        }	
        
        $clearHandlers(this._scroller);  
        
		SmartSoftLine.SmartWebTech.WebControls.ScrollGallery.callBaseMethod(this, 'dispose');
	},
	
	_onScrollerMouseMove : function(e)
	{                
    	    var scrollLeft = this._scrollPercent *(e.clientX - this._scrollerBounds.x);
	        
	        if (scrollLeft < 0) this._scroller.scrollLeft = 0;
    	    else this._scroller.scrollLeft = parseInt(scrollLeft);

	},
	
	
	_onItemMouseOver : function(e)
	{
	    this._infoLabel.innerHTML = e.target.alt;
	},
	
	_onItemMouseLeft : function(e)
	{
	
	},

	set_actualWidth : function(value) {
		this._actualWidth = value;
	},
	get_actualWidth : function() {
		return this._actualWidth.value;
	},
	
	set_infoLabel : function(value) {
		this._infoLabel = value;
	},
	get_infoLabel : function() {
		return this._infoLabel.value;
	},	

	set_scroller : function(value) {
		this._scroller = value;
	},
	get_scroller : function() {
		return this._scroller.value;
	}
	
};

SmartSoftLine.SmartWebTech.WebControls.ScrollGallery.registerClass('SmartSoftLine.SmartWebTech.WebControls.ScrollGallery', Sys.UI.Control);