/* -------------------------------------------------------------------------- */
/* ---------------------------------------------------------- property_tabBox */
/* -------------------------------------------------------------------------- */
/* --------------------------------------------------------------------- tabs */
tabChange = new Array();
function property_tabBox_selectTabDelay (tabId) {
	tabChange[tabId] = setTimeout ("property_tabBox_selectTab('"+tabId+"')", 300);
}
function property_tabBox_selectTabKillDelay (tabId) {
	clearTimeout (tabChange[tabId]);
}
function property_tabBox_selectTab (tabId) {
	if (!tabPhotos) {
		var tabPhotos = document.getElementById('property_tabBox_tabPhotos');
		var tabPhotosShadow = document.getElementById('property_tabBox_tabPhotosShadow');
		var contentPhotos = document.getElementById('property_tabBox_contentPhotos');
		var tab360 = document.getElementById('property_tabBox_tab360');
		var tab360Shadow = document.getElementById('property_tabBox_tab360Shadow');
		var content360 = document.getElementById('property_tabBox_content360');
		var tabMap = document.getElementById('property_tabBox_tabMap');
		var tabMapShadow = document.getElementById('property_tabBox_tabMapShadow');
		var contentMap = document.getElementById('property_tabBox_contentMap');
		var tabContact = document.getElementById('property_tabBox_tabContact');
		var tabContactShadow = document.getElementById('property_tabBox_tabContactShadow');
		var contentContact = document.getElementById('property_tabBox_contentContact');
	}
	
	/*var currentTab;
	var currentTabShadow;
	
	if (currentTab.className) {
		currentTab.className = 'title_sub property_tabBox_tab';
	}	
	if (currentTabShadow.className) {
		currentTabShadow.className = 'property_tabBox_tabShadow';
	}*/
	tabPhotos.className = 'title_sub property_tabBox_tab';
	tabPhotosShadow.className = 'property_tabBox_tabShadow';
	contentPhotos.className = 'property_tabBox_content';
	tab360.className = 'title_sub property_tabBox_tab';
	tab360Shadow.className = 'property_tabBox_tabShadow';
	content360.className = 'property_tabBox_content';
	tabMap.className = 'title_sub property_tabBox_tab';
	tabMapShadow.className = 'property_tabBox_tabShadow';
	contentMap.className = 'property_tabBox_content';
	tabContact.className = 'title_sub property_tabBox_tab';
	tabContactShadow.className = 'property_tabBox_tabShadow';
	contentContact.className = 'property_tabBox_content';

	switch (tabId) {
		case 'property_tabBox_tabPhotos':
			tabPhotos.className = 'title_sub property_tabBox_tab property_tabBox_tabSelected';
			tab360Shadow.className = 'property_tabBox_tabShadow property_tabBox_tabLeftShadow';
			contentPhotos.className = 'property_tabBox_contentSelected';
		break;
		case 'property_tabBox_tab360':
			property_tabBox_display360 (current_360);
			tab360.className = 'title_sub property_tabBox_tab property_tabBox_tabSelected';
			tabMapShadow.className = 'property_tabBox_tabShadow property_tabBox_tabLeftShadow';
			content360.className = 'property_tabBox_contentSelected';
			property_tabBox_display360 (0);
			current_360 = 0;
			//property_tabBox_check360 ();
		break;
		case 'property_tabBox_tabMap':
			tabMap.className = 'title_sub property_tabBox_tab property_tabBox_tabSelected';
			tabContactShadow.className = 'property_tabBox_tabShadow property_tabBox_tabLeftShadow';
			contentMap.className = 'property_tabBox_contentSelected';
		break;
		case 'property_tabBox_tabContact':
			tabContact.className = 'title_sub property_tabBox_tab property_tabBox_tabSelected';
			contentContact.className = 'property_tabBox_contentSelected';
		break;
	}
}

/* ------------------------------------------------------------------- photos */
var property_tabBox_photo = new Array();

var property_tabBox_currentPhoto = 0;

