JS Snippet in Cache leads to firebug errors

hi,

i load a random video task on startup with the youtube api:




    var params = { allowScriptAccess: "always" };

    var atts = { id: "myplayerID" };

    var videourl = "<?= $url ?>";

    var query = "?enablejsapi=1&showinfo=0&playerapiid=myplayerID&version=3";

                                                                                                                   

    swfobject.embedSWF(videourl+query, "video", "250", "204", "9.0.0", null, null, params, atts);

                        

    var duration = 10;  

    var start = 60; 

    var end = duration + start;

    function onYouTubePlayerReady(id){

        player = document.getElementById("myplayerID");

        player.seekTo(start, true);

        player.playVideo();

        setInterval(checkEnd, 1000);

    }

                    			

    function checkEnd(){

        if(player.getCurrentTime() >= end) {

            player.pauseVideo();

            player.seekTo(start, true);

        }

    }



i now click on a button and the same site appears via renderPartial but without a video. this changes from time to time. one time video, the other time only a picture at the same place.

my problem is, if now a video appears the javascript snippet above is still in cache i think, but i dont need it if a picture appears. firebug fires a loop of errors at the player.getCurrentTime() position (makes sense, cause no video is available at this moment a picture is at this place).

the above script i load at the place i need it with:




 $this->renderPartial('/site/videoembed', array('url' => $url, 'task' => $task), false, true);



thx alot