Put scripts in js file and append to div tag with click function

Put scripts in js file and append to div tag with click function

    I have php page pulling data from a mysql db and looping output until a condition isn't met.  What I would like to do is append html to a single div instead of 3 div's.  I was wondering if I can put the script stuff into a separate js file as well.  Below is a link and the code, I'm going to post what I want to end up with further down.

    Example (I know it only displays for the first div)

    1. echo "<img src='http://www.thecatalystchurch.com/images/play_icon.png' width='11' height='9'>&nbsp;<a href='#' id='audio'>Listen Online</a>&nbsp;|&nbsp;\n";
    2.     

    3. if (trim($row_getmessages[VideoURL])=='') {
    4. echo "";
    5. } else {
    6. echo "<img src='http://www.thecatalystchurch.com/images/video_icon.png' width='16' height='16'>&nbsp;<a href='#' id='video'>Watch Online</a>&nbsp;|&nbsp;\n";
    7. }
    8. $year = $row_getmessages[Year];
    9. $file = $row_getmessages[Filename];
    10. $lofs= round(filesize('../messages/' . $year . '/lo/' . $file)/1024/1024,2);
    11. $hifs= round(filesize('../messages/' . $year . '/hi/' . $file)/1024/1024,2);
    12.    
    13.     echo "<img src='http://www.thecatalystchurch.com/images/download_icon.png' width='9' height='11'>&nbsp;<a href='#' id='download'>Download</a><br>\n\n";

    14.   echo "<div id='audiospace' style='margin:3px;width:314px;height:25px;display:none;'>This text will be replaced</div>\n";
    15. echo "<div id='videospace' style='margin:3px;width:314px;height:260px;display:none;'>This text will be replaced</div>\n";
    16. echo "<div id='downloadspace' style='margin:3px;width:314px;height:25px;display:none;'><span style='font-style:italic;font-size:14px'><a href='/messages/$row_getmessages[Year]/lo/$row_getmessages[Filename]'>Low Quality - $lofs MB</a>&nbsp;|&nbsp;<a href='/messages/$row_getmessages[Year]/hi/$row_getmessages[Filename]'>High Quality - $hifs MB</a></span></div>\n";
    17.     
    18. echo "<br>testing<br>";


    19. echo "<script type='text/javascript' src='http://www.thecatalystchurch.com/mediaplayer/swfobject.js'></script>

    20. <script type='text/javascript'>
    21. var so = new SWFObject('$HomeDir/mediaplayer/player.swf','ply','314','25','9','#000000');
    22. so.addParam('allowfullscreen','true');
    23. so.addParam('allowscriptaccess','always');
    24. so.addParam('wmode','opaque');
    25. so.addVariable('file','$URL/$row_getmessages[Year]/lo/$row_getmessages[Filename]');
    26. so.addVariable('skin','http://developer.longtailvideo.com/svn/skins/stormtrooper/stormtrooper.zip');
    27. so.write('audiospace');
    28. </script>

    29. <script type='text/javascript'>
    30. var so = new SWFObject('http://www.thecatalystchurch.com/mediaplayer/player-viral.swf','ply','314','260','9','#000000');
    31. so.addParam('allowfullscreen','true');
    32. so.addParam('allowscriptaccess','always');
    33. so.addParam('wmode','opaque');
    34. so.addVariable('file','$row_getmessages[VideoURL]');
    35. so.addVariable('skin','http://developer.longtailvideo.com/svn/skins/stormtrooper/stormtrooper.zip');
    36. so.write('videospace');
    37. </script>
    38.   
    39. <script type='text/javascript'>
    40. var so = $(<a href='http://www.thecatalystchurch.com/messages/2010/hi/08-22-10.mp3'>HighVersion</a>);
    41. so.write('downloadspace');
    42.             </script>

    43. <script>";
    44. echo "$(function() {
    45.       $('#audio,#video,#download').click(function() {
    46.             var id = '#' + this.id + 'space';
    47.             $('#audiospace,#videospace,#downloadspace').not(id).slideUp('slow');
    48.             $(id).slideToggle('slow');
    49.       });
    50. });
    51. </script>";




    What I am trying to get too...

    1. echo "Title";
    2. echo "Date";
    3. echo "Speaker";

    4. echo "<div id='Links' style='margin:3px;width:314px;height:25px;display:none;'>Listen Online | Watch Online | Download</div>\n";

    I think I will need to add the record id to the "Links" id to make them unique.

    Now for the for the js file...

    1. <script type='text/javascript' src='http://www.thecatalystchurch.com/mediaplayer/swfobject.js'></script>

    2. <script type='text/javascript'>
    3. var so = new SWFObject('$HomeDir/mediaplayer/player.swf','ply','314','25','9','#000000');
    4. so.addParam('allowfullscreen','true');
    5. so.addParam('allowscriptaccess','always');
    6. so.addParam('wmode','opaque');
    7. so.addVariable('file','me$URL/$row_getmessages[Year]/lo/$row_getmessages[Filename]'); so.addVariable('skin','http://developer.longtailvideo.com/svn/skins/stormtrooper/stormtrooper.zip');
    8. so.write('audiospace');
    9. </script>

    10. <script type='text/javascript'>
    11. var so = new SWFObject('http://www.thecatalystchurch.com/mediaplayer/player-viral.swf','ply','314','260','9','#000000');
    12. so.addParam('allowfullscreen','true');
    13. so.addParam('allowscriptaccess','always');
    14. so.addParam('wmode','opaque');
    15. so.addVariable('file','$row_getmessages[VideoURL]');
    16. so.addVariable('skin','http://developer.longtailvideo.com/svn/skins/stormtrooper/stormtrooper.zip');
    17. so.write('videospace');
    18. </script>
    19.  
    20. <script type='text/javascript'>
    21. var so = $(<a href='http://www.thecatalystchurch.com/messages/2010/hi/08-22-10.mp3'>HighVersion</a>);
    22. so.write('downloadspace');
    23. </script>

    24. <script>
    25. $(function() {
    26. $('#audio,#video,#download').click(function() {
    27. var id = '#' + this.id + 'space';
    28. $('#audiospace,#videospace,#downloadspace').not(id).slideUp('slow');
    29.             Depending on whats clicked - Append that Script to Links Div then slide down
    30. $(id).slideToggle('slow');
    31. });
    32. });
    33. </script>
    How can I write it so that I can assign the three "Spaces" to a variable and append it to the div id on the php page?
    There are dynamic links the scripts, but I can pass those from the php page to the js file by defining an
    array in the php page correct?

    var data = {div id:new Array(data1,data2,data3...)}

    So, in wrapping up (because I posted a book), all I'm trying to do is append whichever "Space" is clicked to the 
    Links div on the php page.

    Is this possible? If it doesn't make any sense let me know.

    Any help is greatly appeciated!!