 function SVControl() {
	var map;
	var dragging;
	var hasStreetviewData;
	var svbuttonTracer;
	var roundedCircle;
	var left, top;
	var centerPoint;
	var lastPanoLatLng;
	var mouseWatcher,resizeTimeoutId, window;
	var panChecker, panning, watchMaster, pLeft, pRight, pointChecked;
	var svbuttonDir;
	var nearestPanoLatLng;
	var marker;
	var currentLoc;
	var yaw;
    var isOpera;
}

SVControl.prototype = new GControl();

SVControl.prototype.initialize = function (map) {
	this.map = map;
	this.mouseover = false;
	this.dragging = false;
	this.pointChecked = false;
	this.streetviewclicked = false;
	this.hasStreetviewData = false;
	this.init = false;

	this.browserflashbug = ((navigator.userAgent) && navigator.userAgent.indexOf("Chrome") != -1);
	this.isIE = (navigator.userAgent.toLowerCase().indexOf('msie 7') != -1 || navigator.userAgent.toLowerCase().indexOf('msie 8') != -1);
	this.width = this.map.getContainer().style.width;
	this.height = this.map.getContainer().style.height;
	this.panoramacontainer = document.getElementById("street");
	this.streetview = new GStreetviewOverlay();
	this.map.addOverlay(this.streetview);
	this.streetview.hide();
	this.streetview.SVControl = this;
	GEvent.addListener(this.streetview, "changed", this.changedstreetview);
	this.streetviewclient = new GStreetviewClient();
	this.container = document.createElement("div");
	this.container.style.cssText = "overflow: hidden; width: 40px; height: 40px; position: absolute; border: 0px solid black;";
	this.svbutton = document.createElement("div");
	this.svbutton.style.cssText = "overflow: hidden; width: 40px; height: 40px; z-index: 10001; position: relative; top:0px; left: 0px; border: 0px solid black;";
	this.svbutton.SVControl = this;

	this.svbuttonTracer = document.createElement("div");
	this.svbuttonTracer.style.cssText = "overflow: hidden; width: 60px; height: 40px; z-index: 10001; position: relative; top:0px; left: 0px; border: 0px solid black; display: none;";
	this.roundedCircle = document.createElement("div");
	this.roundedCircle.style.cssText = "-moz-border-radius:50% 50%;border:1px dotted #666;width:8px;height:8px; top: 14px; left: 10px; position:relative;";
	this.cameraView =  document.createElement("div");
	this.cameraView.style.cssText = "overflow: hidden; width: 32px; height: 32px; position: absolute; border: 0px solid black; display: none; top: 0px; left: 0px;";

	this.yawPoints = new Array(-149,-7,-52,-106,0,-8,-470,-9,-470,-89,-678,-43,-902,-58,-763,-53,-2,-57,-504,-36,-88,-4,-151,-50,-763,-1,-901,-96,-902,-5,-503,-82);
	this.yawSlices = new Array(348.75,11.25,33.75,56.25,78.75,101.25,123.75,146.25,168.75,191.25,213.75,236.25,258.75,281.25,303.75,326.25);

	this.container.appendChild(this.svbutton);
        
        /* Logging portion to reverse engineer dom events */
//	this.logContainer = document.createElement("div");
//	this.logContainer.setAttribute("id","logWindow");
//	this.logContainer.style.cssText = "overflow: hidden; width: 500px; height: 100px; position: absolute; background-color: white; border: 1px solid; top: 50px; left: 100px;";
//	this.logText = document.createElement("p"); this.logText.style.cssText = "color: black; text-align: center; font-size: 10px; margin:0px; ";
//	this.logText2 = document.createElement("p"); this.logText2.style.cssText = "color: black; text-align: center; font-size: 10px; margin:0px;";
//	this.logText3 = document.createElement("p"); this.logText3.style.cssText = "color: black; text-align: center; font-size: 10px; margin:0px;";
//	this.logText4 = document.createElement("p"); this.logText4.style.cssText = "color: black; text-align: center; font-size: 10px; margin:0px;";
//	this.logContainer.appendChild(this.logText);
//	this.logContainer.appendChild(this.logText2);
//	this.logContainer.appendChild(this.logText3);
//	this.logContainer.appendChild(this.logText4)
//
//        map.getContainer().appendChild(this.logContainer);

	this.img = document.createElement("img");
	this.img.setAttribute("src", "gui/images/icons/cb_scout_sprite_003_local.png");
	this.img.style.cssText = "border: 0px none ; margin: 0px; padding: 0px; position: absolute; left: -62px; top: -42px; width: 147px; height:935px;";

	this.imgTracer = document.createElement("img");
	this.imgTracer.setAttribute("src", "gui/images/icons/cb_scout_sprite_003_local.png");
	this.imgTracer.style.cssText = "border: 0px none ; margin: 0px; padding: 0px; position: absolute; left: -9px; top: -190px; width: 147px; height:935px;";

	this.imgView = document.createElement("img");
	this.imgView.setAttribute("src", "gui/images/icons/cb_scout_sprite_003_local.png");
	this.imgView.style.cssText = "border: 0px none ; margin: 0px; padding: 0px; position: absolute; left: 0px; top: 0px; width: 147px; height:935px;";


	this.svbutton.appendChild(this.img);
	this.svbuttonTracer.appendChild(this.imgTracer);
	this.svbuttonTracer.appendChild(this.roundedCircle);
	this.cameraView.appendChild(this.imgView);
	map.getContainer().appendChild(this.container);
	map.getContainer().appendChild(this.cameraView);

	this.centerPoint = map.getCenter();

	this.dragbutton = new GDraggableObject(this.container, {
		container: map.getContainer()
	});
	this.dragbutton.SVControl = this;
	GEvent.addDomListener(this.svbutton, "mouseover", this.funcmouseover);
	GEvent.addDomListener(this.svbutton, "mouseout", this.funcmouseout);

	GEvent.addDomListener(this.dragbutton, "dragstart", this.funcdragstart);
	GEvent.addDomListener(this.dragbutton, "dragend", this.funcdragend);
	GEvent.addDomListener(this.dragbutton, "drag", this.funcdrag);

	this.panorama = new GStreetviewPanorama(this.panoramacontainer);
	this.panorama.SVControl = this;

	GEvent.addDomListener(this.panorama, "error", this.hidestreetview);
	return this.container
};

