﻿// JavaScript Document

document.domain="myspace.cn";


var PlayerMObject=PlayerModule();
function PlayerModule(){
	var playerUrl="http://music.myspace.cn/player.html";
	var playerWinName="only_player";
	var paraMeter={type:"",userID:0,playListID:0,songIDs:[],profileID:0,url:"",playerType:""};	// type userID songIDs  playListID
	return{
		"playSong":playSong,
		"playSongList":playSongList,
		"profilePopout":profilePopout
	}
	var popupWindow=null;
	
	function notifyMediate(){
		if(typeof(popupWindow.window.mediateIsLoad!="undefined")&&popupWindow.window.mediateIsLoad){
			popupWindow.notifyPlayer(paraMeter);
		}else{
			setTimeout(notifyMediate,300); //需要用全局变量
		}	
	}
	
	function openPlayer(aoPara){
		paraMeter=aoPara;
		var lswinvalues="alwaysRaised=yes,width=820,height=555,resizable=yes";
		if(window.open){
			if(popupWindow!=null){
				try{
					popupWindow.notifyPlayer(paraMeter);
				}catch(e){	
					popupWindow=window.open(playerUrl,playerWinName,lswinvalues);
					notifyMediate();
				}
			}else{
				popupWindow=window.open(playerUrl,playerWinName,lswinvalues);
				notifyMediate();
			}
		}else{
			openByForm("get",aoPara);
		}
	}
	function playSong(axSong){
		openPlayer({type:"song",userID:0,playListID:0,songIDs:axSong,profileID:0,url:""});
	}
	function playSongList(aiUserID,aiPlayListID){
		openPlayer({type:"list",userID:aiUserID,playListID:aiPlayListID,songIDs:[],profileID:0,url:""});
	}
	function profilePopout(url){
		playerUrl=playerUrl+"?type=profilePopout";
		openPlayer({type:"profilePopout",userID:0,playListID:0,songIDs:[],profileID:0,url:url});
	}
	

	/*第二种方式——通过临时form提交*/
	/*问题是如何保证不刷新页面*/
	function openByForm(type,ao){
		var leForm=document.createElement("form");
		leForm.method="get"; //post
		
		leForm.target=playerWinName;
		leForm.action=playerUrl;
		ao.playerType="formPlayer";	
		for(var x in ao){
			var leTypeInput=document.createElement("input");
			leTypeInput.name=x;
			leTypeInput.value=ao[x];
			leForm.appendChild(leTypeInput);
		}
		document.body.appendChild(leForm);
		leForm.submit();
		document.body.removeChild(leForm);
	}
	
}