
String.prototype.trim = function()
{
//	return this.replace(/^\s+|\s+$/, '');
	var str = (arguments.length == 0)? '\\s': '(' + Array.prototype.slice.call(arguments).join( '|' ) + ')';
	var reg = new RegExp('^' + str + '+|' + str + '+$', 'g');
	return this.replace(reg, '');
}
String.prototype.trimStart = function()
{
	var str = (arguments.length == 0)? '\\s': '(' + Array.prototype.slice.call(arguments).join( '|' ) + ')';
	var reg = new RegExp('^' + str + '+');
	return this.replace(reg, '');
}
String.prototype.trimEnd = function()
{
	var str = (arguments.length == 0)? '\\s': '(' + Array.prototype.slice.call(arguments).join( '|' ) + ')';
	var reg = new RegExp(str + '+$');
	return this.replace(reg, '');
}


String.prototype.startsWith = function( str )
{
	if( this.length < str.length )
		return false;
	
	return this.substr( str.length ) == str;
}

String.prototype.endsWith = function( str )
{
	if( this.length < str.length )
		return false;
	
	return this.substr( this.length - str.length ) == str;
}

String.prototype._indexOf = String.prototype.indexOf;
String.prototype.indexOf = function( str, from, ignoreCase )
{
	if( ignoreCase )
		return this.toLowerCase()._indexOf( str.toLowerCase(), from );
	else
		return this._indexOf( str, from );
}

String.prototype._lastIndexOf = String.prototype.lastIndexOf;
String.prototype.lastIndexOf = function( str, from, ignoreCase )
{
	if( ignoreCase )
		return this.toLowerCase()._lastIndexOf( str.toLowerCase(), from );
	else
		return this._lastIndexOf( str, from );
}

String.prototype.contains = function( str, ignoreCase )
{
	return this.indexOf( str, 0, ignoreCase ) >= 0;
}

String.format = function(){
	if( arguments.length == 0 )
		return '';
	
	var args = arguments;
	var fmt = args[0];
	return fmt.replace( /{(\d+):?([^}]*)}/g, function( val, m1, m2, offset, str ){
		var fmt2 = m2;
		var obj = args[parseInt( m1 ) + 1];
		if( obj == undefined )
			return '';
		
		try{
			return obj.toString( fmt2 );
		}catch(e){
			return obj.toString();
		}
	} );
}


String.prototype.substrB = function( i, maxLen )
{
	if( i == undefined )
		return this;
	if( maxLen == undefined )
		maxLen = this.getByteLength() - i;
//	else
//		maxLen = Math.min( maxLen, this.getByteLength() - i );

	
	var chAry = new Array();
	var len = 0;
	for( ; i < this.length && len < maxLen; i++ ){
		chAry[chAry.length] = this.charAt( i );
		
        // Shift_JIS: 0x0 〜 0x80, 0xa0 , 0xa1 〜 0xdf , 0xfd 〜 0xff 
        // Unicode : 0x0 〜 0x80, 0xf8f0, 0xff61 〜 0xff9f, 0xf8f1 〜 0xf8f3 
		var ch = this.charCodeAt( i );
        if ( (ch >= 0x0 && ch < 0x81) || (ch == 0xf8f0) || (ch >= 0xff61 && ch < 0xffa0) || (ch >= 0xf8f1 && ch < 0xf8f4) )
			len++;
        else
			len += 2;
	}
//	alert( String.format( '{0}\n{1}', chAry, len ) );
	if( len > maxLen )
		delete chAry[chAry.length - 1];
		
	return chAry.join( '' );
}

String.prototype.getByteLength = function()
{
	var len = 0;
	for( var i = 0; i < this.length; i++ ){
		var ch = this.charCodeAt( i );
		
        // Shift_JIS: 0x0 〜 0x80, 0xa0 , 0xa1 〜 0xdf , 0xfd 〜 0xff 
        // Unicode : 0x0 〜 0x80, 0xf8f0, 0xff61 〜 0xff9f, 0xf8f1 〜 0xf8f3 
        if ( (ch >= 0x0 && ch < 0x81) || (ch == 0xf8f0) || (ch >= 0xff61 && ch < 0xffa0) || (ch >= 0xf8f1 && ch < 0xf8f4) )
			len++;
        else
			len += 2;
	}
	return len;
}


String.repeat = function( ch, len )
{
	var list = new Array();
	for( var i = 0; i < len; i++ ){
		list.push( ch );
	}
	return list.join( '' );
}

String.substr = function( text, idx, len, sfx, leftToRight )
{
	// 引数の検証
	if( !text )
		return '';
	if( len == undefined ){
		len = idx;
		idx = 0;
	}
	if( sfx == undefined )
		sfx = '';
	if( leftToRight == undefined )
		leftToRight = true;
	
	if( !leftToRight )
		idx = text.length - idx - len;

	if( idx < 0 )
		idx = 0;
	else if( idx >= text.length )
		return '';

	if( len < 0 )
		len = text.length;

	if( len > text.length - idx )
	{
		len = text.length - idx;
		sfx = '';
	}

	if( leftToRight )
		return text.substr( idx, len ) + sfx;
	else
		return sfx + text.substr( idx, len );
}

Number.prototype.toStringBase = Number.prototype.toString;
Number.prototype.toString = function()
{
	var thisObj = this;
	var strNum = this.toStringBase();
	if( arguments.length == 0 || arguments[0] == '' )
		return strNum;
		
	var fmt = String( arguments[0] );
	if( fmt.match( /(\d+)/ ) ){
		// n 進数変換
		return this.toStringBase( RegExp.$1 );
	}
	
	return fmt.replace( /([cdefgnpx])(-?\d*)/i, function( val, m1, m2, offset, str ){
		var type = m1;
		var precision = parseInt( m2 );
		if( isNaN( precision) )
			precision = -1;
		
		switch( type.toLowerCase() ){
			case 'd':
				if( precision < 0 )
					precision = 0;
				
				strNum = parseInt( strNum ).toString();
				var len = precision - strNum.length;
				return String.repeat( 0, len ) + strNum;
				
			case 'f':
				if( precision < 0 )
					precision = 8;

				var len;
				var idxDot = strNum.indexOf( '.' );
				if( idxDot < 0 ){
					strNum += '.';
					len = precision;
				}else{
					len = precision - (strNum.length - idxDot - 1);
				}
				
				if( precision == 0 )
					return parseInt( strNum );
				if( len < 0 )
					return strNum.substr( 0, idxDot + 1 + precision );
				else if( len > 0 )
					return strNum + String.repeat( 0, len );
//					return (strNum + String.repeat( 0, len )).substr( 0, idxDot + 1 + precision );
				else
					return strNum;
				
			case 'x':
				if( precision < 0 )
					precision = 0;
				
				strNum = thisObj.toStringBase( 16 ).toString();
				var len = precision - strNum.length;
				return String.repeat( 0, len ) + strNum;
				
			default:
				return strNum;
		}
	} );
}

