Function that is not triggered when page loads

Function that is not triggered when page loads

Dear all,

I have a web page that loads a video. I have a function that depending on the video's title appends a div with a button and a link.
Let's say my function is called checkVideo() and looks like:

checkVideo = function(){

        theTitle = Application.getInstance()........;
        if (theTitle == "My title"){
        var myButton = "<div id='myDiv'><a href="http://www.mypage.com"><img  src='image.png'></a></div>";   
        $("#divMain").append(myButton);
        }

  }



The function is working great. I know that because when using Firebug and entering checkVideo() in the Script tab it does the job and shows the div with the button and link.

What's the problem then? The problem is that the function does not get triggered at all, and nothing shows in the page after it is loaded. If I want to see the button and link in the page I have to use Firebug.

Doing:
        $(document).ready(function() {
          checkVideo();
        });


seems like a great idea, but it does not work either. I guess this happens because the video loads before the rest of the page and $(document).ready(function does not jump into the scene until everything is ready ..
What can I do then??? I need my function working!

Thanks a lot in advance!!