jQuery(function() {
	// first
	var firstGallery = new indexGallery(fnew,"box1");
	jQuery(".featured-vehicles .box1 .nav-next a").click(function() {
		firstGallery.next();
		return false;
	}).css("")
	jQuery(".featured-vehicles .box1 .nav-prev a").click(function() {
		firstGallery.prev();
		return false;
	})	
	firstGallery.bind();
	
	
	// second
	var secondGallery = new indexGallery(fused,"box2");
	jQuery(".featured-vehicles .box2 .nav-next a").click(function() {
		secondGallery.next();
		return false;
	}).css("")
	jQuery(".featured-vehicles .box2 .nav-prev a").click(function() {
		secondGallery.prev();
		return false;
	})	
	secondGallery.bind();
	
	// first
	var thirdGallery = new indexGallery(fcert,"box3");
	jQuery(".featured-vehicles .box3 .nav-next a").click(function() {
		thirdGallery.next();
		return false;
	}).css("")
	jQuery(".featured-vehicles .box3 .nav-prev a").click(function() {
		thirdGallery.prev();
		return false;
	})	
	thirdGallery.bind();
})

indexGallery = function(imagesArray,blockId)
{
	return {
		imagesArray: imagesArray,
		blockId: blockId,
		current: 0,
		count: 0,
		bind: function()
		{
			this.count = this.imagesArray.length;
			
			
		},
		show: function(ind)
		{
			this.current = ind;
			
			jQuery(".featured-vehicles ."+blockId+" .imageContainer .loader").show();
			imgEl = jQuery(".featured-vehicles ."+blockId+" .image");
			
			img = new Image();
			img.onload = function() {
				//imgEl.css("width",imgEl.width()).css("height",imgEl.height()).html( img );
				jQuery(".featured-vehicles ."+blockId+" .image").html( "<a href='view_vehicle.php?vin="+imagesArray[ind]["vin"]+"'><img src='"+imagesArray[ind]["image"]+"'></a>" );
				jQuery(".featured-vehicles ."+blockId+" .name").html( "<a href='view_vehicle.php?vin="+imagesArray[ind]["vin"]+"'>"+imagesArray[ind]["name"]+"</a>");
				jQuery(".featured-vehicles ."+blockId+" .summary").html( imagesArray[ind]["desc"]);
				jQuery(".featured-vehicles ."+blockId+" .price").html( imagesArray[ind]["price"]);
				jQuery(".featured-vehicles ."+blockId+" .imageContainer .loader").hide();
			}
			img.src = imagesArray[ind]["image"];
			
		},
		next: function()
		{
			if(this.current==this.count-1) this.current = 0;
			else this.current++;
			
			this.show(this.current);
		},
		prev: function()
		{
			if(this.current==0) this.current = this.count -1;
			else this.current--;
			
			this.show(this.current);
		}
	}
}