Date.prototype.toString = function()
{
	var fmt = ( arguments.length == 0 )? 'yyyy/MM/dd HH:mm:ss': arguments[0];
	
	var date = this;
//	alert( this.getFullYear().toString );
	return fmt.replace( /y+|m+|d+|h+|s+/ig, function( val, offset, str ){
		switch( val ){
			case 'yyyy':
				return date.getFullYear().toString( 'd4' );
			case 'yy':
				return date.getFullYear().toString( 'd2' ).substr( 2, 2 );
			case 'MM':
				return (date.getMonth() + 1).toString( 'd2' );
			case 'dd':
				return date.getDate().toString( 'd2' );
			case 'ddd':
				return date.getDay().toString( 'd2' );
			case 'HH':
			case 'hh':
				return date.getHours().toString( 'd2' );
			case 'mm':
				return date.getMinutes().toString( 'd2' );
			case 'ss':
				return date.getSeconds().toString( 'd2' );
			default:
				return val;
		}
	} );
}

Array.prototype.toString = function()
{
	return this.join( ', ' );
}
Array.prototype.add = function( value )
{
	this[this.length] = value;
}
Array.prototype.removeAt = function( index )
{
	var value = this[index];
	this.splice( index, 1 );
	return value;
}
Array.prototype.remove = function( value )
{
	for( var i = 0; i < this.length; i++ )
	{
		if( this[i] == value )
		{
			return this.removeAt( i );
		}
	}
	return null;
}
Array.prototype.insert = function( index, value )
{
	this.splice( index, 0, value );
}
Array.prototype.clear = function()
{
	this.splice( 0, this.length );
}


///
///	document.getElementById 関数の省略形
///
function $( id, prop, val )
{
	var elem = document.getElementById( id );
	if( !elem || prop == undefined )
		return elem;
	
	if( val == undefined )
		return elem[prop];
	
	var prevVal = elem[prop];
	elem[prop] = val;
	return prevVal;
}

///
///	document.getElementsByName 関数の省略形
///
function $N( name, idx, prop, val )
{
	var elems = document.getElementsByName( name );
	if( !elems || idx == undefined )
		return elems;
	
	var elem = elems[idx];
	if( !elem || prop == undefined )
		return elem;
	
	if( val == undefined )
		return elem[prop];
	
	var prevVal = elem[prop];
	elem[prop] = val;
	return prevVal;
}

var Misc = {
	///
	/// addEventListener を attachEvent に結び附ける
	///
	addEventListener: function( node, name ,func )
	{
		if( node.addEventListener )
		{
			node.addEventListener( name, func, false );
		}
		else if(document.all && document.attachEvent && node.attachEvent)
		{
			node.attachEvent( "on" + name, function()
			{
				var e;
				if( event )
				{
					e = {
						currentTarget: node,
						cancelBubble: event.cancelBubble,
						keyVal: event.keyCode,
						clientX: event.clientX,
						clientY: event.clientY,
						screenX: event.screenX,
						screenY: event.screenY,
						pageX: event.x + Window.getScrollLeft,	// ??
						pageY: event.y + Window.getScrollTop,	// ??
						layerX: event.offsetX,
						layerY: event.offsetY,
						which: event.button,
						
						ctrlKey: event.ctrlKey,
						shiftKey: event.shiftKey,
						
						returnValue: true,
						cancelBubble: false,
						preventDefault: function()
						{
							this.returnValue = false;
						},
						stopPropagation: function()
						{
							this.cancelBubble = true;
						}
					}
				
					func( e );
					event.returnValue = e.returnValue;
					event.cancelBubble = e.cancelBubble;
				}
				else
				{
					e = {
						currentTarget: node,
						returnValue: true,
						cancelBubble: false,
						preventDefault: function()
						{
							this.returnValue = false;
						},
						stopPropagation: function()
						{
							this.cancelBubble = true;
						}
					}
					func( e );
				}
				
//				if( e.canncelBubble )
//				{
//					event.preventDefault(); 
//					event.stopPropagation(); 
//				}
//				
//				return e.returnValue;
			} );
		}
		else
		{
			alert(3);
			node['on' + name] = func;
		}
	},
	
	///
	///
	///
	removeEventListener: function( node, name, func )
	{
		if( document.all && document.detachEvent )
		{
			node.detachEvent( "on" + name, function()
			{
				var e = {
					currentTarget: node,
					cancelBubble: event.cancelBubble,
					keyVal: event.keyCode,
					clientX: event.clientX,
					clientY: event.clientY,
					screenX: event.screenX,
					screenY: event.screenY,
					pageX: event.x + Window.getScrollLeft,	// ??
					pageY: event.y + Window.getScrollTop,	// ??
					layerX: event.offsetX,
					layerY: event.offsetY,
					which: event.button,
					
					ctrlKey: event.ctrlKey,
					shiftKey: event.shiftKey,
					
					returnValue: true,
					cancelBubble: false,
					preventDefault: function()
					{
						this.returnValue = false;
					},
					stopPropagation: function()
					{
						this.cancelBubble = true;
					}
				}
				
				func( e );
				event.returnValue = e.returnValue;
				event.cancelBubble = e.cancelBubble;
			} );
		}
		else if( node.removeEventListener )
		{
			node.removeEventListener( name, func, false );
		}
		else
		{
			node['on' + name] = undefined;
		}
	},
	
	///
	///
	///
	changeFocus: function( id, event )
	{
		if(event.keyCode == 13)
		{
			$(id).focus();
		}
	},
	
	///
	///
	///
	insertNodeAt: function( c, index, target )
	{
		if( c.childNodes.length <= index )
		{
			c.appendChild( target );
		}
		else
		{
			c.insertBefore( target, c.childNodes[index] );
		}
	},
	
	///
	///
	///
	getInnerText: function( c )
	{
		var val = c.innerText;
		if( val == undefined )
		{
			val = c.textContent;
		}
		return val;
	},
	
	///
	///
	///
	dragElement: function( elem )
	{
		addEventListener( elem, 'mousemove', _dragElement_onMouseMove );
		addEventListener( elem, 'mouseup', _dragElement_onMouseUp );
	},
	_dragElement_onMouseMove: function( e )
	{
		if( e.which != 1 )
			return;
		
		e.currentTarget.style.left += (e.pageX + e.layerX) + 'px';
		e.currentTarget.style.top += (e.pageY + e.layerY) + 'px';
	},
	_dragElement_onMouseUp: function( e )
	{
		removeEventListener( e.currentTarget, 'mousemove', _dragElement_onMouseMove );
		removeEventListener( e.currentTarget, 'mouseup', _dragElement_onMouseUp );
	}
	
}



var Query = {
	_query: null,
	
	///
	/// クエリを取得します。
	///
	get: function( key )
	{
		if( !this._query )
		{
			this._query = parse( location.search );
		}
		return this._query[key];
	},
	
	///
	/// クエリ文字列を解析します
	///
	parse: function( search )
	{
		if( search.charAt( 0 ) == '?' )
		{
			search = search.substr( 1, search.length );
		}
		if( search.length == 0 )
			return {};
		
		var query = {};
		var params = search.split( '&' );
		for( var i in params ){
			var pair = params[i].split( '=' );
			if( pair.length < 2 )
				continue;
			
			pair[1] = decodeURI( pair[1] );
			query[pair[0]] = pair[1];
		}
		
		return query;
	},
	
	///
	/// クエリ文字列へ変換します
	///
	toString: function( query )
	{
		if( query == undefined )
		{
			return location.search.trimStart( '\\?', '\\s' );
		}
		
		var ary = new Array();
		for( var key in query )
		{
			ary.push( String.format( '{0}={1}', key, encodeURI( query[key] ) ) );
		}
		return ary.join( '&' );
	}

}



