//<![CDATA[

var centreLat=0.0;
var centreLon=0.0;
var initialZoom=4;
var minZoom = 3;
var maxZoom = 5;

var sh = window.innerHeight;
var sw = window.innerWidth;
/*
centreLat=3+(30/sh*100);
centreLon=-128+(60/sw*100);
*/
if (sw < 500){	// iPhone 480px
	initialZoom=3;
}
else if (sw < 1460){	// WXGA+ 1440px
	initialZoom=4;
}
else {
	initialZoom=5;
//	centreLat-=sh/250+1;
}

var imageWraps=true; //SET THIS TO false TO PREVENT THE IMAGE WRAPPING AROUND
var map; //the GMap2 itself

/////////////////////
//Custom projection
/////////////////////
function CustomProjection(a,b){
this.imageDimension=65536;
this.pixelsPerLonDegree=[];
this.pixelOrigin=[];
this.tileBounds=[];
this.tileSize=256;
this.isWrapped=b;
var b=this.tileSize;
var c=1;
for(var d=0;d<a;d++){
var e=b/2;
this.pixelsPerLonDegree.push(b/360);
this.pixelOrigin.push(new GPoint(e,e));
this.tileBounds.push(c);
b*=2;
c*=2
}
}

CustomProjection.prototype=new GProjection();

CustomProjection.prototype.fromLatLngToPixel=function(latlng,zoom){
var c=Math.round(this.pixelOrigin[zoom].x+latlng.lng()*this.pixelsPerLonDegree[zoom]);
var d=Math.round(this.pixelOrigin[zoom].y+(-2*latlng.lat())*this.pixelsPerLonDegree[zoom]);
return new GPoint(c,d)
};

CustomProjection.prototype.fromPixelToLatLng=function(pixel,zoom,unbounded){
var d=(pixel.x-this.pixelOrigin[zoom].x)/this.pixelsPerLonDegree[zoom];
var e=-0.5*(pixel.y-this.pixelOrigin[zoom].y)/this.pixelsPerLonDegree[zoom];
return new GLatLng(e,d,unbounded)
};

CustomProjection.prototype.tileCheckRange=function(tile,zoom,tilesize){
var tileBounds=this.tileBounds[zoom];
if (tile.y<0 || tile.y >= tileBounds) {return false;}
if (this.isWrapped) {
if (tile.x<0 || tile.x>=tileBounds) { 
tile.x = tile.x%tileBounds; 
if (tile.x < 0) {tile.x+=tileBounds} 
}
}
else { 
if (tile.x<0 || tile.x>=tileBounds) {return false;}
}
return true;
}

CustomProjection.prototype.getWrapWidth=function(zoom) {
return this.tileBounds[zoom]*this.tileSize;
}
////////////////////////////////////////////////////////////////////////////

function customGetTileURL(a,b) {
//converts tile x,y into keyhole string

var c=Math.pow(2,b);

var d=a.x;
var e=a.y;
var f="t";
for(var g=0;g<b;g++){
c=c/2;
if(e<c){
if(d<c){f+="q"}
else{f+="r";d-=c}
}
else{
if(d<c){f+="t";e-=c}
else{f+="s";d-=c;e-=c}
}
}
return "index-tiles/"+f+".jpg"
}

function getWindowHeight() {
if (window.self&&self.innerHeight) {
return self.innerHeight;
}
if (document.documentElement&&document.documentElement.clientHeight) {
return document.documentElement.clientHeight;
}
return 0;
}

function resizeMapDiv() {
//Resize the height of the div containing the map.
//Do not call any map methods here as the resize is called before the map is created.
var d=document.getElementById("map");
var offsetTop=0;
for (var elem=d; elem!=null; elem=elem.offsetParent) {
offsetTop+=elem.offsetTop;
}
var height=getWindowHeight()-offsetTop-16;
if (height>=0) {
d.style.height=height+"px";
}
}

