GMap2.prototype.fMapView = false;
GMap2.prototype.fMapDefaultWidth = 0;
GMap2.prototype.fMapDefaultHeight = 0;

GMap2.prototype.switchMapViewMainPage = function(expand, width, height){

	if (expand == null) {
		expand = !this.fMapView;
	}
	
	if (height) {
		height = height + $('news_on_flagatrip').clientHeight;
	}
	
	var mapElement = $(this.getContainer());

	if (expand && this.fMapDefaultWidth == 0) {
		this.fMapDefaultWidth = mapElement.clientWidth;
	}
	
	if (expand && this.fMapDefaultHeight == 0) {
		this.fMapDefaultHeight = mapElement.clientHeight;
	}
	
	mapElement.addClass('animation');
	new Fx.Morph(mapElement, {
		duration: 2000,
		link: 'cancel',
		transition: Fx.Transitions.Back.easeInOut,
		onComplete: function() {
			mapElement.removeClass('animation');
				this.checkResize();
				this.returnToSavedPosition();
		}.bind(this)
	}).start({'width': expand ? width : this.fMapDefaultWidth, 'height': expand ? height : this.fMapDefaultHeight});
	this.fMapView = expand;
	return this.fMapView;
}

function showInfoWindow(f) {
	if (f && f.options && f.options.cityId) {
		new Request({url: 'ajax.php?action=planatrip.randomcover&place=' + f.options.cityId, 
			onComplete: function(data) {
				data = JSON.decode(data);
				if(data) {
					f.options.rCnt ? rCnt = '<a href="http://'+data.baseHost+'/guides'+f.options.url+'/reports">Отчётов: '+f.options.rCnt+'</a>' : rCnt = 'Отчётов: '+f.options.rCnt;
					f.options.mCnt ? mCnt = '<a href="http://'+data.baseHost+'/guides'+f.options.url+'/messages">Сообщений: '+f.options.mCnt+'</a>' : mCnt = 'Сообщений: '+f.options.mCnt;
					f.options.pfCnt ? pfCnt = '<a href="http://'+data.baseHost+'/guides'+f.options.url+'/pfolders">Фотогалерей: '+f.options.pfCnt+'</a>' : pfCnt = 'Фотогалерей: '+f.options.pfCnt;
					if(data.photoId)
					{
						f.openInfoWindowHtml(
							'<div style="padding:4px 6px">' +
								f.options.info +
								'<div id="planatrip_left_right_col">' +
									'<div id="planatrip_left_col">' +
										'<div class="round_corners" style="margin-top:10px;">' +
											'<span class="wrap">' +
												'<a class="photo" href="http://' + data.memberHost + '/photo_files/id/' + data.folderId + '.html">' +
													'<img alt="' + data.folderName + '" src="http://' + data.memberHost + '/photos/55!x55!/' + data.photoId + '.' + data.photoExt + '" height="55px" width="55px"/>' +
												'</a>' +
												'<span class="rc1"></span><span class="rc3"></span><span class="rc7"></span><span class="rc9"></span>' +
											'</span>' +
										'</div>' +
									'</div>' +
									'<div id="planatrip_right_col">' +
										'<div style="padding-top: 10px">'
										 			+ rCnt +
											'<br/>' + mCnt +
											'<br/>' + pfCnt +
										'</div>' +
									'</div>' +
								'</div>' +
							'</div>'
						);
					} else {
						f.openInfoWindowHtml(
							'<div style="padding:4px 6px">' +
								f.options.info +
								'<div style="padding-top: 10px">'
								 			+ rCnt +
									'<br/>' + mCnt +
									'<br/>' + pfCnt +
								'</div>' +
							'</div>'
						);
					};
				};
			},
			method:'get'
		}).send();
	}
}

function mapClickHandler(f) {
	if (f && f.options && f.options.cityId) {
		var mapElement = $(this.getContainer());
		if (mapElement.clientWidth == 543) {
			$('coll_uncoll').innerHTML = window.gmap && gmap.switchMapViewMainPage(null, 936, 215) ? 'Свернуть карту' : 'Развернуть карту';
		}
		showInfoWindow(f);
	}
}
