﻿(function($, module) {

//-------
// MARKER
//-------

    $.Marker.prototype.toGoogle = function() {
        var options = {};
        if(this.labelText){
            options.title =  this.labelText;
        }
        if(this.iconUrl){
            var icon = new GIcon(G_DEFAULT_ICON, this.iconUrl);
            icon.printImage = icon.mozPrintImage = icon.image;
            if(this.iconSize) {
                icon.iconSize = new GSize(this.iconSize[0], this.iconSize[1]);
                var anchor;
                if(this.iconAnchor) {
                    anchor = new GPoint(this.iconAnchor[0], this.iconAnchor[1]);
                }
                else {
                    // FIXME: hard-coding the anchor point
                    anchor = new GPoint(this.iconSize[0]/2, this.iconSize[1]/2);
                }
                icon.iconAnchor = anchor;
            }
            if(this.iconShadowUrl) {
                icon.shadow = this.iconShadowUrl;
                if(this.iconShadowSize) {
                    icon.shadowSize = new GSize(this.iconShadowSize[0], this.iconShadowSize[1]);
                }
            }
            options.icon = icon;
        }
        if(this.draggable){
            options.draggable = this.draggable;
        }
        var gmarker = new GMarker( this.location.toGoogle(),options);

        if(this.infoBubble){
            var theInfo = this.infoBubble;
            var event_action;
            if(this.hover) {
                event_action = "mouseover";
            }
            else {
                event_action = "click";
            }
            GEvent.addListener(gmarker, event_action, function() {
                gmarker.openInfoWindowHtml(theInfo, {
                    maxWidth: 100
                });
            });
        }

        if(this.hoverIconUrl){
            GEvent.addListener(gmarker, "mouseover", function() {
                gmarker.setImage(this.hoverIconUrl);
            });
            GEvent.addListener(gmarker, "mouseout", function() {
                gmarker.setImage(this.iconUrl);
            });
        }

        if(this.infoDiv){
            var theInfo = this.infoDiv;
            var div = this.div;
            var event_action;
            if(this.hover) {
                event_action = "mouseover";
            }
            else {
                event_action = "click";
            }
            GEvent.addListener(gmarker, event_action, function() {
                document.getElementById(div).innerHTML = theInfo;
            });
        }

        return gmarker;
    };

    // Register
	$.registerModule(module);

})(mxn, 'marker.google');