(function($) { var status = 1 ; $.fn.customSelect = function() { $('.language_link_option').click(function() { $this = $(this); document.getElementById('language_selector_hidden').value = this.rel; show_list(); $('."language_selected_main"').empty().append($this.html()); controllo_option(this.rel); }); function show_list(){ if(status==1){ $('.language_optionlist_container').slideDown(); status=2 }else{ $('.language_optionlist_container').slideUp(); status=1; } } function controllo_option(selected){ $('.language_link_option').each(function(index){ $this = $(this); if(this.rel==selected){ this.className = 'language_link_option language_link_option_selected'; }else{ this.className = 'language_link_option'; } }); } // Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once return this.click(show_list); }; })(jQuery); // Call and execute the function immediately passing the jQuery object