What about the following in your layout file:
$this->headScript()->appendFile('/js/jquery.js');
$this->headScript()->appendScript('$(document).ready(function() { alert("hello"); });','text/javascript');
What I mostly do is:
$this->headScript()->appendFile('/js/jquery.js');
$this->headScript()->appendFile('/js/application.js');
$this->headScript()->appendScript('application.init();', 'text/javascript');
echo $this->headScript();
Then the application.js:
var application = {
init : function() {
//do here anything you like
}
}
If you want to call a specific function from let's say your controller you add this function to your application JS first:
var application = {
init : function() {
//do here anything you like
},
bindChangeEventToSomething : function() {
$('a').click(function() {});
}
}
Then in your controller you could add in your action:
$this->view->headScript->appendScript(
'application.bindChangeEventToSomething()',
'text/javascript'
);