function COMBOSKIN(parent, config){
    this.parent = jQuery(parent)
    this.VParent = null;
    this.VList   = null;
    this.VlistText = null;
    this.parentOffset = null;
    
    !config ? config = {} : '';
    
    this.config = {
        minWidth: config.minWidth==null ? '116px' : config.minWidth
    };
}

COMBOSKIN.prototype.init = function() {
  var virtualList = "";
  var vLIndex = 0;

  if (jQuery(this.parent).length == 0 || jQuery(this.parent)[0].style.display == 'none') return;

  jQuery(this.parent).hide();

  jQuery(this.parent).find('> option').each(function() {
    virtualList += '<li value="' + jQuery(this).get().value + '"><input type="hidden" value="' + vLIndex + '">' + jQuery(this).text() + '</li>';
    vLIndex++;
  })

  jQuery(this.parent).before('<div class="specCombo" id="specCombo' + jQuery(this.parent).attr('id') + '" ><input class="specComboFocus"/><div class="specComboCurrent"><div class="specComboCurrentText"></div></div><a class="specComboCurrentButton"><img src="kepek/btn_combo.gif" alt="" border="0" /></a><ul>' + virtualList + '</ul></div>')



  this.VParent = jQuery('#specCombo' + jQuery(this.parent).attr('id'));
  this.VlistText = this.VParent.find('.specComboCurrentText');

  this.VParent.css({ width: this.config.minWidth });

  //alapertelmezett szoveg beallitasa
  if (this.parent.length != 0) {
    var p = this.parent[0];
    this.VlistText.text(p.options[p.selectedIndex].innerHTML);
  } else {
    this.VlistText.text(jQuery(this.VParent.find('li').get(0)).text());
  }

  //virtualis combo
  this.VList = this.VParent.find('ul');
  this.VList.css({ width: parseInt(this.config.minWidth) + 10 + 'px' });

  jQuery('.specCombo .specComboFocus').blur(function() {
    //oThis.VList.hide();
  })

  //aktualis pozicioja a virtualis elemnek


  var oThis = this;

  this.VParent.find('a.specComboCurrentButton, div.specComboCurrentText').click(function() {
    oThis.parentOffset = jQuery(oThis.VParent).offset();

    oThis.VList.css({
      left: oThis.parentOffset.left + 1 + 'px',
      top: oThis.parentOffset.top + 28 + 'px'
    })

    oThis.VList.toggle();
    oThis.VParent.find('.specComboFocus').focus();
  })

  this.VList.find('li').click(function() {
    var select = jQuery(oThis.parent)[0];
    select.selectedIndex = this.firstChild.value;
    oThis.VlistText.text(jQuery(this).text());
    var text = oThis.VlistText[0];
    if (text.className.indexOf('specComboCurrentTextHighlighted') == -1) text.className += ' specComboCurrentTextHighlighted';
    oThis.VList.hide();
    if (select.fireEvent) {
      select.fireEvent('onchange');
    } else if (document.createEvent) {
      var evt = document.createEvent('HTMLEvents');
      evt.initEvent('change', true, true);
      evt.srcElement = select;
      select.dispatchEvent(evt);
    }
  })
}

function prettySelect() {
  //jQuery(function() {
  var a = new COMBOSKIN(jQuery('#searchZipTypes'), { minWidth: 118 });
  a.init();
  
  var a = new COMBOSKIN(jQuery('#searchTypes'), { minWidth: 238 });
  a.init();

  var b = new COMBOSKIN(jQuery('#ess_select_kiadasi_ev-'), { minWidth: 170 });
  b.init();

  var c = new COMBOSKIN(jQuery('#ess_select_jelleg-'), { minWidth: 170 });
  c.init();

  var c = new COMBOSKIN(jQuery('#ess_select_tema-'), { minWidth: 170 });
  c.init();

  // var c = new COMBOSKIN(jQuery('#kuldemeny_szelesseg'), { minWidth: 238 });
  // c.init();

  // var c = new COMBOSKIN(jQuery('#kuldemeny_hosszusag'), { minWidth: 238 });
  // c.init();

  // var c = new COMBOSKIN(jQuery('#futar_erkezes_nap'), { minWidth: 238 });
  // c.init();

  //  var c = new COMBOSKIN(jQuery('#futar_erkezes_ido_tol'), { minWidth: 238 });
  // c.init();

  // var c = new COMBOSKIN(jQuery('#futar_erkezes_ido_ig'), { minWidth: 238 });
  // c.init();

 // var c = new COMBOSKIN(jQuery('#check_shippingoption'), { minWidth: 238 });
 // c.init();

  var c = new COMBOSKIN(jQuery('#ess_range_price-'), { minWidth: 135 });
  c.init();
  
  var c = new COMBOSKIN(jQuery('#ess_range_price-2'), { minWidth: 135 });
  c.init();

  var c = new COMBOSKIN(jQuery('#topic'), { minWidth: 135 });
  c.init();

  var c = new COMBOSKIN(jQuery('#kerulet'), { minWidth: 50 });
  c.init();
  var c = new COMBOSKIN(jQuery('#searchStreetType'), { minWidth: 100 });
  c.init();
  var c = new COMBOSKIN(jQuery('#search-type'), { minWidth: 100 });
  c.init();
  var c = new COMBOSKIN(jQuery('#meta-subtype'), { minWidth: 100 });
  c.init();
  var c = new COMBOSKIN(jQuery('#meta-subtype'), { minWidth: 100 });
  c.init();
  var c = new COMBOSKIN(jQuery('#kimutatas'), { minWidth: 550 });
  c.init();
  var c = new COMBOSKIN(jQuery('#munkakor'), { minWidth: 550 });
  c.init();
  //})
}