function property_tabBox_nextPhoto () {
	newIndex = (property_tabBox_currentPhoto != property_tabBox_photo.length-1) ? property_tabBox_currentPhoto+1 : 0;
	property_tabBox_displayPhoto (newIndex);
}

function property_tabBox_previousPhoto () {
	newIndex = (property_tabBox_currentPhoto != 0) ? property_tabBox_currentPhoto-1 : property_tabBox_photo.length-1;
	property_tabBox_displayPhoto (newIndex);
}

function property_tabBox_displayPhoto (indx) {
	if (property_tabBox_currentPhoto != indx) {
		obj_oldLink = document.getElementById('property_tabBox_photosLink'+property_tabBox_currentPhoto);
		obj_oldBullet = document.getElementById('property_tabBox_photosBullet'+property_tabBox_currentPhoto);
		obj_oldLink.className = 'title_sub property_tabBox_photosLink';
		obj_oldBullet.className = 'property_tabBox_photosBullet';
		
		obj_oldLink = document.getElementById('property_tabBox_photosLink'+indx);
		obj_oldBullet = document.getElementById('property_tabBox_photosBullet'+indx);
		obj_oldLink.className = 'title_sub property_tabBox_photosLinkSelected';
		obj_oldBullet.className = 'property_tabBox_photosBulletSelected';

		img = document.getElementById('property_tabBox_photosImage');
		desc = document.getElementById('property_tabBox_photosDescription');
		a = document.getElementById('property_tabBox_photosLink');
		img.src = property_tabBox_photo[indx]['thumbnail_uri'];
		desc.innerHTML = property_tabBox_photo[indx]['description'];
		a.href = "javascript: property_tabBox_fullsizePhotoPopup ("+indx+");";
		property_tabBox_currentPhoto = indx;
	}
}

function property_tabBox_fullsizePhotoPopup (indx) {
	var fullsizePopup = window.open("", "property_overview_photo", "width=780,height=608");
	var obj_img = fullsizePopup.document.getElementById('fullsize_property_image');
	fullsizePopup.document.title = property_tabBox_photo[indx]['description'];
	fullsizePopup.width = 530;
	fullsizePopup.height = 405;

	if (obj_img) {
		obj_img.src = property_tabBox_photo[indx]['fullsize_uri'];
	} else {
		var obj_img = fullsizePopup.document.createElement('img');
		obj_img.src = property_tabBox_photo[indx]['fullsize_uri'];
		obj_img.id = "fullsize_property_image";
		obj_img.style.width = "758px";
		obj_img.style.height = "586px";
		obj_img.border = "0";
		
		var obj_a = fullsizePopup.document.createElement('a');
		obj_a.href = "javascript: self.close();";
		obj_a.appendChild(obj_img);
		
		fullsizePopup.document.body.setAttribute("style", "margin: 11px 11px 11px 11px;");
		fullsizePopup.document.body.appendChild(obj_a);
	}
	fullsizePopup.focus ();
}

var property_tabBox_photosCurrentShowLinks = false;
function property_tabBox_photosShowLinks () {
	var linksTd = document.getElementById('property_tabBox_photosLinks');
	var img = document.getElementById('property_tabBox_photosShowLinksIcon');
	var td = document.getElementById('property_tabBox_photosShowLinksText');
	if (property_tabBox_photosCurrentShowLinks) {
		linksTd.style.display = "none";
		img.src = '/Common/img/icon_downArrow.gif';
		td.innerHTML = 'Show Photo List';
		property_tabBox_photosCurrentShowLinks = false;
	} else {
		linksTd.style.display = "";
		img.src = '/Common/img/icon_upArrow.gif';
		td.innerHTML = 'Hide Photo List';
		property_tabBox_photosCurrentShowLinks = true;
	}
}

