//GoogleMap オブジェクト
var g_Map;

//----------	map コントロール一覧	----------------//
// SMALL/LARGE/ZOOM はどちらか片方を選択
//--------------------------------------------------------
var CTRL_SMALL	=	(1<<0);		// スモールコントローラー
var CTRL_LARGE	=	(1<<1);		// ラージコントローラー
var CTRL_TYPE	=	(1<<2);		// type設定
var CTRL_ZOOM	=	(1<<3);		// Zoom Only
var CTRL_SCALE	= 	(1<<4);		// スケール


//-------------------------------------
//	初期マップタイプ
//-------------------------------------
var TYPE_NORMAL		= 	(1<<10);	// 普通地図タイプ
var TYPE_SATELLITE	= 	(1<<11);	// サテライトタイプ
var TYPE_HYBRID		= 	(1<<12);	// デュアルタイプ


//////////////////////////////////////////////////////////////////
//ベースクラス
//////////////////////////////////////////////////////////////////
function MapBase (name) {
	
	this.id = document.getElementById(name); 
	g_Map = new GMap2(this.id);

	//マップエレメントID取得
	MapBase.prototype.getID = function() {
		return this.id;
	}
	
	//マップコントロールセット
	MapBase.prototype.setControl = function(ctrl) {
		if ( ctrl & CTRL_SMALL ){
			g_Map.addControl( new GSmallMapControl() );
		}
		else if ( ctrl & CTRL_LARGE ){
			g_Map.addControl( new GLargeMapControl() );
		}
		else if ( ctrl & CTRL_ZOOM ){
			g_Map.addControl( new GSmallZoomControl() );
		}
		
		if ( ctrl & CTRL_TYPE )
			g_Map.addControl( new GMapTypeControl() );
		
		if ( ctrl & CTRL_SCALE )
			g_Map.addControl( new GScaleControl() );
		
		
		if ( ctrl & TYPE_SATELLITE ) {
			g_Map.setMapType( G_SATELLITE_MAP );
		}
		else if ( ctrl & TYPE_HYBRID ) {
			g_Map.setMapType( G_HYBRID_MAP );
		}
		else {
			g_Map.setMapType( G_NORMAL_MAP );
		}																							
	}

	//オーバービュー作成
	MapBase.prototype.setOverview = function( width, height ) {
		width	= width ? width : 120;
		height	= height ? height : 120;
		g_Map.addControl( new GOverviewMapControl( new GSize(width,height)) );
	}
	
	//アイコン作成
	MapBase.prototype.createIcon = function( image, size_x, size_y, anc_x, anc_y ) {
		var icon 			= new GIcon();
		icon.image			= image;
		icon.iconSize		= new GSize	(size_x,size_y);
		icon.iconAnchor		= new GPoint(anc_x,anc_y);
		icon.printImage		= image.substr(0,image.length-4)+".gif";
		icon.mozPrintImage  = image.substr(0,image.length-4)+".gif";
		return icon;
		
	}
	
	//アイコン影set
	MapBase.prototype.setIconShadow = function( icon, image, size_x, size_y ) {
		icon.shadow			= image;
		icon.shadowSize		= new GSize (size_x,size_y);
		icon.printShadow	= image.substr(0,image.length-4)+".gif";
		return icon;
	}
	
	// マウスホイールのイベントを追加
	MapBase.prototype.setWheelZoom = function() {
	 	if( navigator.userAgent.match( "MSIE"   ) ){ this.id.attachEvent( "onmousewheel" , this._mouseWheelZooming ); }
		if( navigator.userAgent.match( "Gecko"  ) ){ this.id.addEventListener( "DOMMouseScroll" , this._mouseWheelZooming , false ); }
		if( navigator.userAgent.match( "Safari" ) ){ this.id.onmousewheel = this._mouseWheelZooming; }
	}
	
	
	//マウスホイール拡大縮小
	MapBase.prototype._mouseWheelZooming = function( event ) {
		if( navigator.userAgent.match( "MSIE"   ) ){ var delta = event.wheelDelta;   event.returnValue = false; }	//IE
		if( navigator.userAgent.match( "Gecko"  ) ){ var delta = event.detail * -1;  event.preventDefault();    }	//Gecko
		if( navigator.userAgent.match( "Safari" ) ){ var delta = event.wheelDelta;   event.returnValue = false; }	//Safari

		( delta < 0 ) ? g_Map.zoomOut() : g_Map.zoomIn();
	}


	//ドラッギングフラグ
	MapBase.prototype.setDragging = function( flag ) {
		flag ? g_Map.enableDragging() : g_Map.disableDragging();
	}

	//ウィンドウフラグ
	MapBase.prototype.setInfoWindow = function( flag ) {
		flag ? g_Map.enableInfoWindow() : g_Map.disableInfoWindow();
	}

	//ダブルクリックズームフラグ
	MapBase.prototype.setDClickZoom = function( flag ) {
		flag ? g_Map.enableDoubleClickZoom() : g_Map.disableDoubleClickZoom();
	}

	//なめらかズーム
	MapBase.prototype.setContZoom = function( flag ) {
		flag ? g_Map.enableContinuousZoom() : g_Map.disableContinuousZoom();
	}
}


////////////////////////////////////////////
//Ajax & GoogleMaps チェック
///////////////////////////////////////////
function checkBrowser(url)  {
	
	if( /*!checkAjax() ||*/ !GBrowserIsCompatible() ){
		if( !(navigator.userAgent.indexOf("MSIE 5.5")!=-1)){
			location.href = url;
		}
	}						
}


//////////////////////////////////////////
//Ajaxがつかえるか
/////////////////////////////////////////
function checkAjax() {
	var a,ua = navigator.userAgent;
/*	this.bw= { 
	  safari    : ((a=ua.split('AppleWebKit/')[1])?a.split('(')[0]:0)>=124 ,
	  konqueror : ((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3 ,
	  mozes     : ((a=ua.split('Gecko/')[1])?a.split(" ")[0]:0) >= 20011128 ,

	  opera     : (!!window.opera) && ((typeof XMLHttpRequest)=='function') ,
	  msie      : (!!window.ActiveXObject)?(!!createHttpRequest()):false
	}
*/	return (this.bw.safari||this.bw.konqueror||this.bw.mozes||this.bw.opera||this.bw.msie);
}

