
var httpObj;
var timerId;
var t;
var timerId;
var timerObj;

//************************************************************************
// AJAX 送信処理
//************************************************************************
function httpRequest(objid, url) {
	try {
		if ( window.XMLHttpRequest ) {
			httpObj = new XMLHttpRequest();
		} else if ( window.ActiveXObject ) {
			httpObj = new ActiveXObject( "Microsoft.XMLHTTP" );
		} else {
			httpObj = false;
		}
	} catch(e) {
		httpObj = false;
	}
	if ( !httpObj ) {
		alert('SORRY Your Blowser id not used');
		return false;
	}
	
	timerObj = new Object();
	timerObj.timeout_sec = 30;
	timerId = setInterval('timeoutCheck()' , 1000);
	
	httpObj.open("GET", url, true);
	httpObj.onreadystatechange = function() {
		if ( httpObj.readyState == 4 ) {
			clearInterval(timerId);
			document.getElementById(objid).innerHTML = httpObj.responseText;
		}
	}
    
	document.getElementById(objid).zIndex = maxLayer + 2;
	document.getElementById(objid).innerHTML = "<div><img src='http://jsmusicbox.homeip.net/~jsmusicbox/ajax-loader.gif'>"+"<" + "/"+"div>";
	httpObj.send('');
}
//************************************************************************
// AJAX タイムアウトチェック処理
//************************************************************************
function timeoutCheck() {
	timerObj.timeout_sec --;
	if ( timerObj.timeout_sec <= 0 ) {
		clearInterval(timerId);
		httpObj.abort();
		status = "timeout";
		return false;
	}
}
//************************************************************************
// Cookie設定
//************************************************************************
function setCookie(key,val){
	var today = new Date();
	var expires = new Date();
	expireperiod = 1000*60*60*24*365;
	
	expires.setTime(today.getTime() + expireperiod);
	document.cookie = key + "=" + val + '; expires=' + expires.toGMTString()
}
//************************************************************************
// Cookie取得
//************************************************************************
function getCookie(key){
	var search = key + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";",offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			return document.cookie.substring(offset,end);
		}
	}
	return '';
}
//************************************************************************
// midifile設定
//************************************************************************
function song_set() {
	songs="http://" + location.hostname + "/~jsmusicbox/"+arguments[0]+".mid";
	window.status="Loading...";
	t = '<img src="php/download.php?args=' + arguments[0] + '.mid&mode=play" width="1" height="1">';
	if (navigator.javaEnabled() && document.form.elements["appchk"].checked == false) {
		if ( document.form.elements["litechk"].checked == false ) {
			t = t + '<applet archive="jsplayer.jar" code="jsplayer.class" width="' + player_width + '" height="' + player_height + '" MAYSCRIPT>';
		} else {
			t = t + '<applet archive="jsplayer_lite.jar" code="jsplayer_lite.class" width="' + player_width + '" height="' + player_height + '" MAYSCRIPT>';
		}
		t = t + '<PARAM NAME="URL" VALUE="'+songs+'">';
		t = t + '<PARAM NAME="AutoStart" VALUE="true">';
		t = t + '<PARAM NAME="vocal" VALUE="' + getCookie("vocal") + '">';
		t = t + '<PARAM NAME="jukebox" VALUE="false">';
		t = t + '<PARAM NAME="mode" VALUE="style_white">';
		t = t + '<PARAM NAME="device" VALUE="' + getCookie("device") + '">';
		t = t + '<'+'/'+'applet>';
		t = t + '<SCRIPT FOR="MediaPlayer" EVENT="EndOfStream(lResult)" LANGUAGE="JScript">';
		t = t + '	window.status="END";';
		t = t + '<'+'/'+'SCRIPT>';
	} else {
		t = t + '<object ID="MediaPlayer" WIDTH=150 HEIGHT=50 ';
		t = t + 'CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
		t = t + 'STANDBY="Loading Windows Media Player components..." ';
		t = t + 'TYPE="audio/midi"> ';
		t = t + '<PARAM NAME="FileName" VALUE="'+songs+'">';
		t = t + '<PARAM NAME="ShowControls" VALUE="true">';
		t = t + '<PARAM NAME="ShowPositionControls" VALUE="false">';
		t = t + '<PARAM NAME="ShowAudioControls" VALUE="false">';
		t = t + '<embed src=';
		t = t + songs;
		t = t + ' name="midiplayer" width="150" height="50" autostart="true" loop="false" save="false" TYPE="audio/midi">'+'<'+'/embed>';
		t = t + '<'+'/'+'object>';
		t = t + '<SCRIPT FOR="MediaPlayer" EVENT="EndOfStream(lResult)" LANGUAGE="JScript">';
		t = t + '	window.status="END";';
		t = t + '<'+'/'+'SCRIPT>';
	}
	document.getElementById("jsplayer").innerHTML = t;
	window.status="Play...";
	return false;
}
//************************************************************************
// midifile設定
//************************************************************************
function song_set2() {
	songs="http://" + location.hostname + "/~jsmusicbox/"+arguments[0]+".mid";
	t = '<img src="php/download.php?args=' + arguments[0] + '.mid&mode=play" width="1" height="1">';
						
	if (navigator.javaEnabled() && document.form.elements["appchk"].checked == false) {
		if ( document.form.elements["litechk"].checked == false ) {
			t = t + '<applet archive="jsplayer.jar" code="jsplayer.class" width="' + player_width + '" height="' + player_height + '" MAYSCRIPT>';
		} else {
			t = t + '<applet archive="jsplayer_lite.jar" code="jsplayer_lite.class" width="' + player_width + '" height="' + player_height + '" MAYSCRIPT>';
		}
		t = t + '<PARAM NAME="URL" VALUE="'+songs+'">';
		t = t + '<PARAM NAME="AutoStart" VALUE="true">';
		t = t + '<PARAM NAME="vocal" VALUE="' + getCookie("vocal") +'">';
		t = t + '<PARAM NAME="jukebox" VALUE="true">';
		t = t + '<PARAM NAME="mode" VALUE="style_white">';
		t = t + '<PARAM NAME="device" VALUE="' + getCookie("device") + '">';
		t = t + '<'+'/'+'applet>';
	} else {
		t = t + '<object ID="MediaPlayer" WIDTH=150 HEIGHT=50 ';
		t = t + 'CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
		t = t + 'STANDBY="Loading Windows Media Player components..." ';
		t = t + 'TYPE="audio/midi"> ';
		t = t + '<PARAM NAME="FileName" VALUE="'+songs+'">';
		t = t + '<PARAM NAME="ShowControls" VALUE="true">';
		t = t + '<PARAM NAME="ShowPositionControls" VALUE="false">';
		t = t + '<PARAM NAME="ShowAudioControls" VALUE="false">';
		t = t + '<embed src=';
		t = t + songs;
		t = t + ' name="midiplayer" width="150" height="50" autostart="true" loop="false" save="false" TYPE="audio/midi">'+'<'+'/embed>';
		t = t + '<'+'/'+'object>';
		t = t + '<SCRIPT FOR="MediaPlayer" EVENT="EndOfStream(lResult)" LANGUAGE="JScript">';
		t = t + '	main.next();';
		t = t + '	window.status="END";';
		t = t + '<'+'/'+'SCRIPT>';
	}
	document.getElementById("jsplayer").innerHTML = t;
	window.status="Play...";
	return false;
}
//************************************************************************
// midifile stop
//************************************************************************
function song_stop() {
	window.status="stop";
	songs="http://" + location.hostname + "/~jsmusicbox/roland/88reset.mid";
	t = "";
	if (navigator.javaEnabled() && document.form.elements["appchk"].checked == false) {
		if ( document.form.elements["litechk"].checked == false ) {
			t = t + '<applet archive="jsplayer.jar" code="jsplayer.class" width="' + player_width + '" height="' + player_height + '" MAYSCRIPT>';
		} else {
			t = t + '<applet archive="jsplayer_lite.jar" code="jsplayer_lite.class" width="' + player_width + '" height="' + player_height + '" MAYSCRIPT>';
		}
		t = t + '<PARAM NAME="URL" VALUE="'+songs+'">';
		t = t + '<PARAM NAME="AutoStart" VALUE="true">';
		t = t + '<PARAM NAME="vocal" VALUE="' + getCookie("vocal") +'">';
		t = t + '<PARAM NAME="jukebox" VALUE="false">';
		t = t + '<PARAM NAME="mode" VALUE="style_white">';
		t = t + '<PARAM NAME="device" VALUE="' + getCookie("device") + '">';
		t = t + '<'+'/'+'applet>';
	} else {
		t = t + '<object ID="MediaPlayer" WIDTH=150 HEIGHT=50 ';
		t = t + 'CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
		t = t + 'STANDBY="Loading Windows Media Player components..." ';
		t = t + 'TYPE="audio/midi"> ';
		t = t + '<PARAM NAME="FileName" VALUE="'+songs+'">';
		t = t + '<PARAM NAME="ShowControls" VALUE="true">';
		t = t + '<PARAM NAME="ShowPositionControls" VALUE="false">';
		t = t + '<PARAM NAME="ShowAudioControls" VALUE="false">';
		t = t + '<embed src=';
		t = t + songs;
		t = t + ' name="midiplayer" width="150" height="50" autostart="true" loop="false" save="false" TYPE="audio/midi">'+'<'+'/embed>';
		t = t + '<'+'/'+'object>';
	}
	document.getElementById("jsplayer").innerHTML = t;
	return false;
}
//************************************************************************
// window操作
//************************************************************************
// ドラッグ対象オブジェクト情報
var dragFlag = false; // ドラッグ中かどうかのフラグ変数
var dragObj = null; // ドラッグ対象オブジェクト情報
var zi = 1;
var maxLayer = 1;
var offsetX;
var offsetY;
var win_cnt = 1;
var title_bar = 25;