/* --------------------------------------------------------------------- 360s */
var property_tabBox_360 = new Array();
// KEPT IN 
/* <xsl:for-each select="$DOCUMENT/company_media_file[media_type_id=$MEDIA_TYPE_360]">
property_tabBox_360[<xsl:value-of select="position()-1"/>] = new Array();
property_tabBox_360[<xsl:value-of select="position()-1"/>]['fullsize_uri'] = '<xsl:value-of select="fullsize_uri"/>';
property_tabBox_360[<xsl:value-of select="position()-1"/>]['description'] = '<xsl:value-of select="media_caption"/>';
</xsl:for-each> */
/* depricated up in this hizzy
var current_360 = 0;
function property_tabBox_display360 (indx) {
	//alert (current_360+": "+obj_oldSpan.className+"\n"+obj_span.id+": "+obj_span.className);
	if (current_360 != indx) {
		obj_oldLink = document.getElementById('property_tabBox_360Link'+current_360);
		obj_oldBullet = document.getElementById('property_tabBox_360Bullet'+current_360);
		obj_oldLink.className = 'title_sub property_tabBox_360Link';
		obj_oldBullet.className = 'property_tabBox_360Bullet';
		
		obj_oldLink = document.getElementById('property_tabBox_360Link'+indx);
		obj_oldBullet = document.getElementById('property_tabBox_360Bullet'+indx);
		obj_oldLink.className = 'title_sub property_tabBox_360LinkSelected';
		obj_oldBullet.className = 'property_tabBox_360BulletSelected';

		current_360 = indx;

		obj_360 = document.getElementById("property_tabBox_360Applet");
		obj_360.Set_file("/loader.ivr.htm?url="+property_tabBox_360[indx]['fullsize_uri']);
		obj_360.ResetApplet();
	}
	//alert ("old: "+obj_oldSpan.className+"\n"+"new: "+obj_span.className);
}
*/

function property_tabBox_check360 () {
	if (current_360 != 0) {
		needs_to_be = current_360;
		current_360 = 0;
		property_tabBox_display360 (needs_to_be);
	}
}

/* ---------------------------------------------------------------------- map */


/* ------------------------------------------------------------------ contact */



/* -------------------------------------------------------------------------- */
/* ------------------------------------------------ property_drivingDirection */
/* -------------------------------------------------------------------------- */
function property_drivingDirections_showOrigin (url) {
	property_drivingDirections_zoomTd.style.display = 'none';
	property_drivingDirections_overviewLink.style.display = '';
	property_mapquestSwitchMap (url, 1);
	property_mapquestImg.className = 'property_drivingDirections_mapWide';
}
function property_drivingDirections_showDestination (url) {
	property_drivingDirections_zoomTd.style.display = 'none';
	property_drivingDirections_overviewLink.style.display = '';
	property_mapquestSwitchMap (url, 1);
	property_mapquestImg.className = 'property_drivingDirections_mapWide';
	property_mapquestMapInteractive = false;
}
function property_drivingDirections_showOverview (url, zl) {
	property_drivingDirections_zoomTd.style.display = '';
	property_drivingDirections_overviewLink.style.display = 'none';
	property_mapquestSwitchMap (url, zl);
	property_mapquestImg.className = 'property_drivingDirections_map';
	property_mapquestMapInteractive = true;
}


/* -------------------------------------------------------------------------- */
/* --------------------------------------------------------- property_buttons */
/* -------------------------------------------------------------------------- */
function property_buttons_over (div_id) {
	obj_div = document.getElementById(div_id);
	obj_div.className = 'property_buttons_selected';
}
function property_buttons_out (div_id) {
	obj_div = document.getElementById(div_id);
	obj_div.className = '';
}


