window.log = function(){
  log.history = log.history || [];  
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

// create dropdown select field for inputfield
(function($){
  jQuery.fn.wmDropdown = function(options){
    // set default options
    options = $.extend({
      selector: "wm-dropdown",
      type : 'numeric',  // numeric or array
      min : 1,
      max : 10,
      data: [{'value':'test1','label':'testlabel1'},{'value':'test2','label':'testlabel2'}]
    }, options);
    
    var element = $(this);
    element.attr('readonly','readonly');
    
    function showWmDropdown() {
      
      var ul = $('<ul></ul>');
      ul.addClass(options.selector+'-list');
      ul.addClass('ui-corner-bottom')
      ul.css('display','none');
      ul.css('position','absolute');
      ul.css('top',(element.offset().top+element.outerHeight()));
      ul.css('width',element.width());
      ul.css('left',element.offset().left+((element.outerWidth()-element.width())/2));
      ul.css('z-index',65000);
      
      if(options.type == 'numeric' ) {
        for (var i=options.min; i <= options.max; i++) {
          var li = $('<li></li>');
          li.addClass(options.selector+'-item');
          li.html(i);
          li.bind('click',function(){
            element.val($(this).html());
            ul.fadeOut(500);
          });
          ul.append(li);
        }
      } else {
        
      }
      
      element.after(ul);
      element.bind('click',function() {
        ul.toggle('500');
      });
      
    }
    
    showWmDropdown(options, element);
  
  }
})(jQuery);