//************************************************************************
// window open(AJAX)
//************************************************************************
function open_win(url,tt,nm,posX,posY,ww,hh) {
	el = document.createElement("div");
	el.setAttribute("id" , tt+"_win");
	el.setAttribute("class", "shadow");
	el.setAttribute("className", "shadow");
	document.body.appendChild(el);

    str_header = '<div id="' + tt + '_head" class="head"><img src="./close.gif" class="close" onclick="close_win(\'' + tt + '_win\')">';
    str_header = str_header + '<img src="./up.gif" onclick="SmoothScroll.scrollToRow(-300,\'' + tt + '\');" class="close" '+'/'+'>';
    str_header = str_header + '<img src="./down.gif" onclick="SmoothScroll.scrollToRow(300,\'' + tt + '\');" class="close" '+'/'+'>' + nm + '<'+'/'+'div>';
	str_contents = '<div id="' + tt + '" class="content"><'+'/'+'div>';

	document.getElementById(tt+"_win").innerHTML = str_header + str_contents;
//	document.getElementById(tt+"_win").innerHTML = str_contents;

    maxLayer++;
    zi = maxLayer;
	document.getElementById(tt+"_win").style.zIndex = maxLayer;

    if (!posY) {
    	document.getElementById(tt+"_win").style.top = positionY;
        positionY += 10;
    } else {
        document.getElementById(tt+"_win").style.top = posY;
    }

    if (!posX) {
    	document.getElementById(tt+"_win").style.left = positionX;
        positionX += 10;
    } else {
        document.getElementById(tt+"_win").style.left = posX;
    }

    ww = (!ww) ? ww_def : ww - 20;
    hh = (!hh) ? hh_def : hh;

    document.getElementById(tt+"_win").style.width = ww;
    document.getElementById(tt+"_win").style.height = hh;
    document.getElementById(tt+"_head").style.width = ww - 3;
    document.getElementById(tt+"_head").style.height = title_bar;
//    document.getElementById(tt+"_head").style.cursor = "move";
    document.getElementById(tt).style.width = ww - 3;
    document.getElementById(tt).style.height = hh - title_bar-3;

	document.getElementById(tt+"_head").onmousedown = dragStart;
	var str = tt + "_win"
	httpRequest(tt,url);

}
//************************************************************************
// window open(IFRAME)
//************************************************************************
function open_win_url(url,tt,nm,posX,posY,ww,hh) {
	el = document.createElement("div");
	el.setAttribute("id" , tt+"_win");
	el.setAttribute("class", "shadow");
	el.setAttribute("className", "shadow");
	document.body.appendChild(el);

    str_header = '<div id="' + tt + '_head" class="head"><img class="close" src="./close.gif" onclick="close_win(\'' + tt + '_win\')">';
    str_header = str_header + nm + '<'+'/'+'div>'
	str_contents = '<iframe src="' + url + '" width="' + (ww - 20) + '" height="' + hh + '"><'+'/'+'iframe>';

	document.getElementById(tt+"_win").innerHTML = str_header + str_contents;

    maxLayer++;
    zi = maxLayer;
	document.getElementById(tt+"_win").style.zIndex = zi;

    if (!posY) {
    	document.getElementById(tt+"_win").style.top = positionY;
        positionY += 10;
    } else {
        document.getElementById(tt+"_win").style.top = posY;
    }

    if (!posX) {
    	document.getElementById(tt+"_win").style.left = positionX;
        positionX += 10;
    } else {
        document.getElementById(tt+"_win").style.left = posX;
    }
    ww = (!ww) ? 400 : ww - 20;
    hh = (!hh) ? 300 : hh;

    document.getElementById(tt+"_win").style.width = ww;
    document.getElementById(tt+"_win").style.height = hh;
    document.getElementById(tt+"_head").style.width = ww - 3;
    document.getElementById(tt+"_head").style.height = title_bar;
//    document.getElementById(tt+"_head").style.cursor = "move";

	document.getElementById(tt+"_head").onmousedown = dragStart;
	var str = tt + "_win"
}
var flash_flg = false;
//************************************************************************
// window open(FLASH)
//************************************************************************
function open_flash(url,tt,nm,posX,posY,ww,hh) {

    if (flash_flg) {
	    document.getElementById(tt+"_win").style.visibility = "visible";
	} else {
		el = document.createElement("div");
		el.setAttribute("id" , tt+"_win");
		el.setAttribute("class", "flash");
		el.setAttribute("className", "flash");
		document.body.appendChild(el);

	    str_header = '<div id="' + tt + '_head" class="head"><img src="./close.gif" onclick="hide_win(\'' + tt + '_win\')" class="close" >';
	    str_header = str_header + nm + '<'+'/'+'div>'
		str_contents = '';
		//if (getCookie("layout") == "style_white") {
			str_contents = str_contents + '<OBJECT id="mididata" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" border="0" width="750" height="600" align="middle">';
			str_contents = str_contents + '<param name="movie" value="main.swf?mode=white"'+'/'+'>';
			str_contents = str_contents + '<param name="quality" value="high"'+'/'+'>';
			str_contents = str_contents + '<param name="bgcolor" value="#FFFFFF"'+'/'+'>';
			str_contents = str_contents + '<param name="allowscriptaccess" value="always"'+'/'+'>';
			str_contents = str_contents + '<EMBED src="main.swf?mode=white" id="mididata" name="mididata" align="baseline" border="0" width="750" height="600" quality="high" bgcolor="#FFFFFF" swLiveConnect=true name="mididata" type="application/x-shockwave-flash" swliveconnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />';
			str_contents = str_contents + '<'+'/'+'OBJECT>';
		//} else {
		//	str_contents = str_contents + '<OBJECT id="mididata" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" border="0" width="750" height="600" align="middle">';
		//	str_contents = str_contents + '<param name="movie" value="main.swf?mode=black"'+'/'+'>';
		//	str_contents = str_contents + '<param name="quality" value="high"'+'/'+'>';
		//	str_contents = str_contents + '<param name="bgcolor" value="#FFFFFF"'+'/'+'>';
		//	str_contents = str_contents + '<param name="allowscriptaccess" value="always"'+'/'+'>';
		//	str_contents = str_contents + '<EMBED src="main.swf?mode=black" id="mididata" name="mididata" align="baseline" border="0" width="750" height="600" quality="high" bgcolor="#000000" swLiveConnect=true name="mididata" type="application/x-shockwave-flash" swliveconnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />';
		//	str_contents = str_contents + '<'+'/'+'OBJECT>';
		//}	
		document.getElementById(tt+"_win").innerHTML = str_header + str_contents;

	    maxLayer++;
	    zi = maxLayer;
		document.getElementById(tt+"_win").style.zIndex = zi;

	    if (!posY) {
	    	document.getElementById(tt+"_win").style.top = positionY;
	        positionY += 10;
	    } else {
	        document.getElementById(tt+"_win").style.top = posY;
	    }

	    if (!posX) {
	    	document.getElementById(tt+"_win").style.left = positionX;
	        positionX += 10;
	    } else {
	        document.getElementById(tt+"_win").style.left = posX;
	    }
	    ww = (!ww) ? 400 : ww - 20;
	    hh = (!hh) ? 300 : hh;

	    document.getElementById(tt+"_win").style.width = ww;
	    document.getElementById(tt+"_win").style.height = hh;
	    document.getElementById(tt+"_head").style.width = ww - 3;
	    document.getElementById(tt+"_head").style.height = title_bar;
//	    document.getElementById(tt+"_head").style.cursor = "move";

		document.getElementById(tt+"_head").onmousedown = dragStart;
		var str = tt + "_win"
		win_cnt++;
//		httpRequest(tt,url);
	    document.getElementById(tt+"_win").style.visibility = "hidden";
		flash_flg = true;
	}
}
//************************************************************************
// window close
//************************************************************************
function close_win(t) {
//    alert(t);
    var del_obj = document.getElementById(t);
    document.body.removeChild(del_obj);
}
//************************************************************************
// window hide
//************************************************************************
function hide_win(t) {
    var hide_obj = document.getElementById(t);
    hide_obj.style.visibility = "hidden";
}
//************************************************************************
// ドラッグ開始処理
//************************************************************************
function dragStart(e) {
	dragObj = (document.all) ? event.srcElement.parentNode : e.target.parentNode;
	re = new RegExp("head$");
	if (dragObj.getAttribute("id").match(re)) {
		return;
	}
    dragFlag = true;
    if (document.layers) {
        offsetX = e.layerX;
        offsetY = e.layerY;
    } else if (document.all) {
        offsetX = event.offsetX;
        offsetY = event.offsetY;
    } else if (dragObj.getElementsByTagName) {
        offsetX = e.pageX - parseInt(dragObj.style.left);
        offsetY = e.pageY - parseInt(dragObj.style.top);
    }
    maxLayer++;
    zi = maxLayer;
    dragObj.style.zIndex = zi;
}
//************************************************************************
// ドラッグ終了処理
//************************************************************************
function dragEnd() {
    dragFlag = false;
}
//************************************************************************
// ドラッグ中の処理
//************************************************************************
function dragProc(e) {
    if (!dragFlag) return;
    if (document.layers) {
        dragObj.pageX = e.pageX - offsetX;
        dragObj.pageY = e.pageY - offsetY;
	    positionX = dragObj.pageX;
	    positionY = dragObj.pageY;
    } else if (document.all) {
        dragObj.style.left = document.body.scrollLeft + event.clientX - offsetX;
        dragObj.style.top = document.body.scrollTop + event.clientY - offsetY;
	    positionX = dragObj.style.left;
	    positionY = dragObj.style.top;
    } else if (dragObj.getElementsByTagName) {
        dragObj.style.left = e.pageX - offsetX;
        dragObj.style.top = e.pageY - offsetY;
	    positionX = dragObj.style.left;
	    positionY = dragObj.style.top;
    }
    return false;
}
window.document.onmousemove = dragProc;
window.document.onmouseup = dragEnd;