var Cookie = {
	_cookies: null,
	
	///
	/// クッキーを取得します。
	///
	get: function( name )
	{
		if( !this._cookies )
		{
			this._cookies = this.parse( document.cookie );
		}
		return this._cookies[name];
	},
	
	///
	/// クッキーを設定します。
	///
	set: function( name, value, expires, domain, path, secure )
	{
		var cookieStr = String.format( '{0}={1};', name, value );
		if( expires )
			cookieStr += String.format( ' expires={0};', expires.toGMTString() );
		if( domain )
			cookieStr += String.format( ' domain={0};', domain );
		if( path )
			cookieStr += String.format( ' path={0};', path );
		if( secure )
			cookieStr += ' secure';
//		document.cookies[name] = value;
		if( !this._cookies )
		{
			this._cookies = this.parse( document.cookie );
		}
		this._cookies[name] = value;
		document.cookie = cookieStr;
	},
	
	///
	/// クッキーを削除します。
	///
	remove: function( name )
	{
		this.set( name, '', new Date( 1990, 1, 1 ) );
	},
	
	///
	/// クッキーを解析します
	///
	parse: function( str )
	{
		var cookies = {};
		
		var matches = str.match( /(\w+)=([^;]+)/g );
		for( var key in matches )
		{
			var splited = matches[key].toString().split( '=' );
			if( splited.length != 2 )
				continue;
			
			cookies[splited[0]] = splited[1];
		}
		
		return cookies;
	},
	
	///
	///
	///
	toString: function()
	{
		return document.cookie;
	}
}
//document.cookies = Cookie.parse( document.cookie );

var Window = {
	///
	/// 
	///
	getWidth: function()
	{
		if( Browser.getName() == Browser.InternetExplorer )
		{	// IE
			if( document.documentElement )
			{	// Standard Mode
				return document.documentElement.clientWidth;
			}
			else
			{	// Quirks Mode (*1)
				return document.body.clientWidth;
			}
		}
		else
		{
			return window.innerWidth;
		}
	},
	
	///
	/// 
	///
	getHeight: function()
	{
		if( Browser.getName() == Browser.InternetExplorer )
		{	// IE
			if( document.documentElement )
			{	// Standard Mode
				return document.documentElement.clientHeight;
			}
			else
			{	// Quirks Mode (*1)
				return document.body.clientHeight;
			}
		}
		else
		{
			return window.innerHeight;
		}
	},
	
	///
	/// 
	///
	getScrollLeft: function()
	{
		if( Browser.getName() == Browser.InternetExplorer )
		{	// IE
			if( document.documentElement )
			{	// Standard Mode
				return document.documentElement.scrollLeft;
			}
			else
			{	// Quirks Mode (*1)
				return document.body.scrollLeft;
			}
		}
		else
		{
			return window.pageXOffset;
		}
	},
	
	///
	/// 
	///
	getScrollTop: function()
	{
		if( Browser.getName() == Browser.InternetExplorer )
		{	// IE
			if( document.documentElement )
			{	// Standard Mode
				return document.documentElement.scrollTop;
			}
			else
			{	// Quirks Mode (*1)
				return document.body.scrollTop;
			}
		}
		else
		{
			return window.pageYOffset;
		}
	}
}


var Document = {
	///
	/// 
	///
	getWidth: function()
	{
		if( Browser.getName() == Browser.InternetExplorer )
		{	// IE
			return document.body.scrollWidth;
		}
		else
		{
			return document.width;
		}
	},
	
	///
	/// 
	///
	getHeight: function()
	{
		if( Browser.getName() == Browser.InternetExplorer )
		{	// IE
			return document.body.scrollHeight;
		}
		else
		{
			return document.height;
		}
	}}


