var svgBullet = Class.create();

svgBullet.prototype = {

    


    initialize: function(dst) {

        this.target = $(dst);
        this.svgns = "http://www.w3.org/2000/svg";
        this.svgDocument = dst //this.target.getSVGDocument();

        this.xlinkNS = "http://www.w3.org/1999/xlink";
        
	var options = Object.extend({
            x: 0,
            y: 0,
            id: '',
            name: '',
            checkboxUseId: 'bullet',
            checkboxOverUseId: 'bullet_over',
            group: 'bullets'
	},arguments[1] || {});
        
        this.options = options;
        this.options.label = this.options.name;
        
        this.setup();
    
    },
    
    setup: function() {
        
        
       
        /*
	var checkBox = this.svgDocument.createElementNS(this.svgns,"use");
	checkBox.setAttributeNS(null,"x",this.options.x);
	checkBox.setAttributeNS(null,"y",this.options.y);
	checkBox.setAttributeNS(this.xlinkNS,"href","#"+this.options.checkboxUseId);  
	*/
	
	var checkBox = this.svgDocument.createElementNS(this.svgns,"circle");
	checkBox.setAttributeNS(null,"cx",this.options.x);
	checkBox.setAttributeNS(null,"cy",this.options.y);
	checkBox.setAttributeNS(null,"r",2);
	checkBox.setAttributeNS(null,"stroke","black");
	checkBox.setAttributeNS(null,"fill","black");
	checkBox.setAttributeNS(null,"stroke-width","2");
	checkBox.setAttributeNS(null,"overflow","visible");
	checkBox.setAttributeNS(null,"transition","translate(0 0)");
	
	
	checkBox.addEventListener("mouseover",this.myEvents.bind (this),false);
	checkBox.addEventListener("mouseout",this.myEvents.bind (this),false);
	this.checkBox = checkBox;
	
	if (this.options.group != null && this.svgDocument.getElementById(this.options.group)) {
	    this.svgDocument.getElementById(this.options.group).appendChild(this.checkBox);
	} else {
	    this.svgDocument.documentElement.appendChild(this.checkBox);
	}
    },
    
    myEvents: function(ev) {
        switch(ev.type) {
            case "mouseover":
            		if (this.isHidden) {
            			return;
            		}
                //alert(this.options.id);
                this.hilight('red');
                if (this.svgDocument.getElementById('city_label').firstChild) {
                    this.svgDocument.getElementById('city_label').setAttributeNS(null,'x',parseInt(this.options.x));
                    this.svgDocument.getElementById('city_label').setAttributeNS(null,'y',(parseInt(this.options.y) - 15));
                    this.svgDocument.getElementById('city_label').firstChild.nodeValue = this.options.label;
                    
                } 
                //alert(this.checkBox.getAttribute('x') + " " + ev.clientX);               
            break;
            case "mouseout":
            		if (this.isHidden) {
            			return;
            		}
                this.unhilight();
            break;
        }
    },
    
    hilight: function(c) {
        //this.checkBox.setAttributeNS(this.xlinkNS,"href","#"+this.options.checkboxOverUseId);   
        this.checkBox.setAttributeNS(null,"r","3");
        var color = c || "red";
        this.checkBox.setAttributeNS(null,"stroke", color);
        this.svgDocument.getElementById('city_label').setAttributeNS(null,'fill',color);
                if (this.svgDocument.getElementById('city_label').firstChild) {
                    this.svgDocument.getElementById('city_label').setAttributeNS(null,'x',parseInt(this.options.x));
                    this.svgDocument.getElementById('city_label').setAttributeNS(null,'y',(parseInt(this.options.y) - 15));
                    this.svgDocument.getElementById('city_label').firstChild.nodeValue = this.options.label;
                    
                }

    },
    colorize: function(color) {
			this.checkBox.setAttributeNS(null,"stroke",color);
    },
    unhilight: function() {
        this.checkBox.setAttributeNS(null,"r","2");
        var color = this.color || "black";
        this.checkBox.setAttributeNS(null,"stroke",color);
                if (this.svgDocument.getElementById('city_label').firstChild) {
                    this.svgDocument.getElementById('city_label').firstChild.nodeValue = '';
                }
    },
    
    setColor: function(color) {
        
      this.color = color;
      this.checkBox.setAttributeNS(null,"stroke",color);
      this.checkBox.setAttributeNS(null,"fill",color);
      
    },
    
    hide: function() {
    		this.isHidden = true;
				this.checkBox.setAttributeNS(null,"r","0");
				this.checkBox.setAttributeNS(null,"stroke-width","0");
    },
    
    show: function() {
    		this.isHidden = false;
				this.checkBox.setAttributeNS(null,"r","2");
				this.checkBox.setAttributeNS(null,"stroke-width","2");
    }

    
    


};