
if(!Function.prototype.bind)
{
	Function.prototype.bind = function(object) {
	    var method = this
	    return function() {
	        return method.apply(object, arguments) 
	    }
	}
}


var bar = function() {};
bar.prototype = {
	poscount: 0,
	allcount: 0,
	bitems : [],
	itemrefs : {},
	classes : ['nf', 'fn', 'er', 'st', 'nu','ns','bl'],
	bar_container : null,
	str_container : null,
	
	deploy : function(barlength, elid, stid, vi) {
		this.allcount = barlength;
		this.bar_container = document.getElementById(elid);
		this.str_container = document.getElementById(stid);
		var item = null;
		var i = 0;
		if(this.bar_container)
		{
			for(i = 1; i <= barlength; i++)
			{
				item = document.createElement('img');
				item.style.width = (600 / this.allcount) - 1;
				item.src = vi;
				this.bar_container.appendChild(item);
				this.bitems[i] = {'Name' : '', 'Class' : 4,  'Time' : -1, 'Ref' : item};
				this.itemrefs[item] = i;
				this.apply_item(i);
			}
		}
	},
	
	set_item : function(itemid, itemname, itemclass, itemtime, pos_count) {
		if(this.bitems[itemid])
		{
			this.bitems[itemid]['Name'] = itemname;
			this.bitems[itemid]['Class'] = itemclass; 
			if(itemclass == 3)
			{
				this.bitems[itemid]['Time'] = 'Поиск временно не производится';
			}
			else if(itemclass == 2)
			{
				this.bitems[itemid]['Time'] = 'данные не удалось получить';
			}
			else if(itemclass == 6)
			{
				this.bitems[itemid]['Time'] = 'Склад в черном списке';
			}
			else
			{
				this.bitems[itemid]['Time'] = 'данные получены за ' + itemtime + ' сек.';
			}
			
			this.bitems[itemid]['Ref'].onmouseover = new Function("","sebar.item_display('"+itemid+"')").bind(this);
			this.bitems[itemid]['Ref'].onclick = new Function("","document.location='#f"+itemid+"';").bind(this);
			this.bitems[itemid]['Ref'].onmouseout = this.clear_str.bind(this);
			this.apply_item(itemid);
			document.getElementById('bar_percent').innerHTML = Math.round(itemid /(this.allcount/100)) + '%';
			if(itemid < this.allcount && itemclass != 5)
			{
				this.set_item(itemid+1, '', 5, -1, 0);
			}
		}
	},
	
	apply_item : function (itemid) {
		if(this.bitems[itemid])
		{
			this.bitems[itemid]['Ref'].className = this.classes[this.bitems[itemid]['Class']];
		}
	},
	
	item_display: function (itemid)
	{
		if(this.str_container)
		{
			this.str_container.innerHTML = '<b>' + this.bitems[itemid]['Name'] + '</b> &mdash; ' + this.bitems[itemid]['Time'];
		}
	},
	
	clear_str: function() {this.str_container.innerHTML = '&nbsp;';}
}