var Navigator = {
	_userAgent: navigator.userAgent.toLowerCase(),
	_browser: undefined,
	_browserVer: undefined,
//	_jsVer: undefined,
	_platform: undefined,
	_platformVer: undefined,
	_isGecko: undefined,
	
	major: parseInt(navigator.appVersion),
	minor: parseFloat(navigator.appVersion),
	version: parseFloat(navigator.appVersion),
	
	
	///
	///
	///
	IsGecko: function()
	{
		if( this._isGecko == undefined )
		{
			this.isGecko = (this._userAgent.indexOf('gecko') != -1);
		}
		return this._isGecko;
	},
	
	///
	///
	///
	getBrowser: function()
	{
		if( this._browser == undefined )
		{
			if((this._userAgent.indexOf('mozilla')!=-1) && (this._userAgent.indexOf('spoofer')==-1)

						&& (this._userAgent.indexOf('compatible') == -1) && (this._userAgent.indexOf('opera')==-1)

						&& (this._userAgent.indexOf('webtv')==-1) && (this._userAgent.indexOf('hotjava')==-1))
			{
				this._browser = Browser.NetscapeNavigator;
			}
			else if((this._userAgent.indexOf("msie") != -1) && (this._userAgent.indexOf("opera") == -1))
			{
				this._browser = Browser.InternetExplorer;
			}
			else if(this._userAgent.indexOf("opera") != -1)
			{
				this._browser = Browser.Opera;
			}
			else if(this._userAgent.indexOf("firefox") != -1)
			{
				this._browser = Browser.FireFox;
			}
			else if(this._userAgent.indexOf("safari") != -1)
			{
				this._browser = Browser.Safari;
			}
		}
		return this._browser;
	},
	
	///
	///
	///
	getBrowserVer: function()
	{
		if( this._browserVer == undefined )
		{
			switch( this.getBrowser() )
			{
			case Browser.NetscapeNavigator:
				switch( this.major )
				{
				case 2:
				case 3:
				case 4:
					this._browserVer = this.major;
					break;
				
				case 5:
					this._browserVer = 6;
					break;
				}
				break;
			
			case Browser.InternetExplorer:
				if( this.major < 4 )
				{
					this._browserVer = 3;
				}
				else
				{
					if(this._userAgent.indexOf("msie 4")!=-1)
					{
						this._browserVer = 4;
					}
					else if(this._userAgent.indexOf("msie 5.0")!=-1)
					{
						this._browserVer = 5;
					}
					else if(this._userAgent.indexOf("msie 5.5") !=-1)
					{
						this._browserVer = 5.5;
					}
					else if(this._userAgent.indexOf("msie 6.")!=-1)
					{
						this._browserVer = 6;
					}
					else if(this._userAgent.indexOf("msie 7.")!=-1)
					{
						this._browserVer = 7;
					}
				}
				break;
				
			case Browser.Opera:
				for( var i = 2; i < 20; i++ )
				{
					if(this._userAgent.indexOf("opera " + i) != -1 || this._userAgent.indexOf("opera/" + i) != -1)
					{
						this._browserVer = i;
						break;
					}
				}
				break;
				
			case Browser.FireFox:
				if( this._userAgent.match(/firefox\/([0-9\.]+)/) )
				{
					this._browserVer = parseFloat(RegExp.$1);
				}
				break;
				
			case Browser.Safari:
				break;
			}
		}
		return this._browserVer;
	},
	
//	///
//	///
//	///
//	getJavascriptVer: function()
//	{
//		if( this._jsVer == undefined )
//		{
//		}
//		return this._jsVer;
//	},
	
	///
	///
	///
	getPlatform: function()
	{
		if( this._platform == undefined )
		{
			if( (this._userAgent.indexOf("win")!=-1) || (this._userAgent.indexOf("16bit")!=-1) )
			{
				this._platform = Platform.Windows;
			}
			else if((this._userAgent.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) ||   (this._userAgent.indexOf("ibm-webexplorer")!=-1))
			{
				this._platform = Platform.OS_2;
			}
			else if(this._userAgent.indexOf("mac")!=-1)
			{
				this._platform = Platform.Mac;
			}
			else if(this._userAgent.indexOf("sunos")!=-1)
			{
				this._platform = Platform.SUN;
			}
			else if(this._userAgent.indexOf("irix") !=-1)
			{    // SGI
				this._platform = Platform.IRIX;
			}
			else if(this._userAgent.indexOf("hp-ux")!=-1)
			{
				this._platform = Platform.HP_UX;
			}
			else if(this._userAgent.indexOf("aix") !=-1)
			{      // IBM
				this._platform = Platform.AIX
			}
			else if(this._userAgent.indexOf("inux")!=-1)
			{
				this._platform = Platform.Linux;
			}
			else if((this._userAgent.indexOf("sco")!=-1) || (this._userAgent.indexOf("unix_sv")!=-1))
			{
				this._platform = Platform.SCO;
			}
			else if(this._userAgent.indexOf("unix_system_v")!=-1)
			{
				this._platform = Platform.UnixWare;
			}
			else if(this._userAgent.indexOf("ncr")!=-1)
			{
				this._platform = Platform.MP_RAS;
			}
			else if(this._userAgent.indexOf("reliantunix")!=-1)
			{
				this._platform = Platform.Reliant;
			}
			else if((this._userAgent.indexOf("dec")!=-1) || (this._userAgent.indexOf("osf1")!=-1) || (this._userAgent.indexOf("dec_alpha")!=-1) || (this._userAgent.indexOf("alphaserver")!=-1) || 
                  (this._userAgent.indexOf("ultrix")!=-1) || (this._userAgent.indexOf("alphastation")!=-1))
			{
				this._platform = Platform.DEC;
			}
			else if(this._userAgent.indexOf("sinix")!=-1)
			{
				this._platform = Platform.SINIX;
			}
			else if(this._userAgent.indexOf("freebsd")!=-1)
			{
				this._platform = Platform.FreeBSD;
			}
			else if(this._userAgent.indexOf("bsd")!=-1)
			{
				this._platform = Platform.BSD;
			}
			else if((this._userAgent.indexOf("vax")!=-1) || (this._userAgent.indexOf("openvms")!=-1))
			{
				this._platform = Platform.VMS;
			}
		}
		return this._platform;
	},
	
	///
	///
	///
	getPlatformVer: function()
	{
		if( this._platformVer == undefined )
		{
			switch( this.getPlatform() )
			{
			case Platform.Windows:
				// 注: Opera 3.0 では Win32 環境全てでユーザエージェント文字列に "Windows 95/NT4"
				// が含まれており、Win95 と WinNT の区別が出来ません。
				if((this._userAgent.indexOf("win95")!=-1) || (this._userAgent.indexOf("windows 95")!=-1))
				{
					this._platformVer = 95;
				}
				// 注: Win98 の信頼できる判断法は存在しないようです。次のようだから:
				//      - Nav4.x 以前ではユーザエージェントで "Windows" だけしか得られない。
				//      - Win98 上の Mercury では 32 bit バージョンは "Win98" を返すが、
				//        16 bit バージョンは "Win95" を返す。
				else if((this._userAgent.indexOf("win98")!=-1) || (this._userAgent.indexOf("windows 98")!=-1))
				{
					this._platformVer = 98;
				}
				else if((this._userAgent.indexOf("win 9x 4.90")!=-1))
				{
					this._platformVer = 'ME';
				}
				else if((this._userAgent.indexOf("winnt")!=-1) || (this._userAgent.indexOf("windows nt")!=-1))
				{
					if((this._userAgent.indexOf("windows nt 5.0")!=-1))
					{
						this._platformVer = 2000;
					}
					else if((this._userAgent.indexOf("windows nt 5.1")!=-1))
					{
						this._platformVer = 'XP';
					}
					else if((this._userAgent.indexOf("windows nt 5.2")!=-1))
					{
						this._platformVer = 2003;
					}
					else if((this._userAgent.indexOf("windows nt 6.0")!=-1))
					{
						this._platformVer = 'Vista';
					}
					else
					{
						this._platformVer = 'NT';
					}
				}
				break;
				
			case Platform.Mac:
				if((this._userAgent.indexOf("68k")!=-1) || (this._userAgent.indexOf("68000")!=-1))
				{
					this._platformVer = 68000;
				}
				else if((this._userAgent.indexOf("ppc")!=-1) || (this._userAgent.indexOf("powerpc")!=-1))
				{
					this._platformVer = 'PowerPC';
				}
				break;
			
			case Platform.SUN:
				if(this._userAgent.indexOf("sunos 4")!=-1)
				{
					this._platformVer = 4;
				}
				else if(this._userAgent.indexOf("sunos 5")!=-1)
				{
					this._platformVer = 5;
				}
				else if(this.sun && (this._userAgent.indexOf("i86")!=-1))
				{
					this._platformVer = 'i86';
				}
				break;
				
			case Platform.IRIX:
				if(this._userAgent.indexOf("irix 5") !=-1)
				{
					this._platformVer = 5;
				}
				else if((this._userAgent.indexOf("irix 6") !=-1) || (this._userAgent.indexOf("irix6") !=-1))
				{
					this._platformVer = 6;
				}
				break;
			
			case Platform.HP_UX:
				if(this._userAgent.indexOf("09.")!=-1)
				{
					this._platformVer = 9;
				}
				else if(this._userAgent.indexOf("10.")!=-1)
				{
					this._platformVer = 10;
				}
				break;
				
			case Platform.AIX:
				if(this._userAgent.indexOf("aix 1") !=-1)
				{
					this._platformVer = 1;
				}
				else if(this._userAgent.indexOf("aix 2") !=-1)
				{
					this._platformVer = 2;
				}
				else if(this._userAgent.indexOf("aix 3") !=-1)
				{
					this._platformVer = 3;
				}
				else if(this._userAgent.indexOf("aix 4") !=-1)
				{
					this._platformVer = 4;
				}
				break;
			}

		}
		return this._platformVer;
	}
}

var Browser = {
//	InternetExplorer: 'Internet Explorer',
//	FireFox: 'FireFox',
//	Opera: 'Opera',
//	NetscapeNavigator: 'Netscape Navigator',
//	Safari: 'Safari',
//	Etc:	'etc'
	InternetExplorer: 'Internet Explorer',
	FireFox: 'FireFox',
	Opera: 'Opera',
	NetscapeNavigator: 'Netscape Navigator',
	Safari: 'Safari'
}	


