function embedSWF(w, h, feedURL) {
    $('#captionText').hide();
    
    var encodedFeed = encodeURIComponent(feedURL || GLOBAL_FEED_URL);
    
    var flashvars = {
      feed: encodedFeed
    };
    var params = {
      wmode: "opaque", // muy importante!
      allowFullScreen: "true",
      allowScriptAccess: "always"
    };
    swfobject.embedSWF(GLOBAL_SWF_URL, "theSWFContainer", w, h, "0", null, flashvars, params);
    $('#captionText').show(); // redisplay caption
}

function embedRadioSWF(artistName) {
    if (!artistName || artistName == "") {
        $('#radiotitle').hide();
        return;
    }
    
    // replace all spaces with +'s and encode the URI
    var convertedArtistName = encodeURIComponent(artistName.replace(/ /g,"+"));

    $('#radioContainer').html('<div id="lfmEmbed_195936464"></div>');
    $('#radiotitle').style.display = '';
    $('#radiotitle').attr('href', 'http://www.last.fm/listen/artist/' + convertedArtistName);
    $('#radiotitle').html('<b>' + artistName + '</b> radio by last.fm');

    var flashvars = {
        lfmMode: 'radio',
        radioURL: 'artist%2F' + convertedArtistName + '%2Fsimilarartists',
        theme: 'black',
        autostart: 1,
        lang: 'en',
        widget_id: 'radio_ae24eff764d0c8f50a69f14017e68f37'
    };
    var params = {
      allowNetworking: "all",
      allowScriptAccess: "always",
      bgcolor: "000000",
      wmode: "transparent",
      menu: "true",
      movie: "http://cdn.last.fm/widgets/radio/22.swf"
    };
    swfobject.embedSWF("http://cdn.last.fm/widgets/radio/22.swf", "lfmEmbed_195936464", 110, 140, "0", null, flashvars, params);
}

function startOver() {
    window.location.href = window.location.href.split("?")[0] + "?mode=design";
}

function makeMyGallery() {
    var currURL = window.location.href;
    if (currURL.indexOf("?") != -1) {
        window.location.href=currURL + '&mode=design';
    } else {
        window.location.href=currURL + '?mode=design';
    }
}

// initialize the interactivity
$(document).ready(function() {
    embedSWF(GLOBAL_SWF_WIDTH, GLOBAL_SWF_HEIGHT);
    embedRadioSWF(GLOBAL_ARTIST_NAME);
});    
