// JavaScript Document
jQuery.fn.dropDown = function(){
  var element = this;
  this.lastval = jQuery(element).children('.label').children('.value').html();

  this.init = function(){
    jQuery(this).mouseover(function(){
      jQuery(this).addClass('opened');
      jQuery(this).children('.dropDownUl').show();
      jQuery(this).children('.dropDownBottom').show();
    }).mouseout(function(){
      jQuery(this).removeClass('opened');
      jQuery(this).children('.dropDownUl').hide();
      jQuery(this).children('.dropDownBottom').hide();
      var elements = jQuery(this).children('.dropDownUl').children('li').children('input');
      for (var i = 0; i < elements.length; i++)
      {
        var elem = elements[i];
        if (jQuery(elem).attr('checked'))
        {
          element.lastval = jQuery(elem).siblings('label').html();
        }
      }
      jQuery(this).children('.label').children('.value').html(element.lastval); 
    })
    jQuery(this).children('.dropDownUl').children('li').mouseover(function(){
        var val = $(this).children('label').html();
        jQuery(this).parent().siblings('.label').children('.value').html(val);
      }).click(function(){
         var val = $(this).children('input').attr('checked','checked');
         $(this).children('input').change();
         jQuery(element).mouseout();  
      });
  };
  
  if (element.length > 0 && !element.hasClass('disabled'))
    this.init();
};
