var Featured = function(cDiv,divWidth,divHeight,speed,interval,spacer,endSpacer,divBorder,propObj,bUrl){
	this.baseUrl = bUrl; // base url set on the featured properties page
	this.propObj = propObj; //this is the JSON object made on hte featured properties page
	this.divBorder=divBorder; // container div border if any this is needed and required for sizing the div corectly
	this.mainDiv=cDiv; // this is your main container div element
	this.divWidth=divWidth; // main container div width... 
	this.divHeight=divHeight-this.divBorder*2;  // main container div height calculations
	this.speed=speed; // this is the main speed in pixels 
	this.intTime=interval; // time in milleseconds betwween the speed in pixels
	this.spacer=spacer; // space between the properties in pixels
	this.endSpace=endSpacer; // the space between the begining and ending properties
	this.mainOffSetDuh=0; // offset if needed you probably dont have to change this at all
	this.holder=null; //dont worry about it
	this.tmpHolder=null; //dont worry about it
	this.mainPropArray=new Array(); //dont worry about it
	this.init(); //dont worry about it
};
Featured.prototype = {
	init:function(){
	// format currency
		this.mainPropArray = this.setupPropArray(this.propObj);
		var tmpMainDiv=document.getElementById(this.mainDiv);
		var that=this;
		if((typeof(tmpMainDiv)=='undefined')||(tmpMainDiv==null)){
			setTimeout(function(){that.init()},300);
			return;
		};
		tmpMainDiv.innerHTML=this.buildHtml();
		setTimeout(function(){that.setup()},300);
	},
	stopIt:function(){
		clearInterval(doInterval);
	},
	startIt:function(){
		var that=this;
		doInterval = setInterval(function(){that.doAnimation()},this.intTime);
	},
	setup:function(){
		this.holder=document.getElementById('holder');
		this.tmpHolder=document.getElementById('tmpHolder');
		var mainSpan=document.getElementById('mainSpan');
		var that=this;
		if((typeof(this.holder)=='undefined')||(this.holder==null)||(typeof(this.tmpHolder)=='undefined')||(this.tmpHolder==null)||(typeof(mainSpan)=='undefined')||(mainSpan==null)){
			setTimeout(function(){that.setup()},300);
			return;
		};
		this.holder.innerHTML=this.buildPropArray();
		this.tmpHolder.innerHTML=this.buildPropArray();
		this.mainOffSetDuh=mainSpan.offsetWidth;
		this.tmpHolder.style.left=this.mainOffSetDuh+this.endSpace+'px';
		
		YAHOO.util.Event.addListener(document.getElementById(this.mainDiv), "mouseover", function(){
			that.stopIt();																	  
		}); 
		YAHOO.util.Event.addListener(document.getElementById(this.mainDiv), "mouseout", function(){
			that.startIt();
		}); 
		for(var i=0;i<this.mainPropArray.length;i++){
		
		};
		this.startIt();
	},
	buildHtml:function(){
		var newHtml=new Array();
		newHtml[newHtml.length]='<span id="mainSpan" style="visibility:hidden;position:absolute;left:-1999px;top:-1999px">'+this.buildPropArray()+'</span>';
		newHtml[newHtml.length]='<table border="0" cellspacing="0" cellpadding="0"><tr><td>';
		newHtml[newHtml.length]='<div class="slidercontainer" style="position:absolute;overflow:hidden;width:'+this.divWidth+'px;height:'+this.divHeight+'px;">';
		newHtml[newHtml.length]='<div id="holder" style="position:absolute;left:0px;top:0px"></div>';
		newHtml[newHtml.length]='<div id="tmpHolder" style="position:absolute;left:-1999px;top:0px"></div>';
		newHtml[newHtml.length]='</div>';
		newHtml[newHtml.length]='</td></tr></table>';
		return newHtml.join('');
	},
	buildPropArray:function(){
		var props=new Array();
		props[props.length]='<nobr>';
		props[props.length]='<table border="0" cellspacing="0" cellpadding="0"><tr>';
		for(var i=0;i<this.mainPropArray.length;i++){
			props[props.length]='<td>';
			props[props.length]='<div class="sliderimages" id="'+this.mainPropArray[i][1]+'">';
			props[props.length]='<a href="'+this.baseUrl+this.mainPropArray[i][1]+'" target="_self">';
			props[props.length]='<img class="featured-image" src="'+this.mainPropArray[i][0]+'" alt="'+this.mainPropArray[i][1]+'" width="'+this.mainPropArray[i][4]+'" height="'+this.mainPropArray[i][5]+'" border="0" />';
			props[props.length]='</a>';
			props[props.length]='<div class="detail-link"><a href="'+this.baseUrl+this.mainPropArray[i][1]+'" target="_self">Click for details</a></div>';
			props[props.length]='<div class="offered-price">'+this.mainPropArray[i][6]+'</div>';
			props[props.length]='<div class="city-state">'+this.mainPropArray[i][7]+'</div>';
			props[props.length]='</div>';
			props[props.length]='</td>';
			props[props.length]='<td><div style="width:'+this.spacer+'px;height:1px;border:0 none transparent;"></div></td>';
		};
		props[props.length]='</tr></table>';
		props[props.length]='</nobr>';
		return props.join('');
	},
	doAnimation:function(){
		if(parseInt(this.holder.style.left)>(this.mainOffSetDuh*(-1)+9)){
			this.holder.style.left=parseInt(this.holder.style.left)-this.speed+'px';
		}else{
			this.holder.style.left=parseInt(this.tmpHolder.style.left)+this.mainOffSetDuh+this.endSpace+'px';
		};
		if(parseInt(this.tmpHolder.style.left)>(this.mainOffSetDuh*(-1)+9)){
			this.tmpHolder.style.left=parseInt(this.tmpHolder.style.left)-this.speed+'px';
		}else{
			this.tmpHolder.style.left=parseInt(this.holder.style.left)+this.mainOffSetDuh+this.endSpace+'px';
		};
	},
	formatCurrency:function(num){
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num)) num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10) cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + '$' + num);	
	},
	setupPropArray:function(oProp){
		tmpArray = oProp;
		for(var i=0;i<tmpArray["ROWCOUNT"];i++){
			price = this.formatCurrency(tmpArray['DATA']['listing_price'][i]);
			thumbUrl = tmpArray['DATA']['thumbnail_url'][i];
			propId = tmpArray['DATA']['property_id'][i];
			tmpCity = tmpArray['DATA']['city'][i];
			if(tmpCity.length > 12){
				tmpCity = tmpCity.substring(0,10) + "...";
			};
			cityState = tmpCity+", "+tmpArray['DATA']['state'][i];
			this.mainPropArray.push([thumbUrl,propId,'_self','alt-text',100,80,price,cityState]);
		};
		return this.mainPropArray;
	}
}
var sliderReady=true;