$(document).ready(function() {

    $('#pickups-level1').change(function() {
        $("#select-level3").html('');
        $("#pickup_playback").html('');

        var id = this.options[this.selectedIndex].value;
        var label = this.options[this.selectedIndex].text;

        $.ajax({
           type: "GET", url: "ajax.php?level=1&cmd=" +id,
           timeout: 5000,
           success: function(data){
             $("#select-level2").html(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
             $("#select-level2").html("Error: " + textStatus);
            }
          })
      });

    $('#select-level2').change(function() {
        $("#pickup_playback").html('');

        var id = this.options[this.selectedIndex].value;
        var label = this.options[this.selectedIndex].text;
        var cmd =$('#pickups-level1').val();

        $.ajax({
          type: "GET", url: "ajax.php?level=2&company=" +id + '&cmd=' + cmd,
              timeout: 5000,
              success: function(data){
                 $("#select-level3").html(data);
              },
              error: function (XMLHttpRequest, textStatus, errorThrown) {
                 $("#select-level3").html("Error: " + textStatus);
              }
          })
      });

    $('#select-level3').change(function() {
        var id = this.options[this.selectedIndex].value;
        var label = this.options[this.selectedIndex].text;

        $.ajax({
          type: "GET", url: "ajax.php?level=3&testid=" + id,
              timeout: 5000,
              success: function(data){
                 $("#pickup_playback").html(data);
                 var tag = document.getElementById('pickup_playback');
                 YAHOO.MediaPlayer.addTracks(tag, true);
              },
              error: function (XMLHttpRequest, textStatus, errorThrown) {
              $("#pickup_playback").html("Error: " + textStatus);
              }
          })
      });

    function PageLoadedEventHandler() {  
      if(YAHOO.mediaplay.playerAlreadyLoaded()){       
        YAHOO.music.WebPlayer.clear();       
        YAHOO.music.WebPlayer.scrape(); 
      }
    }
      
    $(".long_body").hide();
    //toggle the component with class long_body
    $(".long_head").click(function() {
        if($(this).next(".long_body").is(':hidden'))
          $(".long_head").html('<a href=#>Close</a>');
        else
          $(".long_head").html('<a href=#>Click For More Details</a>');
        $(this).next(".long_body").slideToggle(600);

     });


    jQuery('a[rel*=facebox]').facebox() 

});
