// JavaScript Document
/*@cc_on _d=document;eval('var document=_d')@*/

/* ブラウザごとのCSS出力 */
if (navigator.userAgent.indexOf("MSIE 6") > -1) {
	document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"./css/ie6.css\" media=\"screen\" />");
}

if (navigator.userAgent.indexOf("MSIE") > -1) {
	document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"./css/ie.css\" media=\"screen\" />");
}

var map;
var marker;
var resizeInterval;
var zoom = 17;
var windowWidth = 0;
var windowHeight = 0;
var ln;
var lt;
var title;
var date;
var dream;

function changeMap(lng, lat, title_str, date_str, dream_str) {
	ln = lng;
	lt = lat;
	title = title_str;
	date = date_str;
	dream = dream_str;
	if (marker) map.removeOverlay(marker);
	new Effect.Fade("satelite", {
		from:     1.0,
		to:       0.0,
		fps:      30,
		duration: 1
	});
	setTimeout(showMap, 1200);
};

function showMap() {
	map.setCenter(new GLatLng(lt, ln), zoom);
	map.setMapType(G_SATELLITE_MAP);
	setTimeout(appear, 1000);
}

function appear() {
	new Effect.Appear("satelite", {
		from:      0.1,
		to:        1.0,
		fps:       30,
		duration:  5
	});
	setTimeout(showInfoWindow, 5000);
};

function pan() {
	map.panBy(new GSize(0,1));
};

function onResize() {
	clearInterval(resizeInterval);
	resizeInterval = setInterval(doResize, 1000);
}

function doResize() {
	clearInterval(resizeInterval);
	if(navigator.userAgent.indexOf("MSIE") > -1){
		windowWidth = document.documentElement.clientWidth - 275;
		windowHeight = document.documentElement.clientHeight;
	}else{
		windowWidth = innerWidth - 275;
		windowHeight = innerHeight;
	}
	$("satelite").style.width = windowWidth + "px";
	$("satelite").style.height = windowHeight + "px";
	map = new GMap2($("satelite"), {size : new GSize(windowWidth, windowHeight)});
	//map.disableDragging();
	map.setCenter(new GLatLng(lt, ln), zoom);
	map.setMapType(G_SATELLITE_MAP);
	showInfoWindow();
}

function init() {
	//swfobject
	var so = new SWFObject("indexmenu.swf?balloonenable=1&fromroot=0", "indexmenu", "275", "543", "8");
	so.write("flashcontent");
}

function loadGmap(lng, lat, title_str, date_str, dream_str) {
	if (GBrowserIsCompatible()) {
		ln = lng;
		lt = lat;
		title = title_str;
		date = date_str;
		dream = dream_str;
		doResize();
		
		window.onresize = onResize;
		setInterval(pan, 100);
	}
}

function showInfoWindow() {
	if (marker) map.removeOverlay(marker);
	var temp_marker = new GMarker(new GLatLng(lt, ln));
	marker = temp_marker;
	map.addOverlay(marker);
	var openMarkerInfo = function() {
		temp_marker.openInfoWindowHtml('<div class="dreamInfoContainer"><p class="head"><img src="/images/topbanner/title.gif" width="191" height="17" /></p>' +
	        	'<dl class="dreamInfo"><dt class="firstline"><img src="/images/topbanner/lt_title.gif" width="48" height="14" /></dt><dd class="lttext">' + lt + '</dd>' +
	    		'<dt class="firstline"><img src="/images/topbanner/ln_title.gif" width="57" height="14" /></dt><dd class="lntext">' + ln + '</dd>' +
	    		'<dt><img src="/images/topbanner/title_title.gif" width="37" height="14" /></dt><dd>' + title + '</dd>' +
	    		'<dt><img src="/images/topbanner/date_title.gif" width="27" height="14" /></dt><dd class="datetext">' + date + '</dd>' +
	    		'<dt><img src="/images/topbanner/dream_title.gif" width="38" height="14" /></dt><dd>' + dream + '</dd></dl><div class="clear"></div></div>');
	}
	openMarkerInfo();
    GEvent.addListener(temp_marker, "click", function(overlay, point){
   		openMarkerInfo();
    });
}


