// Create scrolling variable if it doesn't exist
if (!Scrolling_sub1) var Scrolling_sub1 = {};

//Scroller constructor
Scrolling_sub1.Scroller_sub1 = function (o, w, h, t) {
	//get the container
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className.indexOf("Scroller_sub1-Container_sub1") > -1) {
			o = list[i];
		}
	}
	
	//private variables
	var self1  = this;
	var _vwidth1   = w;
	var _vheight1  = h;
	var _twidth1   = o.offsetWidth
	var _theight1  = o.offsetHeight;
	var _hasTween1 = t ? true : false;
	var _timer1, _x, _y;
	
	//public variables
	this.onScrollStart1 = function (){};
	this.onScrollStop1  = function (){};
	this.onScroll1      = function (){};
	this.scrollSpeed1   = 50;
	
	//private functions
	function setPosition1 (x, y) {
		if (x < _vwidth1 - _twidth1) 
			x = _vwidth1 - _twidth1;
		if (x > 0) x = 0;
		
		//alert(y+'.........'+size_div)
		
		if(y < size_div)
		{
			if (y < _vheight1 - size_div) 
				y = _vheight1 - size_div;		
		}

		if (y > 0) y = 0;
		
		
		_x = x;
		_y = y;
		
		o.style.left = _x +"px";
		o.style.top  = _y +"px";
	};
	

	//public functions
	this.scrollBy1 = function (x, y) {
		if(_y == size_div)
		{
			this.stopScroll1();
			this.reset();
		}


			setPosition1(_x - x, _y - y);
			this.onScroll1();
		
	};
	
	this.scrollTo1 = function (x, y) { 
		setPosition1(-x, -y);
		this.onScroll1();
	};
	
	this.startScroll1 = function (x, y) {
		this.stopScroll1();
		this.onScrollStart1();
		_timer1 = window.setInterval(
			function () { self1.scrollBy1(x, y); }, this.scrollSpeed1
		);
	};
		
	this.stopScroll1  = function () { 
		if (_timer1) window.clearInterval(_timer1);
		this.onScrollStop1();
	};
	
	this.reset = function () {
		_twidth1  = o.offsetWidth
		_theight1 = o.offsetHeight;
		_x = 0;
		_y = 0;
		
		o.style.left = "0px";
		o.style.top  = "0px";
		
		if (_hasTween1) t.apply(this);
	};
	
	this.swapContent = function (c, w, h) {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("Scroller_sub1-Container_sub1") > -1) {
				o = list[i];
			}
		}
		
		if (w) _vwidth1  = w;
		if (h) _vheight1 = h;
		this.reset();
	};
	
	this.getDimensions = function () {
		return {
			vwidth  : _vwidth1,
			vheight : _vheight1,
			twidth  : _twidth1,
			theight : _theight1,
			x : -_x, y : -_y
		};
	};
	
	this.getContent = function () {
		return o;
	};
	
	this.reset();
};