SVControl.prototype.getDefaultPosition = function () {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(65, 16))
};


SVControl.prototype.funcmouseover = function () {
	if (!this.SVControl.dragging) {
		if (this.SVControl.hasStreetviewData) {
			this.SVControl.mouseover = true;
			this.SVControl.img.style.left = "-62px";
			this.SVControl.img.style.top = "-320px";
		}
	}
};
SVControl.prototype.funcmouseout = function () {
	if (!this.SVControl.dragging) {
		if (this.SVControl.mouseover) {
			this.SVControl.mouseover = false;
			this.SVControl.img.style.left = "-62px";
			this.SVControl.img.style.top = "-42px";
			this.SVControl.streetview.hide()
		}
		this.SVControl.cameraView.style.display="none";

		if (this.SVControl.watchMaster)
			clearInterval(this.SVControl.watchMaster);
		if (this.SVControl.mouseWatcher)
			clearInterval(this.SVControl.mouseWatcher);
		if (this.SVControl.panChecker)
			clearInterval(this.SVControl.panChecker);
	}
	this.SVControl.svbuttonTracer.style.display="none";
};

SVControl.prototype.mouseWatch = function(){
	if (this.dragging){
		if (!this.mouseMoving && !this.panning){
			// Check if point was already looked at
			if (!this.pointChecked){
				var point = this.map.fromContainerPixelToLatLng(new GPoint(this.left + 15, this.top + 59));

				if (point){
					this.currentLoc = point;
					this.streetviewclient.getNearestPanorama(point, this.callback(this.showPanodata, {
						bind: this,
						args: [],
						suppressArgs: true
					}));

					// Gets nearest LatLng of a panoramicLatLng
					this.streetviewclient.getNearestPanoramaLatLng(point, this.callback(this.getNearestLatLng, {
						bind: this,
						args: [],
						suppressArgs: true
					}));
				}
				this.pointChecked = true;
			}
		}
	}
};

// Callback function to watch for panning of map and mouse movements
SVControl.prototype.masterWatch = function (){
	this.centerPoint != this.map.getCenter() ? this.panning = true : this.panning = false;
	this.centerPoint = this.map.getCenter();

	if (this.pTop != this.top || this.pLeft != this.left){
		this.mouseMoving = true;
		this.pointChecked = false;
	} else
		this.mouseMoving = false;


	this.pTop =  this.top;
	this.pLeft =  this.left;
};

