﻿/// <reference path="../jQuery/jquery-1.3.2-vsdoc2.js" />
/// <reference path="../PremiumBeatMP3Player/swfobject.js />

//$(document).ready(function() {
jQuery(document).ready(function($) {

    // Applying rounded corner effects
    Nifty("div.music-button", "transparent fixed-height");
    Nifty("div.editbox", "transparent fixed-height");

    // Loading up quotes to display on the right side of the main page
    $("#quotes").quotator({
        speed: 5000,
        json: "Scripts/jQuery/quotator/quotator_quotes.js"
    });

    // Calling to a web method to delete older playlist files
    openurmic.OpenUrMicService.ExpireOldPlaylists(1, null, OnError, null);

    // Setting and loading the default playlist to the "Top 5 Most Popular songs"
    //openurmic.OpenUrMicService.GenerateMostPopularPlaylist(5, OnGeneratePlaylistComplete, OnError, OnTimeOut);

    JSGenerateCannedPlayList("MostPopular");

    // Setting up the Artists drop-down list based on the selection made in the Venues drop-down using jQuery.
    var venueDropDown = $('select[id$=VenueDropDown]');
    venueDropDown.change(getArtists);
    getArtists();

    // Binding an event handler to the search box to catch hits to the "enter" key and thus activate the "play" button
    $("#SongSearchTB").keydown(function(e) {
        if (e.keyCode == 13) {
            JSGeneratePlaylist();
            return false;
        }
    });

//    $("#SongSearchTB").keyup(function(e) {
//        if (e.keyCode == 13) {
//            JSGeneratePlaylist();
//            return false;
//        }
//    });

});

//// This repopulates the artists drop-down based on changes to the venues dropdown
function getArtists() {
    $.ajax({
        type: "POST",
        url: "OpenUrMicService.asmx/GetArtistsByVenue",
        data: "{venueID: '" + $('select[id$=VenueDropDown]').val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            var artists = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
            $('select[id$=ArtistDropDown]').attr('disabled', false).removeOption(/./).addOption('', 'All Artists');

            for (var i = 0; i < artists.length; i++) {
                var val = artists[i].ID;
                var text = artists[i].ArtistName;
                //$('select[id$=ArtistDropDown]').addOption(val, text, false);
                $('select[id$=ArtistDropDown]').append($('<option title="' + text + '"></option>').val(val).html(text));
            }
        },
        error: function(xhr, status, error) {
            // Boil the ASP.NET AJAX error down to JSON.
            var err = eval("(" + xhr.responseText + ")");

            // Display the specific error raised by the server 
            alert(err.Message);
        }
    });
}

// This function is called when the user presses the "submit" button and loads the XSPF flash player with a newly created playlist
function JSGeneratePlaylist() {
    var selVenue = $('select[id$=VenueDropDown]').val();
    var selArtist = $('select[id$=ArtistDropDown]').val();
    //var selGenre = $('#<%= GenreDropDown.ClientID %>').val();
    var tags = $('#SongSearchTB').val();
    //openurmic.OpenUrMicService.GetPlayListString(selVenue, selArtist, selGenre, tags, OnGeneratePlaylistComplete, OnError, OnTimeOut);
    openurmic.OpenUrMicService.GetPlayListString(selVenue, selArtist, "0", tags, OnGeneratePlaylistComplete, OnError, "Custom", OnTimeOut);
}

function JSGenerateCannedPlayList(playListType) {
    //openurmic.OpenUrMicService.GenerateCannedPlaylist(playListType, 5, OnGeneratePlaylistComplete, OnError, OnTimeOut, playListType);
    openurmic.OpenUrMicService.GenerateCannedPlaylist(playListType, 10, OnGeneratePlaylistComplete, OnError, playListType, OnTimeOut);
}

// This function is called when the GeneratePlaylist call is successful and its argument contains the return value of that function
function OnGeneratePlaylistComplete(initStrings, playListType, callerMethod) {

    var flashContent;

    // YourMinis Plugin
    //flashContent = '<embed id="XSPFPlayer3" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/daflood/mini:clone02" wmode="transparent" width="227" height="210" FlashVars="' + initStrings.YourminisInitString + '" type="application/x-shockwave-flash" allowScriptAccess="always" />';
    flashContent = '<embed id="XSPFPlayer3" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/daflood/mini:clone02" wmode="transparent" width="390" height="230" FlashVars="' + initStrings.YourminisInitString + '" type="application/x-shockwave-flash" allowScriptAccess="always" />';
    $("#FlashContent").html(flashContent);

    // Premium Beat plugin
    // var so = new SWFObject("http://" + location.host + "/Scripts/PremiumBeatMP3Player/playerMultipleList.swf", "Victor", "222", "210", "7", "#1D0500");
    // so.addVariable("autoPlay", "yes");
    // so.addVariable("overColor", "#1D0500");
    // so.addVariable("playerSkin", "1");
    // so.addVariable("playlistPath", initStrings.PremiumBeatInitString);
    // so.write("FlashContent");

    // JW Player plugin
    //    var so = new SWFObject('http://' + location.host + '/Scripts/jwmediaplayer/player.swf', 'xspf', '390', '230', '9');    
    //    so.addParam('allowfullscreen', 'true');
    //    so.addParam('allowscriptaccess', 'always');
    //    so.addParam('wmode', 'opaque');
    //    so.addVariable('file', initStrings.FLVPlayerInitString);
    //    so.addVariable('frontcolor', '000000');
    //    so.addVariable('lightcolor', '873B10');
    //    so.addVariable('screencolor', '0000EE');
    //    so.addVariable('backcolor', '200600');   
    //    so.addVariable('playlist', 'top');
    //    so.addVariable('autostart', 'true');
    //    so.addVariable('icons', 'false');
    //    so.addVariable("skin", 'http://' + location.host + '/Scripts/jwmediaplayer/skins/stylish_slim.swf');
    //    so.write("FlashContent");

    if (playListType == "MostPopular") $('#PlayerLabelDV').html("Best of...");
    else if (playListType == "MostRecent") $('#PlayerLabelDV').html("Newly Released");
    else $('#PlayerLabelDV').html("Your Selection");
}

/*
function OnGeneratePlaylistComplete(initStrings) {
var flashContent;
flashContent = '<embed id="XSPFPlayer3" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/daflood/mini:clone02" wmode="transparent" width="430" height="360" FlashVars="' + initStrings.YourminisInitString + '" type="application/x-shockwave-flash" allowScriptAccess="always" />';
//        flashContent += '<object id="XSPFPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" type="application/x-shockwave-flash" width="400" height="170" data="' + initStrings.XSPFPlayerInitString + '" enableviewstate="False">';
//        flashContent += '<param name="movie" value="' + initStrings.XSPFPlayerInitString + '" />';
//        flashContent += '<embed src= "' + initStrings.XSPFPlayerInitString + '" quality="high" bgcolor="#E6E6E6" name="xspf_player" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" align="center" height="168" width="400">';
//        flashContent += '</embed></object>';
//document.getElementById("FlashContent").innerHTML = flashContent;
$("#FlashContent").html(flashContent);
}
*/

function OnTimeOut(arg) {
    alert("timeOut has occured");
}

function OnError(arg) {
    alert("error has occured: " + arg._message);
}

