///////////////////////////////////////
//                                   //
//        Wimpy Button Maker         //
//             v 4.1.2               //
//           ©2009 Plaino            //
//           Available at            //
//       www.wimpyplayer.com         //
//                                   //
///////////////////////////////////////

// OPTIONS:
// When a button is clicked, the other buttons will stop playing. 
// This option sets the state that the other buttons will go into.

// The following (default) will put the other buttons into the "pause" state. 
// If the button is clicked again, the track will continue where it left off.
// var wimpyButtonRewindOrPause = "pause";

// The following will put the other buttons will stop and rewind. 
// If the button is clicked again, the track will start from the beginning.
var wimpyButtonRewindOrPause = "pause";


var wimpyUserAgent = navigator.appName.indexOf("Microsoft");
var wimpyButtonIDs = wimpyButtonIDs || Array();
function wimpyButtonStopOthers(myid_in) {
    for (i = 0; i < wimpyButtonIDs.length; i++) {
        if (wimpyButtonIDs[i][0] != myid_in) {
            if (wimpyUserAgent != -1) {
                if (wimpyButtonRewindOrPause == "pause") {
                    window[wimpyButtonIDs[i][0]].js_wimpy_pause();
                } else {
                    window[wimpyButtonIDs[i][0]].js_wimpy_stop();
                }
            } else {
                if (wimpyButtonRewindOrPause == "pause") {
                    document[wimpyButtonIDs[i][0]].js_wimpy_pause();
                } else {
                    document[wimpyButtonIDs[i][0]].js_wimpy_stop();
                }
            }
        }
    }
}
function wimpyButtonTrackStarted(fileName) {
    for (i = 0; i < wimpyButtonIDs.length; i++) {
        //alert(unescape(wimpyButtonIDs[i][1]) == unescape(fileName));
        if (unescape(wimpyButtonIDs[i][1]) == fileName) {
            wimpyButtonStopOthers(wimpyButtonIDs[i][0]);
            break;
        }
    }
}

function writeWimpyButton(theFile, wimpyWidth, wimpyHeight, wimpyConfigs, backgroundColor) {
    var wimpyReg = "MWNOdGlqSkxJJTdEOXYlMjYlN0YlN0YlN0J6MiU3RnFMJTI2OW10djglMjYlM0QlM0YlM0REJTdGQ0YlMjZTY0lE";
    var defaultWidth = 35;
    var defaultHeight = 35;
    var defaultConfigs = "";
    var baseURL = "";
    var wimpySwf = "wimpy_button.swf";
    var wimpyWidth = (wimpyWidth == null) ? defaultWidth : wimpyWidth;
    var wimpyHeight = (wimpyHeight == null) ? defaultHeight : wimpyHeight;
    var wimpyConfigs = (wimpyConfigs == null) ? defaultConfigs : wimpyConfigs;
    var backgroundColor = (backgroundColor == null) ? false : backgroundColor;
    var myid = "wimpybutton" + Math.round((Math.random() * 1000) + 1);
    var myInfo = Array(myid, baseURL + theFile);
    wimpyButtonIDs[wimpyButtonIDs.length] = myInfo;
    var flashCode = "";
    var newlineChar = "\n";
    var backgroundColor = (backgroundColor == null) ? false : backgroundColor;
    if (typeof (backgroundColor) == "string") {
        var Astring = backgroundColor.split("");
        if (Astring[0] == "#") {
            Astring.shift();
            backgroundColor = Astring.join("");
        }
    }
    if (backgroundColor == false) {
        tptParam = '<param name="wmode" value="transparent" />' + newlineChar;
        tptEmbed = ' wmode="transparent"';
    } else {
        tptParam = '<param name="bgcolor" value="#' + backgroundColor + '" />' + newlineChar;
        tptEmbed = ' bgcolor="#' + backgroundColor + '"';
    }
    flashCode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + wimpyWidth + '" height="' + wimpyHeight + '" id="' + myid + '">' + newlineChar;
    flashCode += '<param name="movie" value="' + wimpySwf + '" />' + newlineChar;
    flashCode += '<param name="loop" value="false" />' + newlineChar;
    flashCode += '<param name="menu" value="false" />' + newlineChar;
    flashCode += '<param name="quality" value="high" />' + newlineChar;
    flashCode += '<param name="wmode" value="transparent" />' + newlineChar;
    flashCode += '<param name="allowScriptAccess" value="always" />' + newlineChar;
    flashCode += '<param name="flashvars" value="theFile=' + baseURL + theFile + wimpyConfigs + '&wimpyReg=' + wimpyReg + '&myid=' + myid + '" />' + newlineChar;
    flashCode += '<embed src="' + wimpySwf + '" width="' + wimpyWidth + '" height="' + wimpyHeight + '" flashvars="theFile=' + baseURL + theFile + wimpyConfigs + '&wimpyReg=' + wimpyReg + '&myid=' + myid + '"' + tptEmbed + ' loop="false" menu="false" quality="high" name="' + myid + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>' + newlineChar;
//    document.write('<br>' + myid + '<br><textarea name="textarea" cols="40" rows="3">' + flashCode + '</textarea><br>') + newlineChar;
    document.write(flashCode);
}