SVControl.prototype.funcdragstart = function () {
	this.SVControl.centerPoint = this.SVControl.map.getCenter();

	this.SVControl.watchMaster = setInterval(this.SVControl.callback(this.SVControl.masterWatch,{
			bind: this.SVControl,
			args: [],
			suppressArgs: true
		}), 50);

	this.SVControl.mouseWatcher = setInterval(this.SVControl.callback(this.SVControl.mouseWatch,{
			bind: this.SVControl,
			args: [],
			suppressArgs: true
		}), 250);
	this.SVControl.panChecker = setInterval(this.SVControl.callback(this.SVControl.checkPan,{
			bind: this.SVControl,
			args: [],
			suppressArgs: true
		}), 75);

	this.SVControl.dragging = true;
	this.SVControl.img.style.left = "-3px";
	this.SVControl.img.style.top = "-800px"
};

SVControl.prototype.funcdragend = function () {
	if (this.SVControl.dragging) {
                //console.log("Dragging Ended displaying streetview");
		this.SVControl.dragging = false;
		this.SVControl.point = this.SVControl.map.fromContainerPixelToLatLng(new GPoint(this.left + 15, this.top + 59));
                //console.log("Point to be displayed:",this.SVControl.point);

		this.SVControl.streetviewclient.getNearestPanoramaLatLng(this.SVControl.point, this.SVControl.callback(this.SVControl.showstreetview, {
			bind: this.SVControl,
			args: [],
			suppressArgs: true
		}));
		this.SVControl.container.style.height = "40px";
		this.SVControl.img.style.left = "-62px";
		this.SVControl.img.style.top = "-42px";
		this.SVControl.streetview.hide();
		this.SVControl.container.removeChild(this.SVControl.svbuttonTracer);

		if (this.SVControl.watchMaster)
			clearInterval(this.SVControl.watchMaster);
		if (this.SVControl.mouseWatcher)
			clearInterval(this.SVControl.mouseWatcher);
		if (this.SVControl.panChecker)
			clearInterval(this.SVControl.panChecker);
		this.moveTo(new GPoint(65, 16));
	}
};

SVControl.prototype.checkPan = function (){
	var centerLatLng = this.map.getCenter();
	var coordMove = .001;
	// Faster move for IE
	if (this.isIE)
		coordMove = .005;
	var leftWidthBound = this.map.getSize().width - 40;

	if (this.left == 0 && this.top == 0){
		this.map.panTo(new GLatLng(centerLatLng.lat() + coordMove, centerLatLng.lng() - coordMove));
	// North
	} else if (this.left != 0 && this.top == 0 && this.left < leftWidthBound){
		this.map.panTo(new GLatLng(centerLatLng.lat() + coordMove, centerLatLng.lng()));
	// West
	} else if(this.left == 0 && this.top > 0 && this.top < 270 ){
		this.map.panTo(new GLatLng(centerLatLng.lat(), centerLatLng.lng() - coordMove));
	// South West
	} else if(this.left == 0 && this.top == 270){
		this.map.panTo(new GLatLng(centerLatLng.lat() - coordMove, centerLatLng.lng() - coordMove));
	// South
	} else if (this.left > 0 && this.left < leftWidthBound && this.top == 270){
		this.map.panTo(new GLatLng(centerLatLng.lat() - coordMove, centerLatLng.lng()));
	// South East
	} else if(this.left >= leftWidthBound && this.top == 270){
		this.map.panTo(new GLatLng(centerLatLng.lat()  - coordMove, centerLatLng.lng() + coordMove));
	// East
	} else if(this.left >= leftWidthBound && this.top > 0 && this.top < 270){
		this.map.panTo(new GLatLng(centerLatLng.lat(), centerLatLng.lng() + coordMove));
	// North East
	} else if(this.left >= leftWidthBound && this.top == 0){
		this.map.panTo(new GLatLng(centerLatLng.lat() + coordMove, centerLatLng.lng() + coordMove));
	}
};


