﻿// JScript File

function ShowLocationPin() 
{

	var center = map.getCenter();

}



// Create a marker whose info window displays the info.
function createMarker(point, LocationName, LocationID, LocationPath) 
{
    //alert(queryString("TOUR"));
	//Prepare the map with icons and infowindows.
	var icon = new GIcon();
	var presentLocation = false;
	
	if (LocationID == queryString("TOUR"))
	{
	   	icon.iconSize = new GSize(12, 20);
    	icon.shadowSize = new GSize(22, 20);

	    icon.image="./images/tour.png";
	    icon.shadow="./images/tour_shadow.png";
	    presentLocation = true;

	    initialLong = point.lat();
		initialLatd = point.lng();
	    
	}
	else if (queryString("TOUR") == "false" && LocationID == firstLocation)
	{
	    icon.iconSize = new GSize(12, 20);
    	icon.shadowSize = new GSize(22, 20);

	    icon.image="./images/tour.png";
	    icon.shadow="./images/tour_shadow.png"; 
	    presentLocation = true;
	    
	    initialLong = point.lat();
		initialLatd = point.lng();

	}
	else
	{
	    icon.iconSize = new GSize(12, 20);
	    icon.shadowSize = new GSize(22, 20);
	    icon.image="./images/mm_20_red.png";
	    icon.shadow="./images/mm_20_shadow.png";
	}
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);

	var marker = new GMarker(point, icon);
	
	// Show this marker's info in the info window when it is clicked.
	if ( LocationName != "" )
	{
	    //if ( presentLocation )
	    {
		    presentLocation = false;
//		    GEvent.addListener(marker, 'click', function() 	{

//             var nextLink = "Default.aspx?TOUR=" + LocationID;
//             window.location = nextLink;
//		    });
		    
		    GEvent.addListener(marker, 'click', function() 	{
		    
		    var nextLink = "Default.aspx?TOUR=" + LocationID;
            marker.openInfoWindowHtml(LocationName + "<br><a href='" + nextLink + "'><div style='height:100px;'><img src='Panorama/Thumbnail/" + LocationPath + "'/></div><br>Virtual Tour</a>");
             
		    });
		    
//		    GEvent.addListener(marker, 'mouseout', function() 	{
//            marker.closeInfoWindow() ;
//             
//		    });
	
		}
	}
	else
	{
		GEvent.addListener(marker, 'click', function() 	{
			marker.openInfoWindowHtml("<b>"+infoName+"</b><br>お店は存在しますが情報は登録されてありません！！");
		});
	}
	
	return marker;
}	


/**
 * @author Marco Alionso Ramirez, marco@onemarco.com
 * @url http://onemarco.com
 * @version 1.0
 * This code is public domain
 */

/**
 * The Tooltip class is an addon designed for the Google Maps GMarker class. 
 * @constructor
 * @param {GMarker} marker
 * @param {String} text
 * @param {Number} padding
 */
function Tooltip(marker, text, path, padding){
	this.marker_ = marker;
	//this.text_ = "<img src='Panorama/Thumbnail/"+path+"'><br>" + text.replace("\n\r","");
	this.text_ = text.replace("\n\r","");
	this.padding_ = padding;
}

Tooltip.prototype = new GOverlay();

Tooltip.prototype.initialize = function(map){
	var div = document.createElement("div");
	//div.appendChild(document.createTextNode(this.text_));
	div.innerHTML = (this.text_);
	div.className = 'tooltip';
	div.style.position = 'absolute';
	div.style.visibility = 'hidden';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	this.map_ = map;
	this.div_ = div;
}

Tooltip.prototype.remove = function(){
	this.div_.parentNode.removeChild(this.div_);
}

Tooltip.prototype.copy = function(){
	return new Tooltip(this.marker_,this.text_,this.padding_);
}

Tooltip.prototype.redraw = function(force){
	if (!force) return;
	var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	var iconAnchor = this.marker_.getIcon().iconAnchor;
	var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);
	var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;
	this.div_.style.top = yPos + 'px';
	this.div_.style.left = xPos + 'px';
}

Tooltip.prototype.show = function(){
	this.div_.style.visibility = 'visible';
}

Tooltip.prototype.hide = function(){
	this.div_.style.visibility = 'hidden';
}


//This script return the parameter value of URL 
function PageQuery(q) 
{
    if(q.length > 1) this.q = q.substring(1, q.length);
       else this.q = null;
    this.keyValuePairs = new Array();
    if(q) 
    {
        for(var i=0; i < this.q.split("&").length; i++) 
        {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            if(this.keyValuePairs[j].split("=")[0] == s)
            return this.keyValuePairs[j].split("=")[1];
        }
    return false;
    }
    this.getParameters = function() {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key)
{
    var page = new PageQuery(window.location.search); 
    return unescape(page.getValue(key)); 
}


// Set cookies for Zoom Level
// Cookie name for this is always ZoomLevel
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


// This is to create custom Zoom In and Zoom Out button and to 
// set the zoom value in cookies
function TextualZoomControl() {}

    TextualZoomControl.prototype = new GControl();
    // position properly.
    TextualZoomControl.prototype.initialize = function(map) {  
    var container = document.createElement("div");  
    var zoomInDiv = document.createElement("div");  
    this.setButtonStyle_(zoomInDiv);  
    container.appendChild(zoomInDiv);  
    zoomInDiv.appendChild(document.createTextNode("Zoom Up"));  
    GEvent.addDomListener(zoomInDiv, "click", function() {    map.zoomIn();  createCookie("ZoomLevel",map.getZoom(),1); });  
    var zoomOutDiv = document.createElement("div");  
    this.setButtonStyle_(zoomOutDiv);  
    container.appendChild(zoomOutDiv);  
    zoomOutDiv.appendChild(document.createTextNode("Zoom Down"));  
    GEvent.addDomListener(zoomOutDiv, "click", function() {    map.zoomOut(); createCookie("ZoomLevel",map.getZoom(),1); });  
    map.getContainer().appendChild(container);  return container;
    }


    TextualZoomControl.prototype.getDefaultPosition = function() {  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
    }

    TextualZoomControl.prototype.setButtonStyle_ = function(button) {  
    button.style.textDecoration = "none";  
    button.style.color = "#0000cc";  
    button.style.backgroundColor = "white";  
    button.style.font = "small Arial";  
    button.style.border = "1px solid black";  
    button.style.padding = "2px";  button.style.marginBottom = "3px";  
    button.style.textAlign = "center";  button.style.width = "6em";  
    button.style.cursor = "pointer";
    }
			