var StreetWrapper = function () {
	this.active = false;
	this._onMoveCallback = null;
	this.firstTime = true;
	this.isFirstView = true;
    street = new GStreetviewPanorama(document.getElementById("street"));
    var position = urlInfo.currentPosition || map.getCenter();
    currentPos = new GLatLng(position.lat(), position.lng());
    myPOV = {
        yaw: 180,
        pitch: -20
    };
	var self = this;
    GEvent.addListener(street, "initialized", function(info){
		if (self._onMoveCallback) {
			self._onMoveCallback();
			self._onMoveCallback = null;
		};
		var position = info.latlng;
		if (!StreetWrapper.movingAuto) {
			$('satIcon').hide();
			Player.reset();
		} else {
			StreetWrapper.movingAuto = false;
		}
		urlInfo.registerPosition(position,true);
    });
	var position = urlInfo.currentPosition||currentPos;
	this.moveTo(urlInfo.currentPosition);
};

StreetWrapper.prototype.moveTo = function (latLng) {
	var self = this;
	streetClient.getNearestPanoramaLatLng(latLng , function (latLng) {
		self._prevLatLng = latLng;
		street.setLocationAndPOV(latLng,street.getPOV());
	});
	
}

StreetWrapper.prototype.show = function(latLng){
	this.active = true;
		var position = latLng || urlInfo.currentPosition || map.getCenter();

	if (this._prevLatLng && position.lat()==this._prevLatLng.lat() 
		&& position.lng()==this._prevLatLng.lng()) {
		this._show();
	} else {
		var self = this;
		this._onMoveCallback = function(){
			self._show();
		};
		//setTimeout(
		//function(){
		street.setLocationAndPOV(position, street.getPOV());
		//	},100);
	}
	this.firstTime = false;
	this._prevLatLng = position;
	StreetWrapper.movingAuto = true;
};
StreetWrapper.prototype._show = function(){
	Player.currentMode = MODE_STREET;
	wMap.hide();
	wCanvas.hide();
	$('street').width = $('mapWrapper').style.width;
	var areaOffset = Element.cumulativeOffset($('mapContainer'));
	$('buttonCloseStreet').show();
	SatMap.hideAllMap();
	$('street').style.top = (areaOffset[1]) + 'px';
	$('street').style.left = (areaOffset[0]) + 'px';
	Player.execStartPlay();
	setFlashAttributes();
};
function makeEmbedWmodeTransparent(embed) {
	try {
		embed.wmode = 'opaque'
		embed.setAttribute('wmode','opaque');
	} catch (e) {}
	/*
	var wmode = embed.getAttribute("wmode");
	
	var parent = embed.parentNode;
	var span = document.createElement("span");
	embed =	parent.replaceChild(span, embed);
	span.appendChild(embed);
	var html = span.innerHTML;
	var html2 = html.replace(/<EMBED /i, '<embed wmode="transparent" ');
	span.innerHTML = html2;
	*/
}

function setFlashAttributes () {
    if (!flashInit) {
		var objs = document.getElementsByTagName('OBJECT');
		for (var i=0, l=objs.length; i<l; i++) {
			var flashObj = objs[i];
			makeEmbedWmodeTransparent(flashObj)
			/*
	        flashObj.style.zIndex = 1;
    	    flashObj.wmode = 'transparent';
    	    */
		}
    }
       flashInit = true;
}
StreetWrapper.prototype.hide = function () {
	this.active = false;
	$('street').style.left = '-600px';
};
StreetWrapper.prototype.restore = function () {
	if (this.active) this.show();
}