SVControl.prototype.funcdrag = function () {
	if (this.SVControl.dragging) {
		this.SVControl.streetview.show();
		this.SVControl.container.appendChild(this.SVControl.svbuttonTracer);
		this.SVControl.container.style.height = "80px";
		this.SVControl.svbuttonTracer.style.display="block";
		this.SVControl.cameraView.style.display="none";

		// Change Little Guy to face direction of travel
		if (this.left > this.SVControl.left){
			this.SVControl.img.style.left = "-3px";
			this.SVControl.img.style.top = "-800px";
			this.SVControl.svbuttonDir = "right";
		}
		else if (this.left < this.SVControl.left){
			this.SVControl.img.style.left = "-64px";
			this.SVControl.img.style.top = "-186px";
			this.SVControl.svbuttonDir = "left";

		}

		this.SVControl.left = this.left;
		this.SVControl.top = this.top;
	}
};

SVControl.prototype.getNearestLatLng = function (point){
	if (point){
		var myLoc = this.map.fromLatLngToContainerPixel(point);

		this.yaw = this.calculateYaw(this.currentLoc, point);

		yawPoints = this.yawPoints;
		yawSlices = this.yawSlices;

		if(this.yaw >= yawSlices[0] && this.yaw < 360 || this.yaw < yawSlices[1])  imgPos(yawPoints[0], yawPoints[1], this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[1] && this.yaw < yawSlices[2]) 	imgPos(yawPoints[2], yawPoints[3],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[2] && this.yaw < yawSlices[3]) 	imgPos(yawPoints[4], yawPoints[5],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[3] && this.yaw < yawSlices[4]) 	imgPos(yawPoints[6], yawPoints[7],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[4] && this.yaw < yawSlices[5]) 	imgPos(yawPoints[8], yawPoints[9],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[5] && this.yaw < yawSlices[6])		imgPos(yawPoints[10], yawPoints[11],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[6] && this.yaw < yawSlices[7]) 	imgPos(yawPoints[12], yawPoints[13],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[7] && this.yaw < yawSlices[8]) 	imgPos(yawPoints[14], yawPoints[15],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[8] && this.yaw < yawSlices[9]) 	imgPos(yawPoints[16], yawPoints[17],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[9] && this.yaw < yawSlices[10]) 	imgPos(yawPoints[18], yawPoints[19],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[10] && this.yaw < yawSlices[11]) 	imgPos(yawPoints[20], yawPoints[21],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[11] && this.yaw < yawSlices[12]) 	imgPos(yawPoints[22], yawPoints[23],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[12] && this.yaw < yawSlices[13]) 	imgPos(yawPoints[24], yawPoints[25],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[13] && this.yaw < yawSlices[14]) 	imgPos(yawPoints[26], yawPoints[27],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[14] && this.yaw < yawSlices[15]) 	imgPos(yawPoints[28], yawPoints[29],this.imgView, this.cameraView);
		if(this.yaw >= yawSlices[15] && this.yaw < yawSlices[0]) 	imgPos(yawPoints[30], yawPoints[31],this.imgView, this.cameraView);
	}

	function imgPos (top, left, img, camera){
		var yOffset = 16;
		var xOffset = 16;
		img.style.top = top+ "px";
		img.style.left = left+ "px";
		camera.style.top = (myLoc.y - yOffset) + "px" ;
		camera.style.left = (myLoc.x - xOffset) + "px" ;
		camera.style.display = "block";
	}
};

/* Retrieves nearest panoramas around current location */
SVControl.prototype.showPanodata = function (panoData){
	if (panoData) {
		if (panoData.code != 200) {
			// No Pano Data being returned
			if ( this.svbuttonDir == "right" ){
				this.img.style.left = "-3px";
				this.img.style.top = "-800px";
			} else if ( this.svbuttonDir == "left" ){
				this.img.style.left = "-64px";
				this.img.style.top = "-186px";
			}
			this.cameraView.style.display="none";
	    		return;
		}

		// Switch to active mode
		if ( this.svbuttonDir == "right" ){
			this.img.style.left = "-52px";
			this.img.style.top = "-800px";
		} else if ( this.svbuttonDir == "left" ){
			this.img.style.left = "-15px";
			this.img.style.top = "-315px";
		}
	}
};

