function WrapperObject (name, id, speed) {
	this.id = id;
	this.normalSpeed = speed;
	this.name = name;

	this.out = true;
	this.scrol = true;
	this.inb = true;
	this.descr;
	this.h;
	this.num;
	this.min = 6;
	this.max;
	this.gallery_width
	this.content_width;
	this.maxSpeed = 25;
	this.minShift = 0;
	this.speed = this.normalSpeed;
	this.coord = 0;
	this.winW;
	this.maxShift
	this.deltaShift;
	this.paddingLeft = 4;

	this.j_obj = $("#"+this.id+"_wrapper"); // document.getElementById (this.id+"_wrapper"); // $("#banners212_wrapper").get(0);
	this.obj = this.j_obj.get(0);
	this.j_c_obj = $("#"+this.id); // document.getElementById (this.id);
	this.c_obj = this.j_c_obj.get(0);
	// h = obj;

	this.my_resize ();
	this.timer = setInterval(name+'.scroll();',1);


	eval ("this.j_obj.mouseenter(function(){"+name+".f_mouseenter();})"); 
	eval ("this.j_obj.mouseleave(function(){"+name+".f_mouseleave();})"); 
	eval ("this.j_obj.mousemove(function(e){"+name+".f_mousemove(e);})"); 

	/*
	var hEls = this.c_obj.getElementsByTagName("LI"); 
	for (var i=0, len=hEls.length; i<len; i++) { 
		hEls[i].onmouseover=function() { 
			this.className+=" jshover"; 
		}; 
		hEls[i].onmouseout=function() {
			this.className=this.className.replace(" jshover", ""); 
		} 
	}
	*/
}

WrapperObject.prototype.f_mouseenter = function() {
	this.out=false;
}
WrapperObject.prototype.f_mouseleave = function() {
	this.out=true;
	this.speed=this.speed < 0 ? - this.normalSpeed : this.normalSpeed;
}
WrapperObject.prototype.f_mousemove = function(e) {
	if (! this.scrol) 
		return;
	
	var mouseX;
	var shift;
	var perShift;
	var speedShift;

	mouseX = e.pageX ? e.pageX : (event.clientX + document.body.scrollLeft);
	shift = mouseX - this.maxShift;
	perShift = (Math.abs(shift) - this.minShift) / this.deltaShift;
	if (perShift < 0) { 
		this.speed = 0; 
	} else {
		speedShift = perShift * perShift * this.maxSpeed;
		this.speed = shift < 0 ? - speedShift : speedShift;
	}
}

WrapperObject.prototype.scroll = function () {
	if (this.scrol) {
		this.max = this.content_width - this.gallery_width;

		if (this.out) {
			this.obj.scrollLeft += this.speed;
	//		$("#staff_about").css("display", "none");
			if (this.obj.scrollLeft >= this.max - 5)
				this.speed=-Math.abs(this.speed);
			if (this.obj.scrollLeft <= 0)
				this.speed=Math.abs(this.speed);
		} else {
			if (this.speed > 0 && this.obj.scrollLeft < this.max)
				this.obj.scrollLeft += this.speed;
			else if (this.speed < 0 && this.obj.scrollLeft > 0) {
				this.obj.scrollLeft += this.speed;
			}
		}
	} else {
		if (this.out) {
			this.max = this.gallery_width - this.content_width - this.min;

			this.paddingLeft += this.speed;
			if (this.paddingLeft >= this.max)
				this.speed=-Math.abs(this.speed);
			if (this.paddingLeft <= 0)
				this.speed=Math.abs(this.speed);

			this.j_obj.css("padding-left", paddingLeft + "px")
		}
	}
}

WrapperObject.prototype.my_resize = function () {
	this.winW = $(window).width() - 2;
	if (! ie) {
		this.winW = this.winW - parseInt(this.j_obj.css("padding-right")) - parseInt(this.j_obj.css("padding-left"));
	}
// alert (this.winW + " " + $(window).width() + " " + $(document).width()); 

	this.maxShift = Math.round(this.winW/2);
	this.deltaShift = this.maxShift - this.minShift - 100;

	this.gallery_width = parseInt(this.j_obj.css("width"));

	c_width = 4; // + 96;
	this.j_c_obj.children().each(function(){
		c_width += $(this).outerWidth({'margin':'true'});
	});
	this.content_width = c_width;

	this.j_obj.css("width", this.winW + "px" );
	this.j_c_obj.css("width", this.content_width + "px");

	this.scrol = this.content_width > this.gallery_width + 5;
}



var ff = false;
var ie = true;
jQuery.each(jQuery.browser, function(i, val) {
	if($.browser.mozilla || $.browser.safari)
		ff = true;
	if($.browser.mozilla || $.browser.safari || $.browser.opera)
		ie = false;
});

/*
	var b = ""
	jQuery.each(jQuery.browser, function(i, val) {
		b = b + i + " : " + val + "\n";
	});
	alert (b);
*/

$(document).ready(function(){
//	wrap1 = new WrapperObject ("wrap1", "banners212_1", 2);
//	wrap2 = new WrapperObject ("wrap2", "banners212_2", 4);
//	wrap3 = new WrapperObject ("wrap3", "banners212_3", 3);
//	wrap4 = new WrapperObject ("wrap4", "banners212_4", 5);

//	$(window).resize(function(){my_resize ();});
//	wrap1 = new WrapperObject ('wrap1', 'banners212_1', 1);
});

