addLoadListener(MapInit);

var OImgPreviewer = {};
var RouetData = {MapSection:'map', WinSmartHeight:320, WinSmartDrag:true, ActiveTimer:500, ActiveValue:'如何到這裡'};
var CurrentStatus = {
	//ImgPreviewer
	ImgPreviewerArray: [],
	ImgPreviewerKeyControl: [],
	AllowKeyArray: [37, 38, 39, 40, 27],
	NeedFixBack: [0, 5, 6, 9],
	
	//OLatLng
	OLatLng: {},
	
	Browser: identifyBrowser(),
	BrowserPNGfix: 'ie5,ie5mac,ie5.5,ie6',
	//method
	GetKeyCode: function(e) {
		var KeyCode;
		if (window.event && window.event.srcElement)
			KeyCode = window.event.keyCode;
		else if (e && e.target)
			KeyCode = e.keyCode;
		return KeyCode;
	},
	KeydownEvent: function(e){
		var KeyCode = CurrentStatus.GetKeyCode(e);
		if (CurrentStatus.AllowKeyArray.indexOf(KeyCode) != -1) for (var i=0; i<CurrentStatus.ImgPreviewerKeyControl.length; OImgPreviewer['ImgPreviewer'+CurrentStatus.ImgPreviewerKeyControl[i++]].KeyDownEvent(KeyCode));
	},
	ResizeEvent: function() {
		var PageSize = getPageSize();
		for (var i=0; i<CurrentStatus.ImgPreviewerArray.length; OImgPreviewer['ImgPreviewer'+CurrentStatus.ImgPreviewerArray[i++]].ResizeEvent(PageSize[2]));
		//Map
		MapStatus.ResizeEvent();
	}
};

function MapInit() {
	try {
	  document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
	
	document.getElementsByTagName('body')[0].oncontextmenu = function() { return false; };
	var GetHtml = document.getElementsByTagName('html')[0];
	GetHtml.style.overflowX = 'hidden';
	GetHtml.onkeydown = function(e) { CurrentStatus.KeydownEvent(e) };
	GetHtml.focus();
	
	//get cookie
	var MapEnviSet = MapStatus.GetCookie('MapEnviSet');
	if (MapEnviSet) MapStatus.LoadEnviSet(MapEnviSet);
	
	//map
	MapStatus.MapInit();
	
	//SetElementParameter
	MapStatus.ResizeEvent();
	
	if (IconInfo.length == 0) { Element.hide('BackPOI'); return; }
	
	//WinInfoB
	$('WinInfoB').PosX = -1000;
	$('WinInfoB').PosY = 0;
	$('WinInfoB').isVisible = false;
	if (CurrentStatus.BrowserPNGfix.indexOf(CurrentStatus.Browser) != -1) {
		$('WinInfoBTopShadow').style.background = 'url(/img/transparent.gif)';
		$('WinInfoBTopShadow').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/img/Map/WinInfoB/BackRT.png, sizingMethod=scale)';
		$('WinInfoBBottom').style.background = 'url(/img/transparent.gif)';
		$('WinInfoBBottom').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/img/Map/WinInfoB/BackBottom.png, sizingMethod=scale)';
		$('WinInfoBMidShadow').style.background = 'url(/img/transparent.gif)';
		$('WinInfoBMidShadow').style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/img/Map/WinInfoB/BackRM.png, sizingMethod=scale)';
	}//end if
	$('WinInfoBBtn').onmouseover = function() { this.style.backgroundPosition = '-13px 0px'; };
	$('WinInfoBBtn').onmouseout = function() { this.style.backgroundPosition = '0px 0px'; };
	$('WinInfoBBtn').onclick = function() { OImgPreviewer.ImgPreviewerPicker.ClearWin(); };
	MapStatus.WinInfoBInit();
	
	var PhotoIconInfo = [
		{img:'/img/transparent.gif', Title:'transparent', linkset:'transparent'}
	];
	RollingPrintPhotoMap = new RollingPrint('PhotoMap', {CodeSection:'RollingMainSection', IconWidth:90, IconHeight:90, ColAmt:3, Timer:5000, IconInfo:PhotoIconInfo});
		
	//ImgPreviewer
	var ImgPreviewerW = (MapType == 'Main') ? 985 : 940;
	OImgPreviewer.ImgPreviewerPicker = new ImgPreviewer('Picker', {CodeSection:'PickerSection', Width:ImgPreviewerW, IconWidth:40, FuncID:0, IconInfo:IconInfo, Resizeable:false, KeyControlable:true});//FuncID Start at 0
	var ElementPosArray = getPosition($('map'));
	$('PickerSection').style.left = ElementPosArray[0] + 'px';
	$('PickerSection').style.top = ElementPosArray[1] + 485 - 100 + 'px';
	
	Event.observe(window, "resize", CurrentStatus.ResizeEvent, false);
	
	$('BtnRollingL').onclick = function() {
		clearTimeout(RollingPrintPhotoMap.TimerIntervalID);
		RollingPrintPhotoMap.VaryMode = 'Left';
		RollingPrintPhotoMap.VaryAction();
	}
	$('BtnRollingR').onclick = function() {
		clearTimeout(RollingPrintPhotoMap.TimerIntervalID);
		RollingPrintPhotoMap.VaryMode = 'Right';
		RollingPrintPhotoMap.VaryAction();
	}
}