SVControl.prototype.showstreetview = function (point) {
    if (point) {
        this.cameraView.style.display = "none";

        this.point = point;
        if (this.yaw){
            this.panorama.setLocationAndPOV(this.point,{
                yaw:eval(this.yaw)
                });
            this.yaw = null;
        } else {
            this.panorama.setLocationAndPOV(this.point, {
                yaw:0
            });
        }
        
        this.panorama.show();
        this.panorama.checkResize();

        // Double check all timers are cleared
        if (this.watchMaster)
            clearInterval(this.watchMaster);
        if (this.mouseWatcher)
            clearInterval(this.mouseWatcher);
        if (this.panChecker)
            clearInterval(this.panChecker);

        this.init = true;

        // Resets SV icon to starting position
        this.img.style.left = "-62px";
        this.img.style.top = "-42px";

        $("#tabs").tabs().tabs("select", 1);
    }
};

SVControl.prototype.hidestreetview = function () {
	this.SVControl.panoramacontainer.style.display = "none";
	this.SVControl.closecontainer.style.display = "none";
	this.SVControl.iframe.style.display = "none";
	this.SVControl.panorama.hide();
	this.SVControl.panorama.remove();
};

SVControl.prototype.changedstreetview = function (hasStreetviewData) {
	this.SVControl.hasStreetviewData = hasStreetviewData;
	if (hasStreetviewData) {
		if (this.SVControl.mouseover) {
			this.SVControl.img.style.left = "-62px";
			this.SVControl.img.style.top = "-320px"
		} else {
			this.SVControl.img.style.left = "-62px";
			this.SVControl.img.style.top = "-42px"
		}
	} else {
		this.SVControl.img.style.left = "-102px";
		this.SVControl.img.style.top = "-847px"
	}
};

/************************************************** Utility Classes ******************************************/
/*******************************************				 *************************************/

SVControl.prototype.callback = function callback(func, opts) {
	var cb = function () {
		var args = opts.args ? opts.args: [];
		var bind = opts.bind ? opts.bind: this;
		var fargs = opts.supressArgs === true ? [] : toArray(arguments);
		func.apply(bind, fargs.concat(args))
	};
	return cb

	function toArray(arrayLike) {
		var arr = [];
		for (var i = 0; i < arrayLike.length; i++) {
			arr.push(arrayLike[i])
		}
		return arr
	}
};

SVControl.prototype.calculateYaw = function (from, to){
	var degreesPerRadian = 180.0 / Math.PI;
     	var radiansPerDegree = Math.PI / 180.0;

     	// Returns the bearing in degrees between two points.
     	// North = 0, East = 90, South = 180, West = 270.
       	// See T. Vincenty, Survey Review, 23, No 176, p 88-93,1975.
       	// Convert to radians.
       	var lat1 = from.lat();
       	var lon1 = from.lng();
       	var lat2 = to.lat();
       	var lon2 = to.lng();

       	// Compute the angle.
       	var angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) );
       	if ( angle < 0.0 )
		angle  += Math.PI * 2.0;

       	// And convert result to degrees.
       	angle = angle * degreesPerRadian;
       	angle = angle.toFixed(1);

return angle;
};


/************************************************ StreetViewControl ******************************************/
/*******************************************				 *************************************/

var globalStreetView;

function StreetViewControl() {
	var container;
	var container2;
};

StreetViewControl.prototype = new GControl();

StreetViewControl.prototype.initialize = function (map) {
	this.container = document.createElement("div");
	this.container.style.cssText = "overflow: hidden; width: 30px; height: 40px; position: absolute;";
	var svbutton = document.createElement("div");
	svbutton.style.cssText = "overflow: hidden; width: 30px; height: 40px; z-index: 10001;";
	this.container.appendChild(svbutton);
	var img = document.createElement("img");
	img.setAttribute("src", "gui/images/icons/cb_scout_sprite_003_local.png");
	img.style.cssText = "border: 0px none ; margin: 0px; padding: 0px; position: absolute; left: -102px; top: -847px; width: 147px; height: 935px;";
	svbutton.appendChild(img);
	map.getContainer().appendChild(this.container);

	this.container2 = new SVControl(map);
	globalStreetView = this.container2;
	map.addControl(this.container2);
	return this.container
};
StreetViewControl.prototype.getDefaultPosition = function () {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(65, 16))
};

var map = null;
var myPana
var aPoint, gMapTypeControl;
var flashInstalled, isChrome = false;
var geocoder = null;
var address;
var mls;
var type;
var numImg;
var id;
var parentSite;
var isBasicMapView;
var viewingURL;
var infoWindowText;

