//
// 色選択のダイアログ
//
YAHOO.namespace("dqmap.colorpicker")

YAHOO.dqmap.colorpicker.inDialog = function() {

  var Event=YAHOO.util.Event,
      Dom=YAHOO.util.Dom,
      lang=YAHOO.lang;

  return {
  
    init: function() {
      
      this.dialog = new YAHOO.widget.Dialog("yui-picker-panel", { 
        width : "500px",
        close: true,
        fixedcenter : true,
        visible : false, 
        constraintoviewport : true,
        buttons : [],
        lazyload: true,
        effect: { 
          effect:YAHOO.widget.ContainerEffect.FADE,
          duration:0.5
        }
      });
      
      this.dialog.renderEvent.subscribe(function() {
        if (!this.picker) {
          var txt = YAHOO.lang.merge(
            YAHOO.widget.ColorPicker.prototype.TXT, {
              SHOW_CONTROLS: "詳細を表示",
              HIDE_CONTROLS: "詳細を隠す",
              R: "赤",
              G: "緑",
              B: "青"
            }
          );
          
          this.picker = new YAHOO.widget.ColorPicker("yui-picker", {
            container: this.dialog,
            showhexcontrols: true,
            showhsvcontrols: true,
            txt:txt,
            images: { 
                PICKER_THUMB: "http://yui.yahooapis.com/2.3.0/build/colorpicker/assets/picker_thumb.png", 
                HUE_THUMB: "http://yui.yahooapis.com/2.3.0/build/colorpicker/assets/hue_thumb.png" 
            } 
          });
          
          this.picker.on("rgbChange", function(o) {
            var hex = this.get("hex");
            Dom.get("bgcolor").value = hex;
            Dom.setStyle(Dom.get("bgcolor_btn"), "backgroundColor", '#'+hex);
            Dom.setStyle(Dom.get("preview_marker"), "backgroundColor", '#'+hex);
          });
        }
      });	
      
      this.dialog.validate = function() {
        return true;
      };
      this.dialog.render();
      
      //initialization complete:
    }
    
  }
}();

YAHOO.util.Event.onDOMReady(YAHOO.dqmap.colorpicker.inDialog.init, YAHOO.dqmap.colorpicker.inDialog, true);