var Platform = {
//	Windows: 'Windows',
//	Mac:	'Mac',
//	Linux:	'Linux',
//	Etc:	'etc'
	Windows: 'Windows',
	OS_2: 'OS/2',
	Mac:	'Mac',
	SUN: 'SUN OS',
	IRIX: 'IRIX',
	HP_UX: 'HP-UX',
	AIX: 'AIX',
	Linux:	'Linux',
	SCO: 'SCO',
	UnixWare: 'UnixWare',
	MP_RAS: 'MP-RAS',
	Reliant: 'Reliant',
	DEC: 'DEC',
	SINIX: 'SINIX',
	FreeBSD: 'FreeBSD',
	BSD: 'BSD',
	VMS: 'VMS'
}



function KeyboardEvent( e )
{
//	var keycode, shift, ctrl;
//	if( e != null )
//	{	// Mozilla(Firefox, NN) and Opera 
//		keycode = e.which;
//		ctrl = (typeof e.modifiers == 'undefined')? e.ctrlKey : e.modifiers & Event.CONTROL_MASK;
//		shift = (typeof e.modifiers == 'undefined')? e.shiftKey : e.modifiers & Event.SHIFT_MASK;
//		
////		// イベントの上位伝播を防止 
////		e.preventDefault(); 
////		e.stopPropagation(); 
//	}
//	else
//	{	// Internet Explorer 
//		keycode = event.keyCode; 
//		ctrl = event.ctrlKey; 
//		shift = event.shiftKey; 
//		
////		// イベントの上位伝播を防止 
////		event.returnValue = false; 
////		event.cancelBubble = true; 
//	}

	// キーコードの文字を取得 
	var keychar = String.fromCharCode(e.keyVal).toUpperCase();
	
	this.keyChar = keychar;
	this.keyVal = e.KeyVal;
	this.shiftKey = e.shiftKey;
	this.ctrlKey = e.ctrlKey;

	// 特殊キーコードの対応については次を参照 
	// 27 Esc 
	// 8 BackSpace 
	// 9 Tab 
	// 32 Space 
	// 45 Insert 
	// 46 Delete 
	// 35 End 
	// 36 Home 
	// 33 PageUp 
	// 34 PageDown 
	// 38 ↑ 
	// 40 ↓ 
	// 37 ← 
	// 39 → 
	// 処理の例 
	// if (keycode == 27) { 
	// alert('Escapeキーが押されました'); 
	// } 
}

var keyboard;
function document_onKeyUpDown( e )
{
//	if( !e ){ e = window.event; }	
	keyboard = new KeyboardEvent( e );
}
Misc.addEventListener( document, 'keydown', document_onKeyUpDown );
Misc.addEventListener( document, 'keyup', document_onKeyUpDown );


function bindCheckLink( groupId, url )
{
	var c = document.getElementById( groupId );
	c.setAttribute( 'url', url );
	
	var anchors = c.getElementsByTagName( 'a' );
	for( var i = 0; i < anchors.length; i++ )
	{
		var anchor = anchors[i];
		
		var val = anchor.getAttribute( 'value' );
		if( val == undefined || val == null )
			continue;
		
		anchor.setAttribute( 'checkLinkGroupId', groupId );
		Misc.addEventListener( anchor, 'click', checkLink_onClick );
		
		if( Navigator.getBrowser() == Browser.InternetExplorer && Navigator.getBrowserVer() == 7 )
		{
			anchor.setAttribute( '_href', anchor.href );
			anchor.href = 'javascript:void(0)';
		}
	}
	
	Misc.addEventListener( document.body, 'click', function( e ) {
		if( keyboard && keyboard.ctrlKey )
			return;
		
		for( var i = 0; i < anchors.length; i++ )
		{
			var anchor = anchors[i];
			checkLink_uncheckLink( anchor );
		}
	} );
}

function checkLink_onClick( e )
{
	var c = e.currentTarget;
	var clickEnabled = true;
	
	var groupId = c.getAttribute( 'checkLinkGroupId' );
	var parent = document.getElementById( groupId );
	
	if( keyboard && keyboard.ctrlKey )
	{	// チェーン
		var checked = c.getAttribute( 'check' );
		if( checked )
		{
			checkLink_uncheckLink( c );
		}
		else
		{
			checkLink_checkLink( c );
		}
		
		clickEnabled = false;
	}
	else
	{	// リンク先へジャンプ
//		c.setAttribute( 'check', 1 );
		checkLink_checkLink( c );
		
		var list = new Array();
		var anchors = parent.getElementsByTagName( 'a' );
		for( var i = 0; i < anchors.length; i++ )
		{
			var anchor = anchors[i];
			
			if( !anchor.getAttribute( 'check' ) )
				continue;
			
			var val = anchor.getAttribute( 'value' );
			list[list.length] = val;
		}
		
		if( list.length <= 1 )
		{
			if( Navigator.getBrowser() == Browser.InternetExplorer && Navigator.getBrowserVer() == 7 )
			{
				location.href = c.getAttribute( '_href' );
			}
			clickEnabled = true;
		}
		else
		{
			var url = parent.getAttribute( 'url' );
			
			var value = list.join( '%3b' );
			if( url.indexOf( '{0}' ) >= 0 )
			{
				location.href = url.replace( '{0}', value );
			}
			else
			{
				location.href = url + value;
			}
			
			clickEnabled = false;
		}
	}
	
	if( !clickEnabled )
	{
//		if( e.preventDefault )
//		{
			e.preventDefault();
			e.stopPropagation();
//		}
//		return false;
	}
}

function checkLink_checkLink( c )
{
	c.setAttribute( 'check', 1 );
	c.style.backgroundColor = '#6090f0';
	c.style.color = '#FFF';
}
function checkLink_uncheckLink( c )
{
	c.setAttribute( 'check', '' );
	c.style.backgroundColor = '';
	c.style.color = '';
}


