var music_i = 0;
var Song = new Array();
var playingSoundId = 0;

//检测用户是否登
function checkUserLogin(){
	var login=false;
	var src=$("#keeper_content").attr("src");
	if(src.indexOf("nokeeper.html")==-1) {
		login=true;
	}
	return login;
}

//判断登录回调
function needLogin() {
	document.getElementById('frame_content').contentWindow.loginToFullMusic();
}

//获得Iframe中的对象
function getIframeObj(frame_content) {
    var Browser_Name = navigator.appName;
    var doc;
    if (Browser_Name == "Microsoft Internet Explorer") {
		if(document.frames[frame_content]!=null) {
        	doc = document.frames[frame_content].document;
		}
    } 
	else {
		if (document.getElementById(frame_content) != null) {
        	doc = document.getElementById(frame_content).contentDocument;
		}
    }
    return doc;
}

//取flash对象的兼容方法
function thisMovie(movieName)
{	
    return swfobject.getObjectById(movieName);
}

//设置播放器界面模式
function setPlayerUIMode(bottom,duration) {
    if (String($("#mp3Player").css('bottom')) != bottom) {
        $("#mp3Player").animate({
            bottom: bottom
        },
        {
            duration: duration
        });
    }
}

//收藏并播放方法
function addAndPlay(id)
{
    top.thisMovie('musicBox').addToPlayList(Song[id]);
}

//收藏方法
function addFunc(id)
{
    top.thisMovie('musicBox').addToPlayList(this['song' + id], false);
}

//播放器加载方法
function soundStartLoad(id) {
	//console.log("开始加载歌曲："+id);
	var dom=$("#frame_content").contents().find('#play_menu_' + id);
	if(dom.attr('className')!='style_loading_menu') {
		dom.attr('className','style_loading_menu');
	}
    playingSoundId = id;
    if (id != 0) {
        var urlStr = '/music/playMusic.action?ablummusic.id=' + id;
        $.ajax({
            url: urlStr,
            cache: false,
            success: function(originalRequest) {}
        });
    }
}

//声音开始播放
function soundStartPlay(id) {
	//console.log("开始播放歌曲："+id);
	playCssReset();
    var dom=$("#frame_content").contents().find('#play_menu_' + id);
	if(dom.attr('className')!='style_playing_menu') {
		dom.attr('className','style_playing_menu');
	}
}

//声音停止播放
function soundStop(id) {
	//console.log("停止播放歌曲："+id);
    playCssReset();
	var dom=$("#frame_content").contents().find('#play_menu_' + id);
	if(dom.attr('className')!='style_play_menu') {
		dom.attr('className','style_play_menu');
	}
    playingSoundId = 0;
}

//CSS样式复原
function playCssReset() {
	$("#frame_content").contents().find('.style_loading_menu').each(function() {
		$(this).addClass('style_play_menu');
		$(this).removeClass('style_loading_menu');
    });
	
	$("#frame_content").contents().find('.style_loading_menu').each(function() {
		$(this).addClass('style_play_menu');
		$(this).removeClass('style_playing_menu');
    });
}

//播放列表歌曲
function playList() {
    if (confirm("确定要播放整个列表吗？")) {
        top.thisMovie('musicBox').addAllToPlaylist(Song);
    }
}

//保存自定义专辑方法
/*
data数据格式：
albumCoverImg:String  自定义专辑封面图片地址
albumIntro:String  自定义专辑介绍
albumName:String  自定义专辑名称
albumSongList:Array  自定义专辑歌曲id数组
*/
function cutomAlbumSave(data) {
    var jsonData = jsonParse(String(data));
    var url = '/index/saveCustomizeAlbum.action';
    var amids = "";
    for (var i = 0; i < jsonData.albumSongList.length; i++) {
        amids = amids + (i > 0 ? ",": "") + jsonData.albumSongList[i];
    }
    jQuery.post(
    url, {
        'album.name': jsonData.albumName,
        'album.describe': jsonData.albumIntro,
        'album.imgPath': jsonData.albumCoverImg,
        'amIds': amids
    },
    function(originalRequest) {
        if (originalRequest == "needToLogin") {
            thisMovie('playerObj').customAlbumSaveCallback(false);
            $('#frame_content').filter('#basic-modal-content').modal();
            //document.getElementById("flash_say_iframe").getElementById("basic-modal-content").modal();
        } else if (originalRequest == "Success") {
            thisMovie('musicBox').customAlbumSaveCallback(true);
        } else if (originalRequest == "Fail")
        thisMovie('musicBox').customAlbumSaveCallback(false);
    });
}

//浏览专辑详细信息
function albumDetailView(albumId) {
    //document.getElementById('frame_content').src='/index/albumDetail.action?album.id='+albumId;
    top.koocuHref('/album/' + albumId, true);
}

//歌曲上传方法
function songBatchUpload(albumId) {
    top.thisMovie('musicBox').albumSongsUpload(albumId);
}

//专辑歌曲排序方法
function albumSongSort(albumId) {
    top.thisMovie('musicBox').albumEdit(albumId);
}

// 专辑编辑保存方法
/*
data数据格式：
albumId:String  专辑id
listArr:Array  专辑歌曲列表
	songId:String    歌曲id
	songName:String  歌曲名称
	delete:Boolean   是否删除标识
	update:Boolean   是否更新标识
*/
function albumSongsListSave(data) {
    var url = '/music/modifyMusicInAlbum_saylikes.action';
    jQuery.post(
    url, {
        'jsonStr': data + ''
    },
    function(originalRequest) {
        albumSongsListSaveCallback(originalRequest);
    });
}

//专辑保存回调方法
function albumSongsListSaveCallback(check) {
    if (check == 'success') {
        //保存成功
        thisMovie('musicBox').albumSongsListSaveCallback(true);
    } else {
        //保存失败
        thisMovie('musicBox').albumSongsListSaveCallback(false);
    }
}

//消息通知声音播放方法
function infoSndPlay(info) {
    thisMovie('musicBox').playInfoSound(info);
}

//电台音乐播放
function radioMusicPlay(radioSnd) {
    top.thisMovie('musicBox').playRadio(radioSnd);
}

//电台音乐停止
function radioMusicStop() {
    top.thisMovie('musicBox').stopRadio();
}

//电台播放完毕回调
function radioPlayComplete() {
    frame_content.window.showdt_next();
}

//键盘事件监听
$(document).keydown(
function(event) {
    if (event.target.type == "text" || event.target.type == "password" || event.target.type == "textarea" || event.target.type == "application/x-shockwave-flash") {
        return true;
    }
    else {
        switch (event.keyCode) {
			case 32:
				top.thisMovie('musicBox').playControlByKeyboard('playOrPause');
				return false;
				break;
				
			case 37:
				top.thisMovie('musicBox').playControlByKeyboard('previous');
				return false;
				break;
	
			case 39:
				top.thisMovie('musicBox').playControlByKeyboard('next');
				return false;
				break;
	
			case 107:
			case 187:
				top.thisMovie('musicBox').playControlByKeyboard('volumeUp');
				return false;
				break;
	
			case 109:
			case 189:
				top.thisMovie('musicBox').playControlByKeyboard('volumeDown');
				return false;
				break;
	
			case 82:
				top.thisMovie('musicBox').playControlByKeyboard('playModeSwitch');
				return false;
				break;
        }

    }

}

);