﻿var MapIconMaker = {};

//Create Image for Weather Symbols(Sky,Temp & Wind)
function GetWeatherIcon(iconName) {
    //debugger;
    // Create a base icon for all of our markers that specifies the
    // shadow, icon dimensions, etc.
    var mapIcon = new GIcon();
    mapIcon.image = iconName; 
    //mapIcon.shadow = iconName; 
    mapIcon.iconSize = new GSize(35, 35);
    mapIcon.shadowSize = new GSize(35, 35);
    mapIcon.iconAnchor = new GPoint(6, 20);
    mapIcon.infoWindowAnchor = new GPoint(5, 1);

    return mapIcon;
}

//Create Image for SearchMap Symbols
function GetSearchIcon(iconName) {
    // Create a base icon for all of our markers that specifies the
    // shadow, icon dimensions, etc.
    var mapIcon = new GIcon(iconName);
    mapIcon.shadow = iconName;
    mapIcon.iconSize = new GSize(20, 20);
    mapIcon.shadowSize = new GSize(20, 20);
    mapIcon.iconAnchor = new GPoint(6, 20);
    mapIcon.infoWindowAnchor = new GPoint(5, 1);

    return mapIcon;
}


// Infowin class for displaying a miniature info window. Does not
// respond to any events - so you should show and remove the
// overlay yourself as necessary.
function Infowin(latlng, html) {
    this.latlng_ = latlng;
    this.html_ = html;
    this.prototype = new GOverlay();

    // Creates the DIV representing the infowindow
    this.initialize = function(map) {
        var div = $('<div />');
        div.css({
            position: 'absolute',
            width: 234
        }).appendTo(map.getPane(G_MAP_FLOAT_PANE))

        this.map_ = map;
        this.div_ = div;

        this.update(html);
    }

    this.update = function(html) {
        this.html_ = html;

        this.div_.empty();

        $('<div />').css({
            'background-image': 'url(/images/infow-top.png)',
            height: 14,
            padding: '0 0 0 0'
        }).appendTo(this.div_);

        var content = $('<div />').addClass('infowin-content').css({
            'position': 'relative',
            'overflow': 'hidden',
            'max-height': 100,
            'top': -5
        }).html(html);

        $('<div />').css({
            'background-image': 'url(/images/infow-bottom.png)',
            'background-position': 'bottom left',
            'padding': '0 10px 30px 10px'
        }).append(content).appendTo(this.div_);

        this.redraw(true);
    }

    // Remove the main DIV from the map pane
    this.remove = function() {
        this.div_.remove();
    }

    // Copy our data to a new instance
    this.copy = function() {
        return new Infowin(this.latlng_, this.html_);
    }

    // Redraw based on the current projection and zoom level
    this.redraw = function(force) {
        if (!force) return;

        var point = this.map_.fromLatLngToDivPixel(this.latlng_);

        // Now position our DIV based on the DIV coordinates of our bounds
        this.div_.css({
            left: point.x - 108,
            top: point.y - this.div_.height() - 22
        });
    }
}
