function promoWork(block_id, block_width, block_height, img_width, img_height){
	this.block_id = block_id;
	this.block_width = block_width;
	this.block_height = block_height;
	this.img_width = img_width;
	this.img_height = img_height;
	
	this.images = new Object();
	this.images_box = new Object();
	this.count=0;
	
	this.current = 0;
	this.opacity = 0.5;
}

promoWork.prototype.addImage = function(path, title, link){
    this.images[this.count] = new Object();
    this.images[this.count]['image'] = new Image();
    this.images[this.count]['image'].src = path;
    this.images[this.count]['title'] = title;
   	this.images[this.count]['link'] = link;
    this.count++;
}

promoWork.prototype.inizialize = function(){
	this.block = document.getElementById(this.block_id);
	this.delta =0;
	var obj = {global_obj : this};
	for(i=0; i<this.count; i++){
		//Создаем картинку
		var image = document.createElement('IMG');
		image.src = this.images[i]['image'].src;
		//Создаем div
		var div_item = document.createElement('DIV');
		div_item.className = 'promo-item-box';
		
		//Создаем Div заголовка
		var div_item_title_box = document.createElement('DIV');
		div_item_title_box.className = 'promo-item-title-block';
		div_item_title_box.style.width = this.img_width+'px';
		
		var div_item_title = document.createElement('DIV');
		div_item_title.className = 'promo-item-title-box';
		div_item_title.style.width = this.img_width+'px';
		div_item_title.innerHTML = '<a href="'+this.images[i]['link']+'">'+this.images[i]['title']+'</a>';
				
		div_item.style.left = (((i == 0) ? 0 : this.img_width)+(i-1)*this.delta)+'px';
		if(i > 0){
			this.delta = (this.block_width - this.img_width)/(this.count-1);
			div_item.style.width = this.delta +'px';
			div_item.className = 'promo-item-box-hide';
		}

		this.images_box[i] = div_item;
		this.images_box[i].number = i;
		this.images_box[i].onclick = function () {obj.global_obj.show(this.number)};
		
		
		div_item.appendChild(div_item_title_box);
		div_item.appendChild(div_item_title);
		div_item.appendChild(image);
		//добавляем в наш DIV
		if(i!=this.current)
			$(div_item).css('opacity', this.opacity);
		this.block.appendChild(div_item);
		
	}
	this.showTitle('show', this.current);
}

promoWork.prototype.show = function(current){
	
	if(this.current < current){
		for(i in this.images_box){
			if(i < current){
				$(this.images_box[i]).animate(
						{left: (i*this.delta)+'px', width: this.delta+'px'}, 
						500, function(){});
				$(this.images_box[i]).css('opacity', this.opacity);
				this.showTitle('hide', i);
			}
		}
	}else{
		for(i in this.images_box){
			if(i > current){
				$(this.images_box[i]).animate(
						{left: ((i-1)*this.delta + this.img_width)+'px', width: this.delta+'px'}, 
						500, function(){});
				$(this.images_box[i]).css('opacity', this.opacity);
				this.showTitle('hide', i);
			}
		}
	}

	$(this.images_box[current]).css('opacity', 1);
	
	$(this.images_box[current]).animate(
			{left: (current*this.delta)+'px', width: this.img_width+'px'}, 
			500, function(){});
	this.showTitle('show', current);
	
	this.current = current;
}

promoWork.prototype.showTitle = function(action, current){
		for(j=0; j<this.images_box[current].childNodes.length; j++){
			if(this.images_box[current].childNodes[j].nodeName=='DIV'){
				$(this.images_box[current].childNodes[j]).animate(
						{height: (action == 'show' ? '50' : '0')+'px'}, 
						500, function(){});

			}
		}
}
