var MediaTemp = new Array();

// 获得js文件传入的参数
var baseurl = '';
var sc = document.getElementsByTagName('script');
var scurl = sc[sc.length - 1].src
var baseurl = scurl.substring(0, scurl.lastIndexOf("/") + 1);

/**
* 在网页中嵌入可展开与折叠的多媒体
*
* strType	: 媒体类型, 支持swf flv wma wmv rm ra qt
* strUrl	: 媒体地址
* strWidth	: 宽度
* strHeight : 高度
*
* 2008年1月19日 cpiz 创建
*/
function BuildPlayer(strType, strURL, intWidth, intHeight) {
    var strID = getUniqID();
    document.write("<blockquote>");
    //MediaShow(strType, strID,strURL,intWidth,intHeight);

    document.write("<object type=\"application/x-shockwave-flash\" data=\"" + baseurl + "audioplayer.swf\" width=\"300\" height=\"24\" id=\"audioplayer\"><param name=\"movie\" value=\"" + baseurl + "audioplayer.swf\" /><param name=\"FlashVars\" value=\"soundFile=" + strURL + "\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"bgcolor\" value=\"#F4F5F7\" /></object>");
    document.write("	<p id=\"" + strID + "\">&nbsp;</p>");
    document.write("</blockquote>");
}

function MediaShow(strType, strID, strURL, intWidth, intHeight) {
    var tmpstr = "";
    if (MediaTemp[strID] == undefined) {
        MediaTemp[strID] = false;
    }
    else {
        MediaTemp[strID] = !MediaTemp[strID];
    }


//    if (MediaTemp[strID]) {
//        if (document.all) {
//            document.getElementById(strID).outerHTML = '<p id="' + strID + '">&nbsp;</p>';
//        }
//        else {
//            document.getElementById(strID).innerHTML = '&nbsp';
//        }



//        document.getElementById(strID + "_href").innerHTML = "展开" + strType.toUpperCase() + "内容";

//    } else {


        //document.getElementById(strID + "_href").innerHTML = "折叠" + strType.toUpperCase() + "内容";
        switch (strType) {
            case "swf":
                tmpstr = '<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + intWidth + '" height="' + intHeight + '"><param name="movie" value="' + strURL + '" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="' + strURL + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + intWidth + '" height="' + intHeight + '" /></object>';
                break;
            case "flv":
                tmpstr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + intWidth + '" height="' + intHeight + '"><param name="movie" value="' + baseurl + 'flvplayer.swf?IsAutoPlay=1&BarPosition=1&IsShowBar=1&vcastr_file=' + strURL + '"><param name="quality" value="high"><param name="allowFullScreen" value="true" /><embed src="' + baseurl + 'flvplayer.swf?IsAutoPlay=1&BarPosition=1&IsShowBar=1&vcastr_file=' + strURL + '" allowFullScreen="true"   quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + intWidth + '" height="' + intHeight + '"></embed></object>';
                break;
            case "mp3":
                tmpstr = '<object type="application/x-shockwave-flash" data="' + baseurl + 'audioplayer.swf" width="300" height="24" id="audioplayer"><param name="movie" value="' + baseurl + 'audioplayer.swf" /><param name="FlashVars" value="soundFile=' + strURL + '" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="bgcolor" value="#FFFFFF" /></object>';
                break;
            case "wma":
                tmpstr = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="' + intWidth + '" height="' + intHeight + '"><param name="FileName" VALUE="' + strURL + '" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + strURL + '" autostart="true" width="300" height="45" /></object>';
                break;
            case "wmv":
                tmpstr = '<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="' + intWidth + '" height="' + intHeight + '"><param name="FileName" VALUE="' + strURL + '" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + strURL + '" autostart="true" width="' + intWidth + '" height="' + intHeight + '" /></object>';
                break;
            case "rm":
                tmpstr = '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="' + intWidth + '" height="' + intHeight + '"><param name="SRC" value="' + strURL + '" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="' + strURL + '" nojava="true" controls="ImageWindow" console="one" width="' + intWidth + '" height="' + intHeight + '"></object>' +
				'<br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="' + intWidth + '" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="' + strURL + '" nojava="true" controls="StatusBar" console="one" width="' + intWidth + '" height="24" /></object>' + '<br /><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="' + intWidth + '" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="' + strURL + '" nojava="true" controls="ControlPanel" console="one" width="' + intWidth + '" height="24" autostart="true" loop="false" /></object>';
                break;
            case "ra":
                tmpstr = '<object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" id="RAOCX" width="450" height="60"><param name="_ExtentX" value="6694"><param name="_ExtentY" value="1588"><param name="AUTOSTART" value="true"><param name="SHUFFLE" value="0"><param name="PREFETCH" value="0"><param name="NOLABELS" value="0"><param name="SRC" value="' + strURL + '"><param name="CONTROLS" value="StatusBar,ControlPanel"><param name="LOOP" value="0"><param name="NUMLOOP" value="0"><param name="CENTER" value="0"><param name="MAINTAINASPECT" value="0"><param name="BACKGROUNDCOLOR" value="#000000"><embed src="' + strURL + '" width="450" autostart="true" height="60"></embed></object>';
                break;
            case "qt":
                tmpstr = '<embed src="' + strURL + '" autoplay="true" loop="false" controller="true" playeveryframe="false" cache="false" scale="TOFIT" bgcolor="#000000" kioskmode="false" targetcache="false" pluginspage="http://www.apple.com/quicktime/" />';
        }
        //document.getElementById(strID).innerHTML = tmpstr;
//    }
    //document.getElementById(strID + "_href").blur();
}

// 创建唯一ID值
function getUniqID() {
    var uniqid = "";
    for (var i = 1; i <= 32; i++) {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        uniqid += n;

        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            uniqid += "-";
    }
    return uniqid;
}
