var MostViewedItems = Class.create({
	initialize: function(items, container) {
		this.items = items;
		this.container = container;
		this.current = 0;
		
		var linkLeft = new Element('a',{id:container+'-left',href:'javascript:;',tabindex:'0'});
		linkLeft.className = (this.current > 0)?'mviLeft1':'mviLeft0';
		linkLeft.observe('click', this.goPrevios.bind(this)); 
		
		var linkRight = new Element('a',{tabIndex:'0',id:container+'-right',href:'javascript:;'});
		linkRight.className = (this.current < this.items.length - 1)?'mviRight1':'mviRight0';
		linkRight.observe('click', this.goNext.bind(this)); 
		
		var img_url = imageUrl(this.items[this.current].dealer,items[this.current].id,items[this.current].image,193,156);
		var imgCont = new Element('div', {className:'mviImage',id:container+'-img'});
		imgCont.setStyle({cursor:'pointer',_cursor:'hand',background:'url() 50% 50%'});
		imgCont.appendChild(new Element('div').update(this.current+1));
		imgCont.observe('click', this.goLink.bind(this));
		
		$(this.container).appendChild(linkLeft);
		$(this.container).appendChild(imgCont);
		$(this.container).appendChild(linkRight);
		
		new ImagesLoader(this.container+'-img', img_url);		
	},
	goLink: function() {
		window.location = _base_url + 'p/' + this.items[this.current].id + '/' + this.items[this.current].title;
	},
	goNext: function() {
		if (this.current < this.items.length - 1) {
			this.current++;
			this.render();
		}
	},
	goPrevios: function () {
		if (this.current > 0) {
			this.current--;
			this.render();
		}
	},
	render: function() {
		var linkLeft = $(this.container+'-left');
		linkLeft.className = (this.current > 0)?'mviLeft1':'mviLeft0';

		var linkRight = $(this.container+'-right');
		linkRight.className = (this.current < this.items.length - 1)?'mviRight1':'mviRight0';

		var img_url = imageUrl(this.items[this.current].dealer,items[this.current].id,items[this.current].image,193,156);
		new ImagesLoader(this.container+'-img', img_url);
		
		$$('#' + this.container+'-img div')[0].update(this.current+1);
	}
});
