Thumbtack = function(map_element, options, data, bubble_element,tooltip_element) {
    if (arguments.length > 0) {
        this.initialize(map_element, options, data, bubble_element,tooltip_element);
    }
}

/*
    //Usage example
    
    var t = new Thumbtack(map_element, {
        x: 37,
        y: 170
    },{
        establishment_code: "AIG",
        network_code: "PQ"
    }, bubble_element);
    t.render();
    
*/

Thumbtack.prototype = {
    map_element: null,
    
    options: {
        x: null,
        y: null
    },
    
    y_modifier: 0,
    x_modifier: 0,
    image: null,
    
    data: {
        establishment_code: null,
        network_code: null,
	view_button_url: null,
	reserve_button_url: null
    },
    
    initialize: function(map_element, options, data, bubble_element,tooltip_element) {
        var self = this;
        this.map_element = map_element;
        this.options = options;
        this.data = data;
        
        var pins = jQuery(".pins");
        jQuery.each(pins, function() {
            var pin = jQuery(this);

            if (pin.attr("id").indexOf(self.data.network_code) > -1) {
                self.image = pin.clone();
                self.image.removeClass("pins");
                self.image.addClass(self.data.establishment_code.toUpperCase());
		jQuery(self.image).attr('rel','mapDot')
                return false;   //acts as a break for the each() function
            }
        });

        this.image.css({
            zIndex: "50",
            display: "none",
            position: "absolute",
            cursor: "pointer"
        });
        
        jQuery("body").append(this.image);
        var bubble = new Bubble(bubble_element,tooltip_element, this);

    },
    
    render: function() {
        var origin = this.map_element.offset();

        var imgWidth = this.image.width();
        var imgHeight = this.image.height();
        
        var top = origin.top + this.options.y + this.y_modifier - (imgHeight / 2);
        var left = origin.left + this.options.x + this.x_modifier - (imgWidth / 2);
        
        this.image.css({
            display: "block",
            top: top + "px",
            left: left + "px"
        });
    },
    
    hide: function() {
        this.image.css({
            display: "none",
            top: "0px",
            left: "0px"
        });
    },
    
    onClick: function() {}
};