function getSWVersion () {
	var tVersionString = "";

        if (navigator.plugins && navigator.plugins["Shockwave Flash"] && (tVersionIndex = navigator.plugins["Shockwave Flash"].description.indexOf(".")) != - 1) {
            tVersionString = navigator.plugins["Shockwave Flash"].description.substring(tVersionIndex-2, tVersionIndex+2);
        } else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )) {
		try {
                    var ShockwaveControl = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                } catch (err){}
                if (ShockwaveControl){
                    var sfVersionRaw = ShockwaveControl.getVariable("$version");
                    tVersionString = parseInt(sfVersionRaw.split(" ")[1], 10);
                }
                ShockwaveControl = null;
	}
	return tVersionString;
}

function load(_parentSite,_address, _numImg, _id, _mls, _type, _isBasicMapView) {
    parentSite = _parentSite;
    address = _address;
    numImg = _numImg;
    id = _id;
    mls = _mls;
    type = _type;
    isBasicMapView = _isBasicMapView;

    if (GBrowserIsCompatible()) {
        // Flash is installed and version 10+
        if (getSWVersion() >= 10)
            flashInstalled = true;
        // Disable for IE 6
        if (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1)
            flashInstalled = false;
        // Chrome Browser
        if ((navigator.userAgent) && navigator.userAgent.indexOf("Chrome") != -1)
            isChrome = true;
        
        map = new GMap2(document.getElementById("map"));
        map_street = new GMap2(document.getElementById("street"));
        map.addControl(new GLargeMapControl3D(true));
              
        // Special Case for Chrome Browser
        gMapTypeControl = new GMapTypeControl()
        map.addControl(gMapTypeControl);
        geocoder = new GClientGeocoder();
        showAddress(address);
    }
}

function showAddress(address) {
    if (geocoder) {
        geocoder.getLatLng(address, displayViaAddress);
    }
}

function populateMap(point, center, zoom, isHybrid){
    if (center)
        map.setCenter(point, center);
    if (zoom)
        map.setZoom(15);
    if (isHybrid)
        map.setMapType(G_HYBRID_MAP);

    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml($('.streetViewWindowURL').html());
    aPoint = point;
}

function displayViaAddressSub(point){
    if (!point) {
        var postalcode = address.substr(address.length-7);
        geocoder.getLatLng(postalcode, displayViaPostalCode);
    } else if (isBasicMapView) {
        populateMap(point, 13, null, false);
        streetview();
    } else {
        populateMap(point, 13, 15, true);
        streetview();
    }
}

function displayViaPostalCode(point){
    if (!point) {
    //alert(address + " not found");
    } else if (isBasicMapView) {
        populateMap(point, 13, null, false);
        streetview();
    } else {
        populateMap(point, 13, 15, true);
        streetview();
    }
}

function displayViaAddress(point){
    if (!point) {
        geocoder.getLatLng( address.substr(0, address.length-9), displayViaAddressSub);
    } else if (isBasicMapView) {
        populateMap(point, 13, 18, false);
        streetview();
    } else {
        populateMap(point, 13, 15, true);
        streetview();
    }

}

function displayStreetView(){
    if (globalStreetView == null) {
        displayStreetViewQueued = true;
    } else {
        globalStreetView.showstreetview(aPoint);
    }
}

function streetview(){
    // Check if map point supports street view
    panoClient = new GStreetviewClient();
    panoClient.getNearestPanorama(aPoint, processReturnedData);
}

function processReturnedData(panoData){
    var streetViewTab = 1;
    var selectedTab = $("#tabs").tabs().tabs('option', 'selected');
            
    if (panoData.code == 200 && flashInstalled){
        var streetview = new StreetViewControl();
        map.addControl(streetview);
        GEvent.addListener(marker, "click", displayStreetView);

        if (selectedTab == streetViewTab){           
            displayStreetView();
        }

    } else {
        // Disable streetview if Flash is not installed
        $('#tabs').tabs("option","disabled", [streetViewTab]);
        if (selectedTab == streetViewTab) {
            $("#tabs").tabs().tabs("select", 0);
            $('#tabs').tabs("option","disabled", [streetViewTab]);
            $.cookie('ui-tabs-1','1');
        }
    }
}


function popup(url) {
    newwindow=window.open(url,'name','height=505,width=540');
    if (window.focus) {
        newwindow.focus()
        }
    return false;
}

