(function ($) {
Drupal.behaviors.hegreModelSelects = {
  attach: function (context, settings) {
    var url = location.href;
    var pieces = url.split('hegregirls.com');
    var pattern = new RegExp('([\?|\#].+$)');
    url = pieces['1'];
    url = url.replace(pattern,'').replace('#', '').replace('?', '');
    $("#block-hegre-hegre-model-selects").fadeIn("fast");
    $("#block-hegre-hegre-model-selects select:not('.hegre-processed')").each( function() {
      $(this).find('option[value='+url+']').attr('selected', 'selected');
      $(this).change( function() {
        var goto = $(this).val();
        if (goto != 0) {
          location.href = goto;
        }
      });
    }).addClass('hegre-processed');
  },
  detach: function (context, settings) {
  
  }
};

})(jQuery);;

