﻿/// <reference name="MicrosoftAjax.js"/>
   
var _auditionURL = "/DownloadHandler.ashx?musicID=";
var _currentElement = null;
var _isPlaying = false;
var _musicList = new Array();
var _audImg = ['/images/bu_listen_anime.gif', '/images/custom/icon01_anim.gif'];
var _img = '/images/bu_listen_anime.gif';

function auditionPlayNoImg (element,musicID,menuType){
    if(_currentElement == null){
        // 最初の再生
        _currentElement = element;        
        _externalFlashPlayNoImg(musicID,menuType);
        return;
    }

    if(_currentElement == element){
        if(_isPlaying){
            // 停止
            _externalFlashStopNoImg();
        }else{
            // 再生
            _externalFlashPlayNoImg(musicID,menuType);
        }
    }else{
        // 曲を変えて再生
        _externalFlashStopNoImg();
        _currentElement = element;        
        _externalFlashPlayNoImg(musicID,menuType);
    }
}

function _externalFlashPlayNoImg(musicID,menuType){
    _isPlaying = true;

    if(_musicList[musicID] != musicID){
        // 最初のファイル読み込み
        _musicList[musicID] = musicID;
        document.getElementById("externalFlash").externalLoad(musicID, _auditionURL + musicID + "&menuType=" + menuType);
//        document.getElementById("externalFlash").externalLoad(musicID, "/1.mp3");
    }else{
       document.getElementById("externalFlash").externalPlay(musicID);
    }
}

function _externalFlashStopNoImg(){
    _isPlaying = false;
    document.getElementById("externalFlash").externalStop();
}



function auditionPlay(element, musicID, menuType, imgType) {
    _img = _audImg[imgType];
    if(_currentElement == null){
        // 最初の再生
        _currentElement = element;        
        _externalFlashPlay(musicID,menuType);
        return;
    }

    if(_currentElement == element){
        if(_isPlaying){
            // 停止
            _externalFlashStop();
        }else{
            // 再生
            _externalFlashPlay(musicID,menuType);
        }
    }else{
        // 曲を変えて再生
        _externalFlashStop();
        _currentElement = element;        
        _externalFlashPlay(musicID,menuType);
    }
}

function _externalFlashPlay(musicID,menuType){
    _isPlaying = true;
    _currentElement.setAttribute("stopimg", _currentElement.src);
    _currentElement.src = _img;  	            

    if(_musicList[musicID] != musicID){
        // 最初のファイル読み込み
        _musicList[musicID] = musicID;
        document.getElementById("externalFlash").externalLoad(musicID, _auditionURL + musicID + "&menuType=" + menuType);
//        document.getElementById("externalFlash").externalLoad(musicID, "/1.mp3");
    }else{
       document.getElementById("externalFlash").externalPlay(musicID);
    }
}

function _externalFlashStop(){
    _isPlaying = false;
    stopImg = _currentElement.getAttribute("stopimg");
    _currentElement.src= (stopImg)? stopImg : '/images/icon01.gif';      
    document.getElementById("externalFlash").externalStop();
}
      
function pageLoad(){
    initializeMp3Player();
}

function initializeMp3Player(){
    var so = new SWFObject("/swf/mp3_player_multi.swf", "externalFlash", "1", "1", "9", "#ffffff");
    so.write("externalFlashArea");
    _currentElement = null;
    _isPlaying = false;
    _musicList = new Array();
}

