How to use Drupal.behaviors in Drupal 7? I have these codes in my druapl 7 theme js file (js/test.js):

 (function($) {
    alert("Hi");
    Drupal.behaviors.mythemename = {
      attach: function(context, settings) { 
        alert("Bye");
      }
    }; 

 })(jQuery);


then I call this file using :

 drupal_add_js(drupal_get_path('theme', 'mythemename'). '/js/test.js');


in page--front.tpl.php file inside the theme folder.

But only the first alert is shown.
Why is it so? where is my problem ?
Probably to late to load the js file in the .tpl try in template.php with 

YOUR_THEME_preprocess_page(&amp;$variables) {
  if ($variables['is_front']) {
    drupal_add_js(drupal_get_path('theme', 'mythemename'). '/js/test.js');
  }
}