var Playlist = {
	control: null,
	items: new Array(),
	selectedFullMovieId: null,
	randomPlayEnabled: false,
	_randomPlaylist: new Array(),
	
	init: function( c ){
		this.control = c;
		
		this.scroll = new Scroll( c );
	},
	
	getSelectedFullMovieId: function(){
		return this.selectedFullMovieId;
	},
	
	insertSound: function( info ){
		this.insertRangeSound( new Array( info ) );
	},
	
	insertRangeSound: function( infos ){
		if( !infos || infos.length <= 0 )
			return 0;
		
		// 追加
		for( var i = infos.length - 1; i >= 0; i-- )
		{
			var info = infos[i];
			
			// プレイリストへ追加
			var c = this._findControl( info.fullMovieId );
			if( c )
			{
				Misc.insertNodeAt( this.control, 0, c );
				
				var idx = this._itemIndexOf( info.fullMovieId );
				if( idx >= 0 )
				{
					this.items.removeAt( idx );
					this.items.unshift( info );
				}
			}
			else
			{
				if( this.items.length >= 15 )
				{
					alert( 'リストが一杯です。\nどれか削除して下さい。' );
					return infos.length - (i + 1);
				}
				
				this.items.unshift( info );
				this._randomPlaylist.insert( Math.floor( Math.random() * this._randomPlaylist.length ), info.fullMovieId );
				
				c = this._createItem( info );
				Misc.insertNodeAt( this.control, 0, c );
			}
			
//			// プレイヤーの追加
//			Player.insertFrame( info.fullMovieId );
		}
		
		// 08/11/19 スクロール
		this.scroll.to( this._findControl( infos[0].fullMovieId ) );
		
//		// 余剰除去
//		for( var i = this.items.length - 1; i >= 15; i-- )
//		{
//			this._deleteItem( i );
//		}
		
//		// 再生
//		if( !this.selectedFullMovieId )
//		{
//			this.playNextSound();
//		}

		this._updateCookie();
		return infos.length;
	},
	
	playSound: function( fullMovieId, force ){
		if( !fullMovieId )
		{
			fullMovieId = this.items[0].fullMovieId;
		}
		if( fullMovieId == this.selectedFullMovieId && !force )
			return;
		
		Player.playSound( fullMovieId );
		
		// 08/11/19 スクロール
		this.scroll.to( this._findControl( fullMovieId ) );
		
		var prevFullMovieId = this.selectedFullMovieId;
		if( prevFullMovieId )
		{
			var prevTitleItem = $( 'playlistItemTitle_' + prevFullMovieId );
			if( prevTitleItem )
			{
//				prevTitleItem.style.backgroundColor = "#fff0e5";
				prevTitleItem.className = 'PlayListItem_Header';
				
				prevTitleItem.innerHTML = prevTitleItem.getElementsByTagName( 'marquee' )[0].innerHTML;
			}
		}
		{
			var titleItem = $( 'playlistItemTitle_' + fullMovieId );
//			titleItem.style.backgroundColor = '#ffc9c0';
			titleItem.className = 'PlayListItem_Selected_Header';
			
			var marquee = document.createElement( 'marquee' );
			marquee.scrollAmount = 3;
			marquee.innerHTML = titleItem.innerHTML;
			titleItem.innerHTML = '';
			titleItem.appendChild( marquee );
			
			// Firefox で必要
			if( marquee.init )
			{
//				marquee.scrollDelay = 120;
				marquee.init();
			}
		}
		
		this.selectedFullMovieId = fullMovieId;
	},
	
	playNextSound: function(){
		if( this.items.length == 0 )
			throw new Error( 'プレイリストが空なので、再生できません。' );
		
		if( this.randomPlayEnabled && this.items.length >= 3 )
		{
//			var idx = Math.floor( Math.random() * this.items.length );
//			this.playSound( this.items[idx].fullMovieId );
			var fullMovieId = this._randomPlaylist.shift();
			this._randomPlaylist.add( fullMovieId );
			if( fullMovieId == this.selectedFullMovieId )
			{
				fullMovieId = this._randomPlaylist.shift();
				this._randomPlaylist.add( fullMovieId );
			}
			this.playSound( fullMovieId );
		}
		else
		{
			var idx = this._itemIndexOf( this.selectedFullMovieId );
			if( idx >= 0 )
			{
				if( idx+1 < this.items.length )
				{
					this.playSound( this.items[idx+1].fullMovieId );
				}
				else
				{
					this.playSound( this.items[0].fullMovieId );
				}
			}
			else
			{
				this.playSound( this.items[0].fullMovieId );
			}
		}
	},
	
	contains: function( fullMovieId )
	{
		return this._itemIndexOf( fullMovieId ) >= 0;
	},
	
	clear: function(){
		Cookie.remove( 'playlist' );
		window.close();
	},
	
	deleteSound: function( fullMovieId ){
		var idx = this._itemIndexOf( fullMovieId );
		if( idx < 0 )
			return;
		
		this._deleteItem( idx );
	},
	
	_deleteItem: function( index ){
		if( this.items.length <= index )
			return;
		
		var item = this.items[index];
		this.items.removeAt( index );
		var c = this._findControl( item.fullMovieId );
		this.control.removeChild( c );
		Player.deleteFrame( item.fullMovieId );
		this._updateCookie();
		
		// リストが空ならウィンドウを閉じる
		if( this.items.length == 0 )
		{
			window.close();
			return;
		}
		
		// ランダムプレイリストからも削除
		this._randomPlaylist.remove( item.fullMovieId );
		
		// 削除対象が試聴中のものなら、他のものを試聴状態へ
		if( this.selectedFullMovieId == item.fullMovieId )
		{
			this.selectedFullMovieId = null;
			
			var item2;
			if( index < this.items.length )
			{
				item2 = this.items[index];
			}
			else
			{
				item2 = this.items[0];
			}
			this.playSound( item2.fullMovieId );
		}
	},
	
	_findControl: function( fullMovieId ){
		return $( 'playlistItem_' + fullMovieId );
	},
	
	_itemIndexOf: function( fullMovieId ){
		if( !fullMovieId )
		{
			return -1;
		}
		
		for( var i = 0; i < this.items.length; i++ )
		{
			if( this.items[i].fullMovieId == fullMovieId )
			{
				return i;
			}
		}
		return -1;
	},
	
	_updateCookie: function(){
		var fullMovieIds = new Array();
		for( var i = 0; i < this.items.length; i++ )
		{
			fullMovieIds.add( this.items[i].fullMovieId );
		}
		Cookie.set( 'playlist', fullMovieIds.join( ' ' ), new Date(2050,1,1) );
	},
	
	_createItem: function( info ){
		var item = document.createElement( 'div' );
		item.id = 'playlistItem_' + info.fullMovieId;
		item.innerHTML = String.format( '<div style="margin:0px 0px 2px 0px; background-color:#FFF">\
<div style="border-bottom:solid 3px #e0e0e0" title="{1}">\
<table class="List" style="border:solid 1px #909090; border-width:1px 1px 2px 1px; width:250px; font-size:0.9em">\
<tr><td rowspan="2" style="background-color:#000000; padding:0px; vertical-align:middle; padding:0px 4px">\
	<a style="background-color:#000000; display:block" href="javascript:Playlist.playSound(\'{0}\')">\
		<img src="{5}" alt="{1}" style="width:55px; height:41px" />\
	</a>\
</td>\
<td style="width:100%; padding:0px" onmouseover="this.className=\'HilightItem\'" onmouseout="this.className=undefined" onclick="Playlist.playSound(\'{0}\')">\
	<div style="padding:4px 2px 4px 4px; width:180px; overflow:hidden; white-space:nowrap" class="PlayListItem_Header" id="playlistItemTitle_{0}">\
		<a style="font-weight:bold; text-decoration:none" href="javascript:Playlist.playSound(\'{0}\')" value="{0}">{1}</a>\
	</div>\
	<div style="border-bottom:solid 1px #c0c0c0; margin-bottom:2px"></div>\
</td></tr>\
<tr><td style="text-align:left; vertical-align:bottom; padding:0px"><div style="width:178px; white-space:nowrap; overflow:hidden; padding:4px 2px 4px 6px">\
		{0} - {2}\
		<span style="border:solid 1px #909090; padding:1px 1px 0px 1px; margin-right:3px; background-color:#FFFFFF; font-size:9px">♪</span><b>{4}</b>\
		<a href="javascript:Playlist.deleteSound(\'{0}\')">削</a>\
</div></td></tr>\
</table>\
</div>\
</div>', info.fullMovieId, info.title, info.duration, info.convertedTime, info.playCount, info.thumbnailUrl );
	
		return item;
	}
}
var Player = {
	control: null,
	frameList: new Object(),
	loopEnabled: false,
	
	init: function( c ){
		this.control = c;
	},
	
	getSelectedFrame: function(){
		var fullMovieId = Playlist.getSelectedFullMovieId();
		if( !fullMovieId )
		{
			return null;
		}
		return this.frameList[fullMovieId];
	},
	
	onProgressComplete: function( fullMovieId ){
		this.getSelectedFrame().setAttribute( 'progressCompleted', true );
	},
	
	onPlayComplete: function( fullMovieId ){
		if( this.loopEnabled )
		{
			this.playSound( fullMovieId, true );
		}
		else
		{
			setTimeout(	function(){ Playlist.playNextSound(); }, 500 );
		}
	},
	
	insertFrame: function( fullMovieId ){
		var frm = this.frameList[fullMovieId];
		if( !frm )
		{
			var id = 'iframe_' + fullMovieId;
			frm = document.createElement( 'iframe' );
			frm.id = id;
			frm.src = '/streaming/' + fullMovieId;
			frm.width = 468;
			frm.height = 333;
			frm.scrolling = 'no';
			frm.frameborder = '0';
			frm.style.position = 'absolute';
	//		frm.style.top = '500px';
			this.control.appendChild( frm );
			
			this.frameList[fullMovieId] = frm;
		}
		
		return frm;
	},
	
	playSound: function( fullMovieId, force ){
		var id = 'iframe_' + fullMovieId;
		var frm = this.insertFrame( fullMovieId );
//		if( !frm )
//		{
//			frm = document.createElement( 'iframe' );
//			frm.id = id;
//			frm.src = '/streaming/' + fullMovieId;
//			frm.width = 468;
//			frm.height = 345;
//			frm.scrolling = 'no';
//			frm.frameborder = '0';
//			this.control.appendChild( frm );
//			this.frameList[fullMovieId] = frm;
//		}

		var selectedFrame = this.getSelectedFrame();
		if( selectedFrame && selectedFrame != frm )
		{
////			this.control.insertBefore( frm, currentFrame );
//			this.selectedFrame.style.display = 'none';
//			top.frames[this.selectedFrame.id].stopSound();
//			frm.style.display = '';
			if( selectedFrame.getAttribute( 'progressCompleted' ) )
			{
//				this.control.insertBefore( frm, selectedFrame );
//				window.frames[selectedFrame.id].stopSound();
				selectedFrame.contentWindow.stopSound();
				// style.position を修正すると、 Firefox で iframe の再読み込みが（強制的に）発生してしまい、flash プレイヤーのバッファが無駄になる為、修正
//				selectedFrame.style.position = 'absolute';
				selectedFrame.style.top = '-500px';
			}
			else
			{	// レジューム・一時読み込み停止が一切出来ないので、中途データはいっそのこと破棄
				this.deleteFrame( Playlist.getSelectedFullMovieId() );
			}
		}
		frm.style.top = '0px';
		
		if( (selectedFrame != frm || force) && frm.contentWindow.playSound )
		{
			frm.contentWindow.playSound();
		}
	},
	
	deleteFrame: function( fullMovieId ){
		var frm = this.frameList[fullMovieId];
		if( !frm )
			return;
		
		delete this.frameList[fullMovieId];
		this.control.removeChild( frm );
	}
}


