jQuery.noConflict();
jQuery(function($){	//onload event
	playSampleInit();
});

function playSampleInit(){
	var d = document;
	var type = typeof(d.createElement);
	if (!((type == "function") || (type == "object"))){return;}	//Win IE 5は、"object"を返す

	d.sectionObj = null;
	d.ua = "";

	 if (navigator.userAgent.match(/MSIE 5.+Mac_PowerPC/i)){
		d.ua = "MacIE5";
	}else if (navigator.userAgent.match(/Safari/i)){
		d.ua = "Safari";
	}else if (navigator.userAgent.match(/Opera/i)){
		d.ua = "Opera";	//Opera 7〜
	}
}

//Flash用のdiv要素を新規作成し、任意のdiv.section要素の最後に追加する。
function createFlashBox(obj){
	var d = document;
	if (! d.createElement){ return;}
	if (! d.getElementById){return;}
	
	var flashBox = d.createElement("div");
	flashBox.setAttribute("id","flashBox");
	obj.appendChild(flashBox);
}


function playSample(obj){
	var d = document;
	var type = typeof(d.createElement);
	if (!((type == "function") || (type == "object"))){return;}	//Win IE 5は、"object"を返す
	if (! d.getElementById){return true;}
	
	//swfが読み込まれていれば、一旦削除する。
	if (d.sectionObj){
		var flashBox;
		if (flashBox = d.getElementById("flashBox")){
			if (d.ua == "MacIE5"){
				flashBox.innerHTML = "";	//MacIE5は、こうしないとバグる。
			}else {
				flashBox.removeChild(flashBox.lastChild);
			}
			d.sectionObj.removeChild(d.sectionObj.lastChild);
		}
	}
	
	//get current div.section要素
	//d.sectionObj = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
	
	//get parent div.section要素
	//d.sectionObj = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	
	//get parent div.section要素
	d.sectionObj = obj.parentNode;
	
	if (! d.sectionObj){return true;}

	var flashBox = d.createElement("div");
	flashBox.setAttribute("id","flashBox");
	d.sectionObj.appendChild(flashBox);

	var flaObj;

	if ((d.ua == "Opera") || (d.ua == "Safari") || (d.ua == "MacIE5")){	//(Win IEと同じ処理)
		flaObj = getFlashObjectElement(obj.href,obj.title);
		flashBox.innerHTML = flaObj;
	}else if (d.createElementNS){	//for Moz
		//flaObj = createFlashObjectElement(obj.href,obj.text);
		flaObj = createFlashObjectElement(obj.href,obj.title);
		if (! flaObj){return true;}
		flashBox.appendChild(flaObj);
	}else if (d.body.innerHTML){	//for Win IE
		//flaObj = getFlashObjectElement(obj.href,obj.innerText);
		flaObj = getFlashObjectElement(obj.href,obj.title);
		flashBox.innerHTML = flaObj;
	}else{
		return true;
	}

	return false;
}

//flash用object要素を動的に生成して返す。for Moz
function createFlashObjectElement(path,songname){
	var d = document;
	var obj;

	if (! d.createElement){ return;}
	obj = d.createElement("object");

	if (typeof(encodeURI) == "function"){
		songname = encodeURI(songname);
	}else{
		songname = "";
	}

	var filePath = gRootDir + "/sample_player_3.swf?path=" + path + "&songname=" +songname;
	var param1 = d.createElement("param");
	param1.setAttribute("name","movie");
	param1.setAttribute("value",filePath);
	obj.appendChild(param1);
	
	var param2 = d.createElement("param");
	param2.setAttribute("name","quality");
	param2.setAttribute("value","high");
	obj.appendChild(param2);
	
	var param3 = d.createElement("param");
	param3.setAttribute("name","bgcolor");
	param3.setAttribute("value","#ccffcc");
	obj.appendChild(param3);

	obj.setAttribute("id","flashObj");
	obj.setAttribute("data",filePath);
	obj.setAttribute("type","application/x-shockwave-flash");
	obj.setAttribute("width","360");
	obj.setAttribute("height","50");

	return obj;
}

/*	[memo]
 '<object data="sample_player_3.swf?path=' + path + '" type="application/x-shockwave-flash" width="440" height="30">' + "\n" +
'<param name="movie" value="sample_player_3.swf?path=' + path + '" />' + "\n" +
'<param name="quality" value="high" />' + "\n" +
'<param name="bgcolor" value="#ffffff" />' +  "\n" +
'</object>'
*/


//Flash用のobject要素を生成して返す。
function getFlashObjectElement(path,songname){
	if (typeof(encodeURI) == "function"){
		songname = encodeURI(songname);
	}else{
		songname = "";
	}

	var filePath = "/sample_player_3.swf?path=" + path + "&songname=" +songname;

	return '<object id="flashObj" data="' + filePath + '" type="application/x-shockwave-flash" width="360" height="50">' + "\n" +
'<param name="movie" value="' + filePath + '" />' + "\n" +
'<param name="quality" value="high" />' + "\n" +
'<param name="bgcolor" value="#ccffcc" />' +  "\n" +
'</object>' + "\n";
}



