function FeatBoxImpl() {
	
	// statics
	var initalLoadSize = 25, initalPosition = 13, prefetchLoadSize = 6;

	// dynamic
	var prefetchCounter = 0;
	var FeatBox;
		
	this.setup = function setup() {
		
		FeatBox = new CFeatBox('featbox-home', {
			
	        listener: function(name, p1, p2, p3, p4){
	            			
				/*
				if( window.console ) {
					console.debug('[' + name + '] queP: ' + p1.position + ", currI: " + p2 + ", prevI:" + p3 + ", forw?:" + p4 + ' , arrL:' + this.Objs.length);
				}
				*/

	            // Notable Variables
	            // this.Objs    objects queue
	            // this.pos     index of the object being shown
	            // this.photow  photo display width
	            // this.photoh  photo display height
	            
	            switch(name){
	            	case 'add': // object add. p1 = object being added
	            		break;
	                case 'remove':      // object removal. p1 = object being removed
	                    break; 
	                case 'change':      // when the listing being shown changes. p1: object being show. p2: current index. p3: previous index. p4: is moving forward TRUE/FALSE
	                	
	                	var queuePosition = p1.position;
	                	var currentIndex = p2;
	                	var previousIndex = p3;
	                	var moveForward = p4;
	                	
	                	moveForward ? prefetchCounter++ : prefetchCounter--;
	                	
	                	if (prefetchLoadSize == Math.abs(prefetchCounter)) {
	                		              		
		                	if (moveForward) {
		                		
		                		var reqPosStart;
		                		var reqIndex = currentIndex + prefetchLoadSize;
		                		if (reqIndex > this.Objs.length) {
		                			var leftOver = reqIndex - this.Objs.length;
		                			reqPosStart = this.Objs[leftOver].position;
		                		} else {
		                			reqPosStart = this.Objs[reqIndex].position;
		                		}
		                		
		                		readNext( reqPosStart );
		                		
		                	} else {
		                		
		                		var reqPosStart;
		                		var reqIndex = currentIndex - prefetchLoadSize;
		                		if (reqIndex < 0) {
		                			var leftOver = this.Objs.length + reqIndex;
		                			reqPosStart = this.Objs[leftOver].position;
		                		} else {
		                			reqPosStart = this.Objs[reqIndex].position;
		                		}
		                		
		                		readPrevious( reqPosStart );
		                		
		                	}
	                		prefetchCounter = 0;
	                	}
	                	
	                    break;
	                case 'photoerror':  // photo downloading error
	                    break;
	                case 'photoloaded': // object being added, photo downloaded. p1: success. p2: object being loaded. p3: image jQuery object. 
	                    break;
	                case 'isloaded':    // when show() gets called.  Initiation.
	                    break;
	                case 'isplaying':   // user clicks play/pause.  p1: TRUE = playing, FALSE = pausing
	                    break;
	                }
	            },
	        autoplay: true,
	        defaultsrc: "/resources/eda49c056d/images/vrfresh/featbox-nophoto.jpg",
	        max: initalLoadSize,
	        pos: initalPosition,
	        timer: 5000,
	        debug: false,
	        disableSlide: true
	        });
		
		readInitial();
	}
	
	var readInitial = function readInitial() {
		handleAjaxRequest('initial.htm?regionNavId=0&numResults=' + initalLoadSize, handleAjaxInitialSuccess);
	}
		
	var readNext = function readNext(position) {
		handleAjaxRequest('next.htm?regionNavId=0&numResults=' + prefetchLoadSize + '&lastPosition='+position, handleNextAjaxSuccess);
	}
	
	var readPrevious = function readPrevious(position) {
		handleAjaxRequest('previous.htm?regionNavId=0&numResults=' + prefetchLoadSize + '&lastPosition='+position, handlePreviousAjaxSuccess);
	}
	
	function handleAjaxRequest(url, callback) {
		
		$.ajax({
			type: 'GET',
			cache: false,
			url: '/queue/' + url,
			success: callback,
			dataType: 'json',
			error : handleAjaxError 
		});
		return false;
	}
	
	function handleAjaxInitialSuccess(data) {

		FeatBox.show(convertToArray(data));
	}
	
	function handleNextAjaxSuccess(data) {
		
		FeatBox.add(convertToArray(data), false);
	}
	
	function handlePreviousAjaxSuccess(data) {
		
		FeatBox.add(convertToArray(data).reverse(), true);
	}
		
	function convertToArray(spotlights) {
		var featObjs = new Array;
		$(spotlights).each(function(){
			featObjs.push(convert(this));
		});
		return featObjs;
	}
	
	function convert(spotlight) {
		return {
			position: spotlight.position,
		    id: spotlight.listingId,
		    name: spotlight.propertyName,
		    url: spotlight.propertyLink + "?promoType=spotlight",
		    summary: spotlight.summary,
		    photosrc: spotlight.imageSrc,
		    photoalt: spotlight.imageAlt,
		    hasfreebie: spotlight.hasFreebie,
		    hassavings: spotlight.hasSaving,
		    toString: function() {
		    	return "Object["+spotlight.position+"]";
		    }
		}
	}
	
	function handleAjaxError(XMLHttpRequest, textStatus, errorThrown) {
		if (textStatus == 'timeout') {
			if(window.console) {
				console.debug('The request took too long. Please try again.');
			}
		} else {
			console.debug('An error occured. Please try again or contact customer support.');
		}
	}
	
}

function sendContainerTracking() {
	sendContainerClickedOmniture('HP', 'R1', 'C1');
	return true;
}

$(document).ready(function() {
	$('#search-form').submit(function() {
		setSendOmnitureDate();
		$.cookie("VR_OMNITURE_MULTISEARCH", "NewSearch", {
			path : '/vacation-rentals/'
		});
	});

});