/* -------------------------------------------------------------------------- */
/* ------------------------------------------------------ property_floorplans */
/* -------------------------------------------------------------------------- */
function show_property_floorplan (name, url) {
	var fullsizePopup = window.open("", "property_floorplan", "width=780,height=608");
	var obj_img = fullsizePopup.document.getElementById('fullsize_floorplan_image');
	fullsizePopup.document.title = name + ' Floorplan';
	fullsizePopup.width = 530;
	fullsizePopup.height = 405;

	if (obj_img) {
		obj_img.src = url;
	} else {
		//var obj_img = fullsizePopup.document.createElement('img');
		var obj_img = new Image(758,586);
		obj_img.src = url;
		obj_img.id = "fullsize_floorplan_image";
		obj_img.style.width = "758px";
		obj_img.style.height = "586px";
		obj_img.border = "0";
		
		var obj_a = fullsizePopup.document.createElement('a');
		obj_a.href = "javascript: self.close();";
		obj_a.appendChild(obj_img);
		
		fullsizePopup.document.body.setAttribute("style", "margin: 11px 11px 11px 11px;");
		fullsizePopup.document.body.appendChild(obj_a);
	}
	fullsizePopup.focus ();
}


/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------- balloon functions */
/* -------------------------------------------------------------------------- */
var positioner;
var property_balloonMove = function (id) {
	var obj = document.getElementById(id);
	if (xMousePos + 35 + obj.clientWidth > xMousePosMax) {
		x = xMousePos - 5 - obj.clientWidth;
	} else {
		x = xMousePos + 10;
	}
	if (yMousePos + 35 + obj.clientHeight > yMousePosMax) {
		y = yMousePos - 5 - obj.clientHeight;
	} else {
		y = yMousePos + 10;
	}
	obj.style.left = x+'px';
	obj.style.top = y+'px';
}
function property_showBalloon (id) {
	var obj = document.getElementById(id);
	obj.style.display = '';
	property_balloonMove (id);
	positioner = setInterval('property_balloonMove(\''+id+'\')', 50);
}
function property_hideBalloon (id) {
	var obj = document.getElementById(id);
	obj.style.display = 'none';
	clearInterval(positioner);
}


/* -------------------------------------------------------------------------- */
/* ------------------------------------------------------- mapquest functions */
/* -------------------------------------------------------------------------- */
var property_mapquestImageBaseSrc = '';
//var property_mapquestImageFinalSrc = '';
//var property_mapquestDefaultZoom = 8;
var property_mapquestZoomLevel = 8;
var property_mapquestZoomCurrentClass = '';
var property_mapquestRequestCount = 0;
var property_mapquestMapInteractive = true;

function property_mapquestSwitchMap (url, zl) {
	property_mapquestMoveZoomBar (zl);
	property_mapquestImg.src = url + property_mapquestReturnRequestCount();
}

function property_mapquestImageClick (obj) {
	if (property_mapquestMapInteractive) {
		if (obj.x) {
			x = xMousePos - obj.x;
			y = yMousePos - obj.y;
		} else {
			x = xMousePos - findPosX(obj) - 3;
			y = yMousePos - findPosY(obj) - 3;
		}
		property_mapquestCenter (x,y);
	}
}

/*function property_mapquestResetImage () {
	property_mapquestImg.src = property_mapquestImageFinalSrc;
	property_mapquestMoveZoomBar (property_mapquestDefaultZoom);
}*/

function property_mapquestZoomIn () {
	if (property_mapquestZoomLevel < 10) {
		property_mapquestZoomTo (property_mapquestZoomLevel + 1);
	}
}

function property_mapquestZoomOut () {
	if (property_mapquestZoomLevel > 1) {
		property_mapquestZoomTo (property_mapquestZoomLevel - 1);
	}
}

function property_mapquestClearSrc () {
	if (property_mapquestImageBaseSrc == "") {
		property_mapquestImageBaseSrc = property_mapquestImg.src;
	}
	return property_mapquestImageBaseSrc;
}

function property_mapquestReturnRequestCount () {
	property_mapquestRequestCount++;
	return '&requestCount=' + property_mapquestRequestCount;
}

function property_mapquestKeepSessionAlive () {
	property_mapquestImg.src = property_mapquestClearSrc() + property_mapquestReturnRequestCount();
}

