soundManager.allowPolling = true;   // enable flash status updates. Required for whileloading/whileplaying.
soundManager.consoleOnly = true;   // if console is being used, do not create/write to #soundmanager-debug
soundManager.debugMode = false;      // enable debugging output (div#soundmanager-debug, OR console..)
soundManager.flashLoadTimeout = 750;// ms to wait for flash movie to load before failing (0 = infinity)
soundManager.flashVersion = 8;      // version of flash to require, either 8 or 9. Some features require 9.
soundManager.nullURL = '';  // (Flash 8 only): URL of silent/blank MP3 for unloading/stopping request.
soundManager.url = '/vis/soundmanager/'; // path (directory) where SM2 .SWF files will be found.
soundManager.useConsole = true;     // use firebug/safari console.log()-type debug console if available
soundManager.useMovieStar = false;  // enable experimental support for Flash 9.0r115+ MPEG4 audio + video
soundManager.useHighPerformance = true;// position:fixed flash movie for faster JS/flash callbacks
soundManager.waitForWindowLoad = false; // always delay soundManager.onload() until after window.onload()

SMobj = null;

BEplayer = {
    debug : 0,
    multiPlay : true,
    multiItems : null,
    streamBase : '/Ajax/getStream/',
    stop: function(elm){

        mySMSound = soundManager.getSoundById($(elm).attr("smobj"));
    
        time = new Date().getTime();
        startTime = $(elm).attr("started");
    
            // Kick stop for the player object
            if (mySMSound) {
                mySMSound.stop();
            }
            // Set the status to 0
            $(elm).attr("status", "0");
            
            // If we're using the graphical type, set the image to play
            if ($("img", elm).length > 0) {
                $("img", $(elm)).attr("src", $("img", $(elm)).attr("src").replace(/_stop/, '_play'));
            }
            // If we're using the text, set that
            if ($(".play", elm).length > 0) {
                $(".stop", elm).fadeOut("normal", function(){
                    $(".play", $(elm).parent()).fadeIn();
                });
            }
    }, // end stop
    play: function(elm){
        // Set some bases
        sURL = BEplayer.streamBase + $(elm).attr("rel");//+"/true/true";
     //   $.ajaxSetup({async: false});
    //    streamURL = $.getJSON(sURL).responseText;
        
    //    if ( soundManager.canPlayURL( streamURL ) ) {
        
            time = new Date().getTime();
            idString = 'mySound_'+time;
    
            // Store the ID of the sound object in the element
            $(elm).attr("smobj", idString);

            // set the status to on
            $(elm).attr("status", "1");
                        
            //  Given that we can, initiate the object
            SMobj = soundManager.createSound({
                id: idString,
                url: sURL,
                volume: 100,
                autoPlay: true,
                onfinish: function() { BEplayer.stop($(elm)); }
            });

            // and the images, if we're using em
            if ($("img", elm).length > 0) {
                $("img", $(elm)).attr("src", $("img", $(elm)).attr("src").replace(/_play/, '_stop'));
            }
            
            // same for the text links, if we're using them
            if ($(".play", elm).length > 0) {
                $(".play", elm).fadeOut("normal", function(){
                    $(".stop", $(elm).parent()).fadeIn();
                });
            }
            
            // Make sure multiplay is allowed, if it's not, stop all other instances
            if (BEplayer.multiPlay != true) {
                cur = $(elm).attr("smobj");
                $(BEplayer.multiItems).each(function() {
                    if ($(this).attr("smobj") && $(this).attr("smobj") != cur) {
                        BEplayer.stop(this);
                    }
                });
            }
        
     //   } //else { console.log( 'cant do it' ); } // end canPlay

    } // end play
} // end BEplayer object