/**
* --------------------------------------------------------------------
 * jQuery-Plugin "combobox"
 * Version: 1.0, 08.05.2009
 * by Matthias Wilhelm / mindconnect
 * http://www.mindconnect.com/
 *
 * Copyright (c) 2009 Mindconnect
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */

(function($) {

	$.fn.combobox = function(options) {

	
		// build main options before element iteration
		var opts = $.extend({}, $.fn.combobox.defaults, options);
		var newIndex=0;
		// iterate and reformat each matched element

    return this.each(function() {

      	var $this = $(this);
	      // build element specific options
	    var combodropimage='<span class="downimage" title="Select an option" /></span>';
		
		var selectbox=$this;
		var selectid=newIndex++;
	
		var html="";
		var title=(this.options.length>0) ? this.options[this.selectedIndex].text : 0;
		
		html+='<div id="dhtml_'+selectid+'" class="dhtmlselect">'+title+" "+combodropimage+'<div class="dropdown" style="width:100%;">';
		for (var i=0; i<this.options.length; i++)
		{
			html+='<a href="'+this.options[i].value+'">'+this.options[i].text+'</a>';
		}
		html+='</div></div>';
	
	
		this.style.display="none";
		$this.after(html);
		
		var $dhtml=$("#dhtml_"+selectid);
		$dhtml.css("zIndex",opts.combozindex--);
		$dhtml.width($this.width());
		
		$dhtml.mouseover(function(){
		  	 this.getElementsByTagName("div")[0].style.display="block";
		}).mouseout(function(){
			 this.getElementsByTagName("div")[0].style.display="none";
		});

    });

  };

  //
  // private function for debugging
  //

  function debug($obj) {

    if (window.console && window.console.log)
      window.console.log('hilight selection count: ' + $obj.size());
  };


  //
  // plugin defaults
  //

  $.fn.combobox.defaults = {
	combodropimage:'../img/ico/icon_pfeil_unten.png',
    combozindex:50
  };

//
// end of closure
//

})(jQuery);



