function initCurrListings(list_images)
{
	var cl = new CurrentListings(
		4, 
		document.getElementById('listBtnLeft'), 
		document.getElementById('listBtnRight'),
		list_images
	);
}

function associateObjWithElem(obj, methodName, params)
{
	return (function(e) {
		e = e || window.event;
		return obj[methodName](e, obj, params);
	});
}

function CurrentListings(num_listings, btn_left, btn_right, list_images)
{
	this.btn_left = btn_left;
	this.btn_right = btn_right;
	
	this.btn_left.onclick = associateObjWithElem(this, "shiftLeft", []);
	this.btn_right.onclick = associateObjWithElem(this, "shiftRight", []);

	this.list_images = list_images;

	this.img = new Array();
	this.price = new Array();
	this.listhrefimage = new Array();
	this.listhreftext = new Array();
	for (var i = 0; i < 4; i++) {
		this.img.push(document.getElementById('listImage[' + i + ']'));
		this.price.push(document.getElementById('listPrice[' + i + ']'));
		this.listhrefimage.push(document.getElementById('listHrefImage[' + i + ']'));
		this.listhreftext.push(document.getElementById('listHrefText[' + i + ']'));
	}

	this.curr_img = 0;
	this.reloadImages();
}

CurrentListings.prototype.reloadImages = function()
{
	for (var i = 0; i < this.img.length; i++) {
		this.img[i].src = this.list_images[(i + this.curr_img) % this.list_images.length][0];
		this.price[i].innerHTML = this.list_images[(i + this.curr_img) % this.list_images.length][1];
		this.listhrefimage[i].href = this.listhreftext[i].href = 'listing?id=' + this.list_images[(i + this.curr_img) % this.list_images.length][2];
	}
}

CurrentListings.prototype.shiftLeft = function(e, obj, params)
{
	obj.curr_img--;
	if (obj.curr_img < 0)
		obj.curr_img = this.list_images.length - 1;

	obj.reloadImages();
}

CurrentListings.prototype.shiftRight = function(e, obj, params)
{
	obj.curr_img = (obj.curr_img + 1) % obj.list_images.length;
	obj.reloadImages();
}