//************************************************************************
// スクロールクラス
//************************************************************************
var SmoothScroll = {};
SmoothScroll = {
	targetScrollTop : 0,	// we're gonna make the $(parentid).scrollTop -> targetScrollTop
    targetScrollPos : 0,
	dist : 0,
	timer : 0,
	count : 0,
	parentid : 0,
	lastDist : 0,
	//speedStore : [],		// for debug
	options : {},
	defaultOptions : {
		time : 1*1000,	// [ms]
		unit : 50			// [ms]
	},
	scrollTo : function( element, parent, options ){
		this.options.time = this.defaultOptions.time;
		this.options.unit = this.defaultOptions.unit;
		if( options ){
			this.options.time = ( options.time ) ? options.time : this.options.time;
			this.options.unit = ( options.unit ) ? options.unit : this.options.unit;
		}
		clearInterval( this.timer );
		this.parentid = parent;

		this.scrollTopMax = this.$(parent).scrollHeight - this.$(parent).offsetHeight + parseInt(this.$(parent).style.borderTopWidth) + parseInt(this.$(parent).style.borderBottomWidth);

		if( navigator.userAgent.match( "MSIE" ) ){
			this.targetScrollTop = ( element ) ? this.$(element).offsetTop : 0;
		}else{
			var targetOffsetTop = ( element ) ? this.$(element).offsetTop : this.$(parent).offsetTop;
			this.targetScrollTop = targetOffsetTop - this.$(parent).offsetTop;
		}
		this.targetScrollTop = ( this.targetScrollTop > this.scrollTopMax ) ? this.scrollTopMax : this.targetScrollTop;

		this.dist = this.targetScrollTop - this.$(parent).scrollTop;
		this.lastDist = 0;
		this.timer = setInterval('SmoothScroll.update()', this.options.unit );
		this.count = 0;
		//this.speedStore = [];
		this.update();
	},
	scrollToRow : function( row, parent, options ){
		this.options.time = this.defaultOptions.time;
		this.options.unit = this.defaultOptions.unit;
		if( options ){
			this.options.time = ( options.time ) ? options.time : this.options.time;
			this.options.unit = ( options.unit ) ? options.unit : this.options.unit;
		}
		clearInterval( this.timer );
		this.parentid = parent;

		this.scrollTopMax = this.$(parent).scrollHeight - this.$(parent).offsetHeight + parseInt(this.$(parent).style.borderTopWidth) + parseInt(this.$(parent).style.borderBottomWidth);

		if( navigator.userAgent.match( "MSIE" ) ){
		    this.targetScrollTop = this.targetScrollPos + row;
            if ( this.targetScrollTop < 0 ) {
                this.targetScrollTop = 0;
            }
            if ( this.targetScrollTop > this.scrollTopMax ) {
                this.targetScrollTop = this.targetScrollPos - row;
            }
		}else{
			var targetOffsetTop = this.targetScrollPos + row;
            if ( targetOffsetTop < 0 ) {
                targetOffsetTop = 0;
            }
            if ( targetOffsetTop > this.scrollTopMax ) {
               targetOffsetTop = this.targetScrollPos - row;
            }
			this.targetScrollTop = targetOffsetTop - this.$(parent).offsetTop;
		}
		this.targetScrollTop = ( this.targetScrollTop > this.scrollTopMax ) ? this.scrollTopMax : this.targetScrollTop;
		this.targetScrollPos = ( this.targetScrollTop > this.scrollTopMax ) ? this.scrollTopMax : this.targetScrollTop;

		this.dist = this.targetScrollTop - this.$(parent).scrollTop;
		this.lastDist = 0;
		this.timer = setInterval('SmoothScroll.update()', this.options.unit );
		this.count = 0;
		//this.speedStore = [];
		this.update();
	},
	update : function(){
		var dist = this.targetScrollTop - this.$(this.parentid).scrollTop;
		var speed = 2 * dist * this.options.unit / ( this.options.time - this.options.unit * this.count );
		//this.speedStore.push( speed );
		speed = ( speed > 0 ) ? Math.ceil( speed ) : Math.floor( speed );
		if( Math.abs(dist) <= Math.abs(speed) ){
			// got there
			clearInterval( this.timer );
			this.$(this.parentid).scrollTop = this.targetScrollTop;
			return;
		}else if( this.lastDist == dist ){
			// stuck
			clearInterval( this.timer );
			this.$(this.parentid).scrollTop = this.targetScrollTop;
			return;
		}
		var scrollTop = this.$(this.parentid).scrollTop + speed;
		this.$(this.parentid).scrollTop = scrollTop;
		this.lastDist = dist;
		this.count++;
		if( this.count == this.options.time / this.options.unit ){
			// timeout
			clearInterval( this.timer );
			this.$(this.parentid).scrollTop = this.targetScrollTop;
		}
	},
	$ : function(id) {
		return document.getElementById(id);
	}
}
function dl(file){
  document.location='php/download.php?args='+file+'.mid&mode=dl2';
}
/***********************************************
* Disable select-text script- c Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//form tags to omit in NS6+:
var omitformtags=["input", "textarea", "select"]

omitformtags=omitformtags.join("|")

function disableselect(e){
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}

function txt_set(id) {
	if (document.all) {
	  // IE
	  doc  = frames[id].document;
	} else {
	  // Mozilla
	  doc = document.getElementById(id).contentDocument;
	}
//	if (id.document) {
		txt = doc.body.innerHTML.replace("Lylics=","");
		txt = txt.replace("<PRE>","");
		txt = txt.replace("</PRE>","");
		txt = txt.replace("<pre>","");
		txt = txt.replace("</pre>","");
		txt = txt.replace("\x10","\x13");
		document.getElementById(id+"_txt").value = txt;
//	}
}
//************************************************************************
// midifile 操作(FLASH)
//************************************************************************
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function mididata_DoFSCommand(command, args) {

	if (command == "play") {
		song_set(args);
	} 
	if (command == "play2") {
		song_set2(args);
	}
	if (command == "dl") {
		dl(args);
	}
	if (command == "stop") {
		song_stop("");
	}
}
