// vc_id = "$Id: ppListingDropDown.js 9505 2006-08-10 18:11:34Z jgiven $"
// JavaScript Document


// drop down reporter
// @param true if using ajax to populate detail, optional
function listingDropDownReporter(  ) {
	this.positionChange = listingDropDown;
	this.XHRStateChange = loadPropertyDetailsXHR;
}

function acceptListingImages(imageArray) {
	
}

function listingDropDown(positionevent,id) {
	var divLayer = document.getElementById("listingDivLayer");
	var matches = getNearbyLocationFixIDs(positionevent);
	var loopCount = 0;
	var objInnerHTML = '';
	
	// Check to see if user is drawing box.
	if (areListingMapBoundsInitialized() != false) {
		return;
	}
	
	if (matches.length > 0) {
	    for ( var i = 0; i < matches.length; i++ ) {
		if (matches[i]) {
		    var pointLocation = retrieveLocationFix(matches[i]);
		    var detail = pointLocation.url ? 
			"javascript:updateListingDetailXHR('" + pointLocation.url + "');" : 
			"javascript:loadPropertyDetails('" + pointLocation.pid + "');";
		    if (loopCount == 1) {
			var basepath = APPIMAGES ? APPIMAGES + "/" : "images/";
			objInnerHTML += "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><img src=" + 
			    basepath + "spacer.gif width=1 height=8 border=0></td></tr></table>";
			objInnerHTML += "<table cellpadding=0 cellspacing=0 border=0 width=100% bgcolor=#000000><tr><td><img src=" + 
			    basepath + "spacer.gif width=1 height=1 border=0></td></tr></table>";
			objInnerHTML += "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td><img src=" + 
			    basepath + "spacer.gif width=1 height=8 border=0></td></tr></table>";
		    }
		    
		    objInnerHTML += "<table cellpadding=0 cellspacing=0 border=0 width=100%><tr>";
		    //objInnerHTML += "<td class=smalltext_dark>" + pointLocation.id + ") " + "</td>";
		    //objInnerHTML += "<td width=5>&nbsp;</td>";
		    if ( pointLocation.thumb ) {
			objInnerHTML += "<td class=smalltext_dark><a href=\"" + detail + "\">" +
			    "<img src=" + pointLocation.thumb + " border=0 width=75 height=55></a></td>";
		    } else {
			objInnerHTML += "<td class=smalltext_dark><a href=\"" + detail + "\">" +
			    "<img src=" + LDTHUMBS[ pointLocation.pid ] + " border=0 width=75 height=55></a></td>";
		    }
		    objInnerHTML += "<td width=5>&nbsp;</td>";
		    objInnerHTML += "<td class=smalltext_dark>";
		    //objInnerHTML += pointLocation.id + ") ";
		    objInnerHTML += pointLocation.address + "<br>";
		    objInnerHTML += pointLocation.price + ", " + pointLocation.bedbath + "<br>";
		    objInnerHTML += "<a href=\"" + detail + "\">" +  "View #" + pointLocation.id + "</a>";
		    objInnerHTML += "</td></tr></table>";
		}
		if (loopCount == 1) {
		    var loopCount = 0;
		}
		var loopCount = loopCount + 1;
	    }
	    if (objInnerHTML != '') {
		document.getElementById("pListingInfo").innerHTML = objInnerHTML;
		displayLayer(positionevent.screen.x, positionevent.screen.y, 1);
		
	    }
	} else if (matches.length == 0) {
	    displayLayer(positionevent.screen.x, positionevent.screen.y, 0);
	}
	//alert(positionevent.page.y);
	//alert(positionevent.screen.y);
}

function displayLayer(tempX,tempY,showHide) {
	var divLayer = document.getElementById("listingDivLayer");
	var offSetRight = -1;
	var mouseMapX = tempX - 50; // Account for the 50px discrepancy on the position change event page x
	//document.getElementById('city1').value = mouseMapX + '|' + retrieveMap(POSITION_MAP).screen.right;
	
	//Where in relation to the map
	//Should I place the Div Layer
	//If left side, then the right & viceversa
	if ((showHide == 1) && (mouseMapX < retrieveMap(POSITION_MAP).screen.right / 2)) {
		var tempX = tempX - 5;
		var tempY = tempY - 5;
	} else if ((showHide == 1) && (mouseMapX > retrieveMap(POSITION_MAP).screen.right / 2)) {
		if (divLayer.offsetWidth) {
			var offSetRight = 220;
		} else {
			var offSetRight = 220;
		}
		var tempX = tempX - offSetRight;
		var tempY = tempY - 5;
	}
	
	if(showHide == 1) {
		//document.getElementById('city1').value = tempX;
		//divLayer.style.position = 'relative';
		divLayer.style.top = tempY + 'px';
		divLayer.style.left = tempX + 'px';
		divLayer.style.zIndex = 5000;
		if (offSetRight != 0) { divLayer.style.display = 'block'; }
	} else if (showHide == 0) {
		divLayer.style.display = 'none';
	}
}

function loadPropertyDetails(listingID) {
        parent.document.getElementById("ppSearchForm").className = '';
	//parent.document.getElementById("ppListingCart").className = '';
	parent.document.getElementById("ppListingDetail").className = 'current';
	parent.document.getElementById('ppSearchFormContainer').style.display = 'none';
	//parent.document.getElementById('ppShoppingCartHolder').style.display = 'none';
	parent.document.getElementById('ppListingDetail').style.display = 'block';
	parent.document.getElementById('ppListingDetailiFrame').style.display = 'block';
	//alert(window.parent.ppRightFrame);
	window.parent.ppRightFrame.location = 'index.cfm?fuseaction=listing.smallListingDetail&ListingID=' + listingID;
	// make the call again for safari to make sure it refrences the iFrame as a window object and not a td object.  Stupid Safari.
	window.parent.ppRightFrame.location = 'index.cfm?fuseaction=listing.smallListingDetail&ListingID=' + listingID;
}

function loadPropertyDetailsXHR( xhr ) {
    if ( xhr.success( ) ) {
        document.getElementById("ppListingDetailiFrame").innerHTML = xhr.responseText( );
	document.getElementById("ppListingDetailiFrame").style.width = '250px';
	document.getElementById("ppSearchForm").className = '';
	document.getElementById("ppListingDetail").className = 'current';
	document.getElementById('ppSearchFormContainer').style.display = 'none';
	document.getElementById("ppListingDetailiFrame").style.display = 'block';
    }
}

function addToShoppingCart(listingID) {
	parent.changeSectionTab("ppListingCart","");
	parent.document.getElementById('ppListingDetailiFrame').style.display = 'none';
	parent.document.getElementById('ppSearchFormContainer').style.display = 'none';
	parent.document.getElementById('ppShoppingCartHolder').style.display = 'block';
	window.parent.ppShoppingCartIframe.location = 'index.cfm?fuseaction=listing.ppShoppingCartDetails&listing=' + listingID;
}


