function galleryWork(obj_id, count_visible_photo, offset) {
    this.obj_id = obj_id;
    this.obj = false;
    this.position = 0;
    this.finish_position = 0;
    this.count_visible_photo = count_visible_photo;
    this.offset = offset;
    this.timer = false;
    this.runON = true;
}

galleryWork.prototype.initialize = function () {
    if(!this.obj){
	this.obj = document.getElementById(this.obj_id);
	//считаем количество картинок
	this.finish_position = this.obj.getElementsByTagName('img').length;
	this.finish_position = -(this.finish_position-this.count_visible_photo)*this.offset;
	// Добавляем обработчики для колесика
	/* Gecko */
	this.addHandler(this.obj, 'DOMMouseScroll', function(o){return function(event){o.wheel(event)}}(this));
	/* Opera */
	this.addHandler(this.obj, 'mousewheel', function(o){return function(event){o.wheel(event)}}(this));
	/* IE */
	this.addHandler(this.obj, 'mousewheel', function(o){return function(event){o.wheel(event)}}(this));
	}
}

galleryWork.prototype.go = function (type) {
    if(this.runON){
	if(this.position == 0 && type == 'left')
	    return false;

	if(this.position == this.finish_position && type == 'right')
	    return false;
	
	this.movements(type, 0);
    }

 return false;
}

galleryWork.prototype.movements = function (type, i) {
    if(type == 'left')
	var delta = 5;
    else if(type == 'right')
	var delta = -5;
    else
	return false;

    if((delta > 0 && i < this.offset) || (delta < 0 && i > -this.offset)){
	
	this.runON = false;

	i+=delta;
	
	this.position += delta;

	this.obj.style.left = (this.position)+'px';

	var obj = {global_obj : this};

	this.timer = window.setTimeout(function () {obj.global_obj.movements(type, i)}, 1);
    }else{
	window.clearTimeout(this.timer);
	this.runON = true;
    }

 return false;
}

galleryWork.prototype.wheel = function(event) {
    var delta; // Направление скролла
    // -1 - скролл вниз
    // 1  - скролл вверх
    event = event || window.event;
    // Opera и IE работают со свойством wheelDelta
    if (event.wheelDelta) {
        delta = event.wheelDelta / 120;
        // В Опере значение wheelDelta такое же, но с противоположным знаком
        if (window.opera) delta = -delta;
    // В реализации Gecko получим свойство detail
    } else if (event.detail) {
        delta = -event.detail / 3;
    }
    // Запрещаем обработку события браузером по умолчанию
    if (event.preventDefault)  event.preventDefault();
    event.returnValue = false;
   
    if(delta>0){
	this.go('left');
    }
    else{
	this.go('right');
    }
    
    return false;
}


//Функция для добавления обработчика событий
galleryWork.prototype.addHandler = function(object, event, handler, useCapture) {
    if (object.addEventListener) {
        object.addEventListener(event, handler, useCapture ? useCapture : false);
    } else if (object.attachEvent) {
        object.attachEvent('on' + event, handler);
    } else alert("Add handler is not supported");
}