function load() {
if (GBrowserIsCompatible()) {
resizeMapDiv();
var copyright = new GCopyright(1,
new GLatLngBounds(new GLatLng(-90, -180),
new GLatLng(90, 180)),
0,
"Copyright &copy; 2010 <a href=\"http://o-aiw.com/diary/contact\">// Office AIW //</a> All RightS Reserved.");
var copyrightCollection = new GCopyrightCollection("");
copyrightCollection.addCopyright(copyright);

//create a custom picture layer
var pic_tileLayers = [ new GTileLayer(copyrightCollection , 0, 17)];
pic_tileLayers[0].getTileUrl = customGetTileURL;
pic_tileLayers[0].isPng = function() { return false; };
pic_tileLayers[0].getOpacity = function() { return 1.0; };
var proj=new CustomProjection(6,imageWraps);
var pic_customMap = new GMapType(pic_tileLayers, proj, "Pic",
{maxResolution:5, minResolution:2, errorMessage:"Data not available"});

//Now create the custom map. Would normally be G_NORMAL_MAP,G_SATELLITE_MAP,G_HYBRID_MAP
map = new GMap2(document.getElementById("map"),{ backgroundColor: "#FFFFFF", mapTypes:[pic_customMap]});
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.enableDoubleClickZoom();
map.enableContinuousZoom();
map.enableScrollWheelZoom();
map.setCenter(new GLatLng(centreLat, centreLon), initialZoom, pic_customMap);

//登録されているマップタイプ全てを取得して
//ズームレベルの制限するメソッドをオーバーライド
var maptypes = map.getMapTypes();
for (var i = 0; i < maptypes.length; i++) {
	maptypes[i].getMinimumResolution = function() {
		return minZoom;
	};
	maptypes[i].getMaximumResolution = function() {
		return maxZoom;
	};
}

/////////////////////////////////////////////////////////////////////////////////////
//Add any markers here e.g.
//map.addOverlay(new GMarker(new GLatLng(x,y)));
/////////////////////////////////////////////////////////////////////////////////////
// アイコンオプションの設定
var icon = new GIcon();
icon.image = "http://o-aiw.com/images/check_icon.png";
icon.iconSize = new GSize(103, 36);
//icon.iconSize = new GSize(42, 36);
icon.iconAnchor = new GPoint(17, -5);

// お問い合わせ
var latlng_inq = new GLatLng(-0.55, -33.0);
var mark_inq = new GMarker(latlng_inq, icon);
// マーカーの表示
map.addOverlay(mark_inq);
// クリックイベント
GEvent.addListener(mark_inq, "click", function(){
// インフォウィンドウの表示
//var text_inq = "";
//map.openInfoWindow(latlng_inq, document.createTextNode(text_inq));
map.openInfoWindowHtml(latlng_inq, html_inq);
})

// 略歴
var latlng_career = new GLatLng(-33.0, 105.0);
var mark_career = new GMarker(latlng_career, icon);
// マーカーの表示
map.addOverlay(mark_career);
// クリックイベント
GEvent.addListener(mark_career, "click", function(){
// インフォウィンドウの表示
//var text_career = "";
//map.openInfoWindow(latlng_career, document.createTextNode(text_career));
map.openInfoWindowHtml(latlng_career, html_career);
})

// 実績
var latlng_exp1 = new GLatLng(-26.08, 40.0);
var mark_exp1 = new GMarker(latlng_exp1, icon);
// マーカーの表示
map.addOverlay(mark_exp1);
// クリックイベント
GEvent.addListener(mark_exp1, "click", function(){
// インフォウィンドウの表示
map.openInfoWindowHtml(latlng_exp1, html_exp1);
})

var latlng_exp2 = new GLatLng(-38.35, 40.0);
var mark_exp2 = new GMarker(latlng_exp2, icon);
// マーカーの表示
map.addOverlay(mark_exp2);
// クリックイベント
GEvent.addListener(mark_exp2, "click", function(){
// インフォウィンドウの表示
map.openInfoWindowHtml(latlng_exp2, html_exp2);
})

}
}

//]]>
