﻿var map , getXML , HotelIcon, PointIcon ;
var aryMarker = new Array();
var aryLabel = new Array();
var Defautl_ShowLabel = false;
var _HItem;
var _PItem;
var ActColor = '#FFCC00';
var bgColor = '#FFE888';
var fgColor = '#F7F5F0';



function changeColor(div,s) {

    
    if(div.id == _HItem)
        div.style.backgroundColor = ActColor;
    else
        div.style.backgroundColor = (s==1)?bgColor:fgColor;
    
}

function changeColor_p(div,s) {

    if(div.id == _PItem)
        div.style.backgroundColor = ActColor;
    else
        div.style.backgroundColor = (s==1)?bgColor:fgColor;

}

function showLabelName() {
    Defautl_ShowLabel = (!Defautl_ShowLabel);
    var ctl = document.getElementById("ctlLabelsw");
    for (var labelkey in aryLabel) {
            if(Defautl_ShowLabel) {
                ctl.className = 'markertip';
                aryLabel[labelkey].show();
            } else {
                ctl.className = 'ShowLabel';
                aryLabel[labelkey].hide();
            }
    }
}



function createMarker(point,html,Icon,key) {
    
    var marker = new GMarker(point,{icon:Icon});

   
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
    });

    GEvent.addListener(marker, "mouseover", function() {
        
        aryLabel[key].show();
    });
    
    GEvent.addListener(marker, "mouseout", function() {
        if(!Defautl_ShowLabel) aryLabel[key].hide();
    });

    return marker;
}

function SetPoint(PointPKey){
       
    if(_PItem) 
        document.getElementById(_PItem).style.backgroundColor = fgColor;
        
    _PItem = 'P' + PointPKey;
        document.getElementById(_PItem).style.backgroundColor = ActColor;
    
    
    
    LoadDat(PointPKey,'Point',true);  

}



function changeHotelFnTitle(strtitle) {

    document.getElementById('HotelFnTitle').innerHTML =  strtitle;

}

function changePointFnTitle(strtitle) {

    document.getElementById('PointFnTitle').innerHTML = '['+ strtitle + ']鄰近景點';
    
}


function triggerFirstHotel() {
    var divHotelList = document.getElementById('divHotelList');
        if(divHotelList.childNodes.length > 0) {
            map.clearOverlays();
            aryMarker=[];
            aryLabel=[];
            var firstHotel = document.getElementById('firstHotel');
            divHotelList.childNodes[0].style.backgroundColor = ActColor;
            //firstHotel.fireEvent("onclick");
            
            
            var evt;
            var el = document.getElementById('firstHotel');
            if (document.createEvent){
            evt = document.createEvent("MouseEvents");
            evt.initMouseEvent("click", true, true, window,
            0, 0, 0, 0, 0, false, false, false, false, 0, null);
            }
            (evt)? el.dispatchEvent(evt):(el.click && el.click());
        }
}

function ShowAllHotel() {
    var h = document.getElementById("divHotelList");

    for(var i=0;i < h.childNodes.length;i++) {
        
       
        LoadDat(h.childNodes[i].id.substr(1),'Hotel',false);
    }

}

function ShowAllPoint() {
    var h = document.getElementById("divPointList");

    for(var i=0;i < h.childNodes.length;i++) {
        
       
        LoadDat(h.childNodes[i].id.substr(1),'Point',false);
    }

}


// 繼承 Goverlay

      function ELabel(point, html, classname, pixelOffset, percentOpacity, overlap) {
        // Mandatory parameters
        this.point = point;
        this.html = html;
        
        // Optional parameters
        this.classname = classname||"";
        this.pixelOffset = pixelOffset||new GSize(0,0);
        if (percentOpacity) {
          if(percentOpacity<0){percentOpacity=0;}
          if(percentOpacity>100){percentOpacity=100;}
        }        
        this.percentOpacity = percentOpacity;
        this.overlap=overlap||false;
        this.hidden = false;

      
      ELabel.prototype = new GOverlay();

      ELabel.prototype.initialize = function(map) {
        var div = document.createElement("div");
        div.style.position = "absolute";
        div.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);
        this.map_ = map;
        this.div_ = div;
        if (this.percentOpacity) {        
          if(typeof(div.style.filter)=='string'){div.style.filter='alpha(opacity:'+this.percentOpacity+')';}
          if(typeof(div.style.KHTMLOpacity)=='string'){div.style.KHTMLOpacity=this.percentOpacity/100;}
          if(typeof(div.style.MozOpacity)=='string'){div.style.MozOpacity=this.percentOpacity/100;}
          if(typeof(div.style.opacity)=='string'){div.style.opacity=this.percentOpacity/100;}
        }
        if (this.overlap) {
          var z = GOverlay.getZIndex(this.point.lat());
          this.div_.style.zIndex = z;
        }
        if (this.hidden) {
          this.hide();
        }
      }

      ELabel.prototype.remove = function() {
        this.div_.parentNode.removeChild(this.div_);
      }

      ELabel.prototype.copy = function() {
        return new ELabel(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
      }

      ELabel.prototype.redraw = function(force) {
        var p = this.map_.fromLatLngToDivPixel(this.point);
        var h = parseInt(this.div_.clientHeight);
        this.div_.style.left = (p.x + this.pixelOffset.width) + "px";
        this.div_.style.top = (p.y +this.pixelOffset.height - h) + "px";
      }

      ELabel.prototype.show = function() {
        if (this.div_) {
          this.div_.style.display="";
          this.redraw();
        }
        this.hidden = false;
      }
      
      ELabel.prototype.hide = function() {
        if (this.div_) {
          this.div_.style.display="none";
        }
        this.hidden = true;
      }
      
      ELabel.prototype.isHidden = function() {
        return this.hidden;
      }
      
      ELabel.prototype.supportsHide = function() {
        return true;
      }

      ELabel.prototype.setContents = function(html) {
        this.html = html;
        this.div_.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
        this.redraw(true);
      }
      
      ELabel.prototype.setPoint = function(point) {
        this.point = point;
        if (this.overlap) {
          var z = GOverlay.getZIndex(this.point.lat());
          this.div_.style.zIndex = z;
        }
        this.redraw(true);
      }
      
      ELabel.prototype.setOpacity = function(percentOpacity) {
        if (percentOpacity) {
          if(percentOpacity<0){percentOpacity=0;}
          if(percentOpacity>100){percentOpacity=100;}
        }        
        this.percentOpacity = percentOpacity;
        if (this.percentOpacity) {        
          if(typeof(this.div_.style.filter)=='string'){this.div_.style.filter='alpha(opacity:'+this.percentOpacity+')';}
          if(typeof(this.div_.style.KHTMLOpacity)=='string'){this.div_.style.KHTMLOpacity=this.percentOpacity/100;}
          if(typeof(this.div_.style.MozOpacity)=='string'){this.div_.style.MozOpacity=this.percentOpacity/100;}
          if(typeof(this.div_.style.opacity)=='string'){this.div_.style.opacity=this.percentOpacity/100;}
        }
      }

      ELabel.prototype.getPoint = function() {
        return this.point;
      }
      ELabel.prototype.U = function() {
        return this.point;
      }
      ELabel.prototype.V = function() {
        return this.point;
      }
      ELabel.prototype.W = function() {
        return this.point;
      }
      ELabel.prototype.X = function() {
        return this.point;
      }
      ELabel.prototype.Y = function() {
        return this.point;
      }
      ELabel.prototype.Z = function() {
        return this.point;
      }

      } 
