
function Cars(){
	this.m_items = null;
	this.m_idx = -1;
	this.m_numberOfPhotos = 0;
	this.m_leftArrow = null;
	this.m_rightArrow = null;
	this.m_leftArrowT = null;
	this.m_rightArrowT = null;
}

Cars.prototype.onDocReady = function(){
	var self = this;
	
	this.m_items = $(".detailPhotosContainer .photo");
	this.m_numberOfPhotos = this.m_items.size();

	this.m_leftArrow = $(".arrowLeft");
	this.m_rightArrow = $(".arrowRight");
	this.m_leftArrowT = $(".arrowLeftT");
	this.m_rightArrowT = $(".arrowRightT");
	
	this.m_leftArrow.bind('click', function () { self.onLeftArrowClick(); });
	this.m_rightArrow.bind('click', function () { self.onRightArrowClick(); });
	this.m_leftArrowT.bind('click', function () { self.onLeftArrowTClick(); });
	this.m_rightArrowT.bind('click', function () { self.onRightArrowTClick(); });
	
	$("#numAll").html(this.m_numberOfPhotos);
	this.showPhoto(0);
}

Cars.prototype.showPhoto = function(idx){
	var self = this;
	
	if(this.m_idx != -1)
		this.m_items.eq(self.m_idx).css("display", "none");
		
	this.m_idx = idx;
	
	$("#num").html(this.m_idx + 1);
	
	this.m_items.eq(self.m_idx).css("display", "inline");
}

Cars.prototype.onLeftArrowClick = function(){
	var self = this;
	
	if(self.m_idx == 0)
		return;
	
	this.showPhoto(self.m_idx - 1);
}

Cars.prototype.onRightArrowClick = function(){
	var self = this;
	
	if(self.m_idx == self.m_numberOfPhotos - 1)
		return;
	
	this.showPhoto(self.m_idx + 1);
}

Cars.prototype.onLeftArrowTClick = function(){
	var self = this;
	
	this.showPhoto(0);
}

Cars.prototype.onRightArrowTClick = function(){
	var self = this;
	
	this.showPhoto(self.m_numberOfPhotos - 1);
}

////////////////////////////////////////////////////////////////////////////
// one and only
// 
var g_cars = new Cars();

$(document).ready(function(e){

	g_cars.onDocReady();

});
