

// scroller object
function textScroller(v_id, v_cid, v_obj, v_loop){
	this.d_element = document.getElementById(v_id);
	this.d_width = this.d_element.offsetWidth;
	this.c_width = document.getElementById(v_cid).offsetWidth;
	this.scroll_loop = v_loop;
	if(this.scroll_loop){
		this.x = this.c_width;
	} else {
		this.x = 0;
	}
	this.scroll_amt = 1;
	this.scroll_dir = -1;
	this.obj = v_obj;
	this.timer = 0;
	this.scroll = function(){
		if((this.scroll_loop && this.x > -this.d_width) || ((this.scroll_dir == -1 && this.x - this.c_width > -this.d_width) || (this.scroll_dir == 1 && this.x + this.c_width < this.c_width))){
			this.move(this.x + this.scroll_amt * this.scroll_dir);
			this.d_element.style.visibility = 'visible';
			this.timer = setTimeout(this.obj + '.scroll()', 50);
		} else {
			if(this.scroll_loop){
				this.move(this.c_width);
			} else {
				this.scroll_dir *= -1;
			}
			this.d_element.style.visibility = 'visible';
			this.timer = setTimeout(this.obj + '.scroll()', 50);
		}
	};
	this.move = function(new_x){
		this.x = new_x;
		this.d_element.style.left = this.x + 'px';
	};
	this.scrollLeft = function(){
		if(!this.scroll_loop){
			if(this.scroll_dir == -1){
				this.incSpeed();
			} else {
				this.scroll_amt = 1;
				this.scroll_dir = -1;
			}
		}
	};
	this.scrollRight = function(){
		if(!this.scroll_loop){
			if(this.scroll_dir == 1){
				this.incSpeed();
			} else {
				this.scroll_amt = 1;
				this.scroll_dir = 1;
			}
		}
	};
	this.incSpeed = function(){
		if(this.scroll_amt < 4){
			this.scroll_amt++;
		} else {
			this.scroll_amt = 1;
		}
	};
}

// google maps and image stuff
function showMap(address){
	if (!document.getElementById('listimg')) return;
	
	if (GBrowserIsCompatible()) {
		var gmap = new GMap2(document.getElementById("listimg"));
		gmap.addControl(new GSmallMapControl());
		var geocoder = new GClientGeocoder();

		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert('Sorry, no map is currently available for this location.');
				} else {
					gmap.setCenter(point, 13);
					var marker = new GMarker(point);
					gmap.addOverlay(marker);
				}
			}
		);
	}
}

function officeMap(address){
	if (!document.getElementById('officemap')) return;
	document.getElementById('officemap').style.display = 'block';
	
	if (GBrowserIsCompatible()) {
		var gmap = new GMap2(document.getElementById("officemap"));
		gmap.addControl(new GSmallMapControl());
		var geocoder = new GClientGeocoder();

		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					document.getElementById('officemap').style.display = 'none';
				} else {
					gmap.setCenter(point, 13);
					var marker = new GMarker(point);
					gmap.addOverlay(marker);
				}
			}
		);
	}

}

function showImg(src){
	if (!document.getElementById('listimg')) return;
	document.getElementById('listimg').style.backgroundColor = 'transparent';
	document.getElementById('listimg').innerHTML = '<img src="' + src + '" />';
}

// listing details popup
function showDetails(id){
	
	window.open('ListingDetailsPopup.aspx?id=' + id, '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,status=0,menubar=0,resizable=0,width=620,height=480');
	
}

function showIDXDetails(id){
	
	window.open('IDXDetailsPopup.aspx?id=' + id, '_blank', 'toolbar=0,scrollbars=1,location=0,statusbar=0,status=0,menubar=0,resizable=0,width=620,height=480');
	
}

// global img scroller
var img_scroller;

function initImgScroller(firstImg){
	document.getElementById('listimg').innerHTML = '<img src="' + firstImg + '" />';
	img_scroller = new textScroller('imglist', 'imglistwindow', 'img_scroller', 0);
	img_scroller.scroll();
}