function property_mapquestMoveZoomBar (zl) {
	if (zl != property_mapquestZoomLevel) {
		var newZoomButton = document.getElementById(property_mapquestZoomLevelButtonBaseId + zl);
		var oldZoomButton = document.getElementById(property_mapquestZoomLevelButtonBaseId + property_mapquestZoomLevel);
		if(newZoomButton){
			newZoomButton.className = property_mapquestZoomLevelButtonClass + ' ' + property_mapquestZoomLevelButtonSelectedClass;
		}
		if(oldZoomButton){
			oldZoomButton.className = property_mapquestZoomLevelButtonClass;
		}
		property_mapquestZoomLevel = zl;
	}
}

function property_mapquestZoomTo (zl) {
	if (zl != property_mapquestZoomLevel) {
		property_mapquestMoveZoomBar (zl);
		property_mapquestImg.src = property_mapquestClearSrc() + '&zoomLevel=' + zl + property_mapquestReturnRequestCount();
//		alert (property_mapquestImg.src);
	}
}

function property_mapquestCenter (x,y) {
	property_mapquestImg.src = property_mapquestClearSrc() + '&mapBrowse=center&x=' + x + '&y=' + y + property_mapquestReturnRequestCount();
//	alert (property_mapquestImg.src);
}

function property_mapquestZoomMouseOver (obj) {
	if (obj.className.indexOf(property_mapquestZoomLevelButtonSelectedClass) == -1) {
		obj.className = obj.className + ' ' + property_mapquestZoomLevelButtonHighlightedClass;
	}
}

function property_mapquestZoomMouseOut (obj) {
	obj.className = str_replace (obj.className, ' ' + property_mapquestZoomLevelButtonHighlightedClass, '');
	//obj.className = obj.className.replace(/\ property_tabBox_mapZoomHighlighted/, "");
}

function property_mapquestPopupDrivingDirections (str_url) {
	obj_street = document.getElementById('property_tabBox_mapDrivingStreet');
	str_street = obj_street.value;
	obj_city = document.getElementById('property_tabBox_mapDrivingCity');
	str_city = obj_city.value;
	obj_state = document.getElementById('property_tabBox_mapDrivingState');
	str_state = obj_state.value;
	obj_zip = document.getElementById('property_tabBox_mapDrivingZip');
	str_zip = obj_zip.value;

	str_url = str_url + "/originating_address[street_line1]/"+str_street+"/originating_address[city]/"+str_city+"/originating_address[state_code]/"+str_state+"/originating_address[postal_code]/"+str_zip;
	var drivingDirectionsPopup = window.open(str_url, "property_tabBox_mapDrivingDirections", "top=10,left=10,width=552,height="+(document.body.clientHeight - 80)+",scrollbars=yes,resizable=yes,status=no");
	drivingDirectionsPopup.focus ();
}


/* -------------------------------------------------------------------------- */
/* ------------------------------------ mouse tracking and location functions */
/* -------------------------------------------------------------------------- */
// MOUSE POSITION TRACKER 
// (used to help determine where a user clicked on map image and in balloon popups)
if (document.layers) {
	document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = captureMousePosition;
} else if (document.all) {
	document.onmousemove = captureMousePosition;
} else if (document.getElementById) {
	document.onmousemove = captureMousePosition;
}
var document_obj = document.getElementById('document');
var document_container = document.getElementById('document_container');

var drag = false;
var cXp = 0;
var cYp = 0;
var xMousePos = 0;
var yMousePos = 0;
var xMousePosMax = 0;
var yMousePosMax = 0;
function captureMousePosition(e) {
	if (!e) var e = window.event;
	if (navigator.appName !="Microsoft Internet Explorer") {
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;
	} else {
		xMousePos = window.event.x+document.body.scrollLeft;
		yMousePos = window.event.y+document.body.scrollTop;
		xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
		yMousePosMax = document.body.clientHeight+document.body.scrollTop;   
	}
	//window.status = "x:"+xMousePos+"  y:"+yMousePos;
}

// FUNCTION USED BY NON-MOZILLA BROWSERS TO FIND AN OBJECT'S
// POSITION ON THE PAGE. DOES _NOT_ INCLUDE THE SCROLL OFFSET
// (courtesy of QuirksMode.org) 
// (used to help determine where a user clicked on map image)
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}