/*
var g_img, g_beginTime;
//g_loadEmptyImage();
function g_loadEmptyImage()
{
//	if( !Cookie.get( 'dlv' ) || Cookie.get( 'dlv' ) == 0 )
	{
		var expires = new Date();
		expires.setTime( expires.getTime() + 1000 * 3600 * 1 );
		Cookie.set( 'dlv', 1, expires, 'anyap.info', '/' );
		
		g_img = new Image();
		Misc.addEventListener( g_img, 'load', g_img_onload );
	//	g_img.onload = g_img_onload;
		g_img.src = 'http://res.anyap.info/nicosound/img/empty.aspx?' + new Date().getTime();
		g_beginTime = new Date();
	}
}
function g_img_onload()
{
	if( !g_beginTime )
	{
		g_beginTime = new Date();
	}
	var duration = (new Date().getTime() - g_beginTime.getTime()) / 1000;
	var size = g_img.width * g_img.height * 4;
	if( !size )
	{
		size = 40 * 1024;
	}
	var expires = new Date();
	expires.setTime( expires.getTime() + 1000 * 3600 * 1 );
	Cookie.remove( 'dlv' );
	Cookie.set( 'dlv', (duration === 0)? 1024*1024: size / duration, expires, 'anyap.info', '/' );
	g_img = void 0;
}
function _addYear( date, year )
{
	var newDate = new Date();
	newDate.setTime( date.getTime() );
	newDate.setYear( date.getYear() + year );
	return newDate;
}
/*/
if( !Cookie.get( 'dlv' ) || Cookie.get( 'dlv' ) == 0 )
{
//	g_initDLVelocimeter();
}
function g_initDLVelocimeter()
{
	var swfUrl = 'http://res.anyap.info/nicosound/swf/DLVelocimeter2.swf';
	var objectUrl = 'http://res.anyap.info/nicosound/js/empty.aspx?' + new Date().getTime();
	var callback = 'g_dlVelocimeter_complete';
	var flashVars = 'objectUrl=' + objectUrl + '&callback=' + callback;
	
	document.write( '\
<object id="externalDLVelocimeter" width="1" height="1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\
	<param name="movie" value="' + swfUrl + '" />\
	<param name="allowScriptAccess" value="always" />\
	<param name="quality" value="high" />\
	<param name="FlashVars" value="' + flashVars + '" />\
	<embed name="externalDLVelocimeter" src="' + swfUrl + '" width="1" height="1" FlashVars="' + flashVars + '" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
</object>' );
}
function g_dlVelocimeter_complete( size, duration )
{
	var expires = new Date();
	expires.setTime( expires.getTime() + 1000 * 3600 * 1 );
	
	var dlv = (duration === 0)? 1024*1024: size / duration;
	var strPrevDlv = Cookie.get( 'dlv' );
	if( strPrevDlv )
	{
		dlv = (dlv + Number(strPrevDlv)) / 2;
	}
	Cookie.remove( 'dlv' );
	Cookie.set( 'dlv', dlv, expires, 'anyap.info', '/' );
	
//	alert( size + '/' + duration + '=' + size/duration );
}
//*/

function changeFocus( id, event )
{
	if(event.keyCode == 13)
	{
		document.getElementById(id).focus();
	}
}

function confirmDelete( idx )
{
	// 選択レコードの削除確認ダイアログ
	return confirm( '選択されたレコードを削除します' );
}

function createPlayer2( url, args )
{
	if( !args.volume )
		args.volume = 100;
	if( !args.balance )
		args.balance = 0;
	if( !args.rate )
		args.rate = 1;
	if( navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0 )
	{
		if( args.width )
			args.width += 2;
	}
	
	var html = '';
	html += '\
<object id="' + args.id + '" width="' + args.width + '" height="' + args.height + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\
	<param name="movie" value="/swf/AudioPlayer.swf?s=1&' + Math.floor(new Date().getTime()/300000) + '" />\
	<param name="FlashVars" value="' + (url? 'flv=' + url + '&': '') + 'duration=' + args.duration + '&autoPlay=' + args.autoStart + '&volume=' + args.volume + '&autoRewind=false&repeat=' + args.repeat + '&timeout=30000">\
	<param name="quality" value="high" />\
	<embed name="' + args.id + '" src="/swf/AudioPlayer.swf?s=1&' + Math.floor(new Date().getTime()/300000) + '" width="' + args.width + '" height="' + args.height + '" FlashVars="flv=' + url + '&duration=' + args.duration + '&autoPlay=' + args.autoStart + '&volume=' + args.volume + '&autoRewind=true&repeat=' + args.repeat + '&timeout=30000" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
</object>';
//	html += '<a href="' + url + '">hoge</a>';
	
	document.write( html );
}

function createSwfObject( url, args )
{
	if( navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0 )
	{
		if( args.width )
		{
			args.width += 2;
		}
	}
	
	var html = '';
	html += '\
<object id="' + args.id + '" width="' + args.width + '" height="' + args.height + '" style="' + args.style + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\
	<param name="movie" value="' + url + '?' + Math.floor(new Date().getTime()/300000) + '" />\
	<param name="quality" value="high" />\
	<param name="FlashVars" value="userAgent=' + navigator.userAgent + '" />\
	<embed name="' + args.id + '" src="' + url + '?' + Math.floor(new Date().getTime()/300000) + '" width="' + args.width + '" height="' + args.height + '" FlashVars="userAgent=' + Navigator.getBrowser() + '" quality="high" style="' + args.style + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
</object>';
	
	document.write( html );
}

function openPlayerWindow()
{
	var w = window.open( '/streaming.aspx', 'wStreamingPlayer', 'width=740,height=328,location=yes,resizable=yes,status=yes' );
	if( w )
	{
		w.focus();
	}
	
	return w;
}
function playStreaming( info )
{
	try
	{
		var clientId = 'externalAPClient';
		var client = window[clientId]? window[clientId]: document[clientId];
		if( !client )
			return;

		_insertSound_status = null;
		client.insertSounds( new Array( info ) );
		var intervalId = setInterval( function(){
			if( !_insertSound_status )
				return;
			
			clearInterval( intervalId );
			switch( _insertSound_status )
			{
			case 'status':
				if( client )
				{
//					if( status == 'status' && info && !client.selectedFullMovieId )
//					{
//						client.playSound( info.fullMovieId );
//					}
	
					if( Navigator.getBrowser() != Browser.InternetExplorer )
					{
						window.blur();
					}
					client.focusWindow();
				}
				break;
				
			case 'error':
				var w = openPlayerWindow();
				window.wStreamingPlayer = w;
				break;
			}
		}, 100 );
		
//		var w = window.wStreamingPlayer;
//		if( !w || w.closed )
//		{
//			w = window.open( '/streaming.aspx', 'wStreamingPlayer', 'width=740,height=318,location=yes,resizable=yes,status=yes' );
//			window.wStreamingPlayer = w;
//		}
//		else
//		{
//			if( info )
//			{
//				w.Playlist.insertSound( info );
//			}
//		}
//		w.focus();
//		
//		return w;
	}
	catch( ex )
	{
		alert( ex.message );
	}
}
var _insertSound_status;
function insertSounds_onStatus( status, infos )
{
//alert( status );
//	switch( status )
//	{
//	case 'status':
//		var client = $('externalAPClient');
//		if( client )
//		{
//			client.focusWindow();
//		}
//		break;
//		
//	case 'error':
//		var w = window.open( '/streaming.aspx', 'wStreamingPlayer', 'width=740,height=318,location=yes,resizable=yes,status=yes' );
//		window.wStreamingPlayer = w;
//		
//		w.focus();
//		break;
//	}
	_insertSound_status = status;
}

function transferUrl( url )
{
	location.href = url;
}



var Scroll = function( cBox ){
	this._scrollBox = cBox;
	this._intervalId = null;
	this._tickCount = 0;
	this._targetScrollTop = 0;
//	this._maxScrollTop = 0;
	this._prevDistance = 0;
	
	this.scrollTime = 500;
	this.interval = 24;
	
//this._logs = new Array();
	this.to = function( c, scrollTime )
	{
		// 初期化
		if( scrollTime )
		{
			this.scrollTime = scrollTime;
		}
		clearInterval( this._intervalId );
		
//		alert( this._scrollBox.scrollTop + ', ' + this._scrollBox.offsetHeight );
//		this._maxScrollTop = this._scrollBox.scrollHeight - this._scrollBox.offsetHeight + Number(this._scrollBox.style.borderTopWidth) + Number(this._scrollBox.style.borderBottomWidth);
//		if( Navigator.getBrowser() == Browser.InternetExplorer )
//		{
//			this._targetScrollTop = c? c.offsetTop: 0;
//		}
//		else
//		{
//			this._targetScrollTop = c? c.offsetTop - this._scrollBox.offsetTop: 0;
//		}
//		this._targetScrollTop = Math.min( this._targetScrollTop, this._maxScrollTop );
		var cOffsetTop;
		if( Navigator.getBrowser() == Browser.InternetExplorer )
		{
			cOffsetTop = c? c.offsetTop: 0;
		}
		else
		{
			cOffsetTop = c? c.offsetTop - this._scrollBox.offsetTop: 0;
		}
		var cOffsetHeight = (Navigator.getBrowser() == Browser.InternetExplorer && Navigator.getBrowserVer() <= 6)? c.offsetHeight/2: c.offsetHeight;
		var isOver = cOffsetTop < this._scrollBox.scrollTop;
		var isUnder = this._scrollBox.scrollTop + this._scrollBox.offsetHeight < cOffsetTop + cOffsetHeight;
//		alert( String.format( "over:{0}, under:{1}", isOver, isUnder ) );
		if( isOver && !isUnder )
		{
//			var maxScrollTop = this._scrollBox.scrollHeight - this._scrollBox.offsetHeight + Number(this._scrollBox.style.borderTopWidth) + Number(this._scrollBox.style.borderBottomWidth);
//			this._targetScrollTop = Math.min( this._targetScrollTop, maxScrollTop );
			this._targetScrollTop = cOffsetTop;
		}
		else if( !isOver && isUnder )
		{
			this._targetScrollTop = cOffsetTop + cOffsetHeight - this._scrollBox.offsetHeight;
		}
		else
		{
			return;
		}
		
		
		// スクロール開始
//this._logs.clear();
		this._prevDistance = 0;
		this._tickCount = 0;
		var thisObj = this;
		this._intervalId = setInterval( function(){ thisObj._onTick(); }, this.interval );
		this._onTick();
	}
	
	this._onTick = function()
	{
		var dist = this._targetScrollTop - this._scrollBox.scrollTop;
		var velocity = 2 * dist * this.interval / ( this.scrollTime - this.interval * this._tickCount );
		velocity = (velocity > 0)? Math.ceil( velocity ): Math.floor( velocity );
//this._logs.add( String.format( "tickCount:{0}, velocity:{1}, distance:{2}", this._tickCount, velocity, dist ) );
		
		if( Math.abs( dist ) <= Math.abs( velocity ) )
		{
			this._endTick();
			return;
		}
		if( this._prevDistance == dist )
		{
			this._endTick();
			return;
		}
		
		var scrollTop = this._scrollBox.scrollTop + velocity;
		this._scrollBox.scrollTop = scrollTop;
		
		this._prevDistance = dist;
		this._tickCount++;
		if( this._tickCount * this.interval >= this.scrollTime )
		{
			this._endTick();
		}
	}
	
	this._endTick = function()
	{
		clearInterval( this._intervalId );
		this._scrollBox.scrollTop = this._targetScrollTop;

//$('StreamingPlayer').innerHTML = this._logs.join( '<br>' );
	}
}
