//
// F3 Lib
// written by Masashi Satoh / Forum3 TOKYO
// www.forum3.com
//

//
// time bomb 'NEW' sign
//

function tnew( me, limit ) {
	var dt = new Date();
	if ( Date.parse( limit ) < dt.getTime() ) {
		me.style.display = 'none';
	}
	return false;
}

//
// anti spam email link
//

function mailto( a1, a2, opt ) {
	var ma = a1 + '@' + a2;
	var mahref = '<a class="captionlink" href="mailto:' + ma + opt + '">' + ma + '</a>';
	document.write( mahref );
}

//
// std cross function
//

function getobj( layName ) {
	if ( document.all ) {
		return document.all( layName );
	} else if ( document.layers ) {
		return document.layers[ layName ];
	} else {
		return document.getElementById( layName );
	}
}

function focus_by_id( layName ) {
	var obj = getobj( layName );
	obj.focus();
}

function vibration( layName, interval ) {
	if ( document.all ) {
		document.all( layName ).style.top = interval;
		document.all( layName ).style.left = interval;
	} else if ( document.layers ) {
		document.layers[ layName ].top = interval;
		document.layers[ layName ].left = interval;
	} else if ( obj = document.getElementById( layName ) ) {
		obj.style.top = interval;
		obj.style.left = interval;
	}
}

function getBGCOLOR( layName ) {
	if ( document.all ) {
		return document.all( layName ).style.backgroundColor;
	} else if ( document.layers ) {
		return document.layers[ layName ].bgColor;
	} else if ( obj = document.getElementById( layName ) ) {
		return obj.style.backgroundColor;
	}
}

function setBGCOLOR( layName, value ) {
	if ( document.all ) {
		document.all( layName ).style.backgroundColor = value;
	} else if ( document.layers ) {
		document.layers[ layName ].bgColor = value;
	} else if ( obj = document.getElementById( layName ) ) {
		obj.style.backgroundColor = value;
	}
}

function getVISIBLE( layName ) {
	if ( document.all ) {
		if( document.all( layName ).style.visibility == '' ) return 'inherit';
		return document.all( layName ).style.visibility;
	} else if ( document.layers ) {
		if ( document.layers[ layName ].visibility == 'show' ) return 'visible';
		if ( document.layers[ layName ].visibility == 'hide' ) return 'hidden';
		if ( document.layers[ layName ].visibility == 'inherit' ) return 'inherit';
	} else if ( obj = document.getElementById( layName ) ) {
		return obj.style.visibility;
	}
	return '';
}

function setVISIBLE( layName, value ) {
	if ( document.all ) {
		document.all( layName ).style.visibility = value;
	} else if ( document.layers ) {
		document.layers[ layName ].visibility = value;
	} else if ( obj = document.getElementById( layName ) ) {
		obj.style.visibility = value;
	};
}

//=== function toggleblock =============================

function toggleblock( id, y ) {
	var o = getobj( id );
	if ( o.style.display == 'block' ) {
		o.style.display = 'none';
	} else {
		o.style.display = 'block';
		if ( y ) {
			scrollBy( 0, y );
		}
	}
}

//=== function openSubWindow ===========================

function openSubWindow( url, id, w, h ) {

	var cfg = 'width=' + w + ',height=' + h;
	if ( id == 'photo' ) {
		cfg += ',scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0';
	} else {
		cfg += ',scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0';
	}
	wh = window.open( url,id,cfg );
	wh.focus();
}

function opencat( a ) {
	if ( a.href.substr( a.href.length - 1, 1 ) != '#' ) {
		openSubWindow( a.href + '?qd=1', 'catalogue', 584, 620 );
	}
}

//=== class post arguments =============================

function postdata( poststr ) {
	postdata.param = new Array();

	postdata.string = poststr.substring( 1 );
	postdata.string = postdata.string.split( '&' );
	for ( var i = 0; i != postdata.string.length; i++ ) {
		postdata.param[ postdata.string[ i ].split( '=' )[ 0 ] ] = escape( unescape( postdata.string[ i ].split( '=' )[ 1 ] ) );
	}

	function escape( str ) {
		str = str.replace( /\&/g, '&amp;' );
		str = str.replace( /</g, '&lt;' ); 
		str = str.replace( />/g, '&gt;' ); 
		str = str.replace( /\"/g, '&quot;' );
		str = str.replace( /\'/g, '&#39;' );
		return str;
	}
}

//=== function Cookie ==================================
//=== updated 2006.08 ========

function cookies( instance, masterkey, expires, path ) {
	this.instance = instance;
	this.masterkey = masterkey;
	this.expires = expires;
	this.path = path;			// 2007.07
	this.domain = '';
	this.datalist = new Array();

	function receive() {
		var raw, elm, c, d, e;
		var da;
		delete this.datalist;
		this.datalist = new Array();
		raw = ' ' + document.cookie + ';';
		c = d = 0;
		len = raw.length;
		while ( c < len ) {
			d = raw.indexOf( ';', c );
			elm = raw.substring( c + 1, d );
			e = elm.indexOf( '=' );
			if ( unescape( elm.substring( 0, e ) ) == this.masterkey ) {
				elm = elm.substring( e + 1, d - c - 1 );
				da = elm.split( "&" );
				for ( c in da ) {
					elm = da[ c ].split( ":" );
					this.datalist[ unescape( elm[ 0 ] ) ] = unescape( elm[ 1 ] );
				}
				return;
			}
			c = d + 1;
		}
	}

	function get( key ) {
		if ( this.datalist[ key ] == null ) {
			return '';
		} else {
			return this.datalist[ key ];
		}
	}

	function send( key, val ) {
		var c;
		var senddata = '';
		if ( arguments.length == 2 ) {
			this.datalist[ key ] = val;
		}
		for ( c in this.datalist ) {
			if ( this.datalist[ c ] ) {
				senddata += '&' + escape( c ) + ':' + escape( this.datalist[ c ] );
			}
		}
		senddata = this.masterkey + '=' + senddata.substr( 1, senddata.length - 1 ) + ';';
		if ( this.path != '' ) {
			senddata += 'path=' + this.path + ';';
		}
		if ( this.domain != '' ) {
			senddata += 'domain=' + this.domain + ';';
		}
		if ( this.expires > 0 ) {
			var now = new Date;
			var exp = new Date( now.getTime() + ( 1000 * 60 * 60 * 24 * this.expires ) );
			senddata += 'expires=' + exp.toGMTString();
		}
		document.cookie = senddata;
	}

	function set( key, val ) {
		this.datalist[ key ] = val;
	}

	function clear() {
		delete this.datalist;
		this.datalist = new Array();
	}

	cookies.prototype.receive = receive;
	cookies.prototype.get = get;
	cookies.prototype.send = send;
	cookies.prototype.set = set;
	cookies.prototype.clear = clear;
	return this;
}

//=== class folding menu ====================================

function foldmenu( name, path, pn, po, mn, mo ) {
	this.instancename = name;
	this.staticon = new Array();
	this.dispstat = new Array();
	this.category = new Array();
	this.btnid = new Array();
	this.catid = new Array();
	this.menuobj = null;
	this.iconpath = path;
	this.iconpn = pn;
	this.iconpo = po;
	this.iconmn = mn;
	this.iconmo = mo;
	this.cookie = null;
	this.key = '';

	function setcategory() {

		var c, catid, btnid;
		catid = arguments[ 0 ];
		btnid = arguments[ 1 ];

		this.btnid[ catid ] = btnid;
		this.catid[ btnid ] = catid;
		this.dispstat[ btnid ] = true;
		this.staticon[ btnid ] = new menu();
		this.staticon[ btnid ].preloadimg( this.iconpath, this.iconmn, this.iconmo, this.iconmn );
			this.staticon[ btnid ].buttonsetup( btnid );

		for ( c = 2; c < arguments.length; c++ ) {
			this.category[ arguments[ c ] ] = catid;
		}
	}

	function flash() {
		var tmp = new Array();
		if ( this.cookie != null ) {
			tmp = this.cookie.get( this.key ).split( "+" );
			for ( c in tmp ) {
				if ( tmp[ c ] != '' ) { this.dispstat[ tmp[ c ] ] = false; }
			}
		}
		var c;
		for ( c in this.dispstat ) {
			if ( this.dispstat[ c ] == false ) {
				this.close( this.catid[ c ] );
			}
		}
	}

	function over( btnid ) {
		this.staticon[ btnid ].mouseover( btnid );
	}

	function out( btnid ) {
		this.staticon[ btnid ].mouseout( btnid );
	}

	function setmenuobj( obj ) {
		this.menuobj = obj;
	}

	function setcookieobj( key, obj ) {
		this.key = key;
		this.cookie = obj;
	}

	function open( catid ) {
		this.staticon[ this.btnid[ catid ] ].preloadimg( this.iconpath, this.iconmn, this.iconmo, this.iconmn );
		this.staticon[ this.btnid[ catid ] ].mouseout( this.btnid[ catid ] );
		var obj = getobj( catid );
		obj.style.display = 'block';
		if ( this.cookie != null ) {
			this.dispstat[ this.btnid[ catid ] ] = true;
			var c;
			var d = '';
			for ( c in this.dispstat ) {
				if ( c != '' &&  this.dispstat[ c ] == false ) { d += '+' + c; }
			}
			this.cookie.send( this.key, d.substr( 1, d.length - 1 ) );
		}
	}

	function close( catid ) {
		this.staticon[ this.btnid[ catid ] ].preloadimg( this.iconpath, this.iconpn, this.iconpo, this.iconpn );
		this.staticon[ this.btnid[ catid ] ].mouseout( this.btnid[ catid ] );
		var obj = getobj( catid );
		obj.style.display = 'none';
		if ( this.category[ this.menuobj.getselected() ] == catid ) {
			setTimeout( this.instancename + ".open( '" + catid + "' );", 360 );
		} else {
			if ( this.cookie != null ) {
				this.dispstat[ this.btnid[ catid ] ] = false;
				var c;
				var d = '';
				for ( c in this.dispstat ) {
					if ( c != '' && this.dispstat[ c ] == false ) { d += '+' + c; }
				}
				this.cookie.send( this.key, d.substr( 1, d.length - 1 ) );
			}
		}
	}

	function select( catid ) {
		var c, obj, stat;
		this.menuobj.mouseselected( catid );
		if ( this.category[ catid ] != null ) {
			this.open( catid );
		}
	}

	function toggle( catid ) {
		var c, obj, stat, tf;
		obj = getobj( catid );
		stat = obj.style.display;
		if ( stat == 'none' ) {
			this.open( catid );
		} else {
			this.close( catid );
		}
	}

	foldmenu.prototype.flash = flash;
	foldmenu.prototype.toggle = toggle;
	foldmenu.prototype.open = open;
	foldmenu.prototype.close = close;
	foldmenu.prototype.setcategory = setcategory;
	foldmenu.prototype.setmenuobj = setmenuobj;
	foldmenu.prototype.setcookieobj = setcookieobj;
	foldmenu.prototype.select = select;
	foldmenu.prototype.mouseover = over;
	foldmenu.prototype.mouseout = out;
	return this;

}

//=== class menu ====================================
// get name value of child node

function cname( self ) {
	var o = self.childNodes;
	var n;
	for ( n = 0; n < o.length; n++ ) {	// don't use for in loop ; netscape 7
		if ( o[ n ].name ) {
			return o[ n ].name;
		}
	}
}

// search sibling node sub

function search_sib( root, tag ) {
	var o = root.childNodes;
	var r;
	var n;
	for ( n = 0; n < o.length; n++ ) {
		if ( o[ n ].nodeName == tag ) {
			return o[ n ];
		} else {
			r = search_sib( o[ n ], tag );
			if ( r ) {
				return r;
			}
		}
	}
	return false;
}

// search sibling IMG name

function sibimg( self, n ) {
	var o = self;
	var i;
	for ( i = 0; i < n; i++ ) { o = o.parentNode; }
	return search_sib( o, 'IMG' ).name;
}

// search sibling A href

function sibhref( self, n ) {
	var o = self;
	var i;
	for ( i = 0; i < n; i++ ) { o = o.parentNode; }
	return search_sib( o, 'A' ).href;
}

//=== class menu ====================================

function button( btnid ) {
	this.over = false;
	this.btnid = btnid;
	return this;
}

function menu() {
	this.selected_button = '';
	this.loaded = false;
	this.release_sel = false;
	this.cookiekey = '';
	this.action = '';

	function preload( path, base_image, over_image, selected_image ) {
		this.base_img = path + base_image;
		this.over_img = path + over_image;
		this.selected_img = path + selected_image;
		if ( document.images ) {
			c1 = new Image(); c2 = new Image(); c3 = new Image();
			c1.src = this.base_img;
			c2.src = this.over_img;
			c3.src = this.selected_img;
			this.loaded = true;
		}
	}

	function buttonsetup() {
		for ( c = 0; c < arguments.length; c++ ) {
			this[ arguments[ c ] ] = new button( arguments[ c ] );
		}
	}

	function btnsetuporder( name, number ) {
		for ( c = 1; c <= number; c++ ) {
			nstr = '0' + c;
			nstr = name + nstr.substr( nstr.length - 2, 2 );
			this[ nstr ] = new button( nstr );
		}
	}

	function over( btnid ) {
		if ( this.loaded ) {
			document[ btnid ].src = this.over_img;
		}
		this[ btnid ].over = true;
	}

	function out( btnid ) {
		this[ btnid ].over = false;
		if ( ( this.selected_button == btnid ) && ( !this.release_sel ) ) {
			if ( this.loaded ) {
				document[ btnid ].src = this.selected_img;
			}
		} else {
			if ( this.loaded ) {
				document[ btnid ].src = this.base_img;
			}
		}
	}

	function selected( btnid ) {
		if ( this.selected_button != '' ) {
			if ( this.loaded ) {
				document[ this.selected_button ].src = this.base_img;
			}
		}
		if ( this.loaded ) {
			document[ btnid ].src = this.selected_img;
		}
		this.selected_button = btnid;
		eval( this.action );
	}

	function getselected() {
		return this.selected_button;
	}

	menu.prototype.preloadimg = preload;
	menu.prototype.buttonsetup = buttonsetup;
	menu.prototype.btnsetuporder = btnsetuporder;
	menu.prototype.mouseover = over;
	menu.prototype.mouseout = out;
	menu.prototype.mouseselected = selected;
	menu.prototype.getselected = getselected;
	return this;
}

//=== class select images ==============================

function selectimages( image_id ) {
	this.image_id = image_id;
	this.instance = image_id;
	this.current_img = 0;
	this.loaded = false;
	this.images = new Array();

	function preload() {	// arg[ 0 ] : path; arg[ 1.. ] : image;
		this.loaded = false;
		var path = arguments[ 0 ];
		var lim = arguments.length;
		var c;
		for ( c = 1; c < lim; c++ ) {
			this.images[ c - 1 ] = path + arguments[ c ];
			if ( document.images ) {
				img = new Image();
				img.src = this.images[ c - 1 ];
			}
		}
		this.loaded = true;
	}

	function show( image_no ) {
		if ( !document[ this.image_id ] ) {
			return false;
		}
		if ( this.loaded ) {
			this.current_img = parseInt( image_no, 10 );
			document[ this.image_id ].src = this.images[ this.current_img ];
		}
	}

	function hide() {
		if ( !document[ this.image_id ] ) {
			return false;
		}
		if ( this.loaded ) {
			document[ this.image_id ].src = this.images[ 0 ];
		}
	}

	selectimages.prototype.preload = preload;
	selectimages.prototype.show = show;
	selectimages.prototype.hide = hide;
	return this;
}

//=== class slide show ==============================

function slideshow( instancename ) {
	this.instance = instancename;
	this.image_id = '';
	this.current_img = 0;
	this.interval = 3;
	this.loaded = false;
	this.flash_flg = false;
	this.slide_img = new Array();
	this.null_image = '';

	function preload() {	// arg[ 0 ] : path; arg[ 1.. ] : image;
		this.loaded = false;
		this.path = arguments[ 0 ];
		ini = 1;
		lim = arguments.length;
		if ( this.slide_img.length > 0 ) {
			ini = this.slide_img.length + 1;
			lim = lim + ini - 1;
		}
		for ( c = ini; c < lim; c++ ) {
			this.slide_img[ c - 1 ] = this.path + arguments[ c - ini + 1 ];
			if ( document.images ) {
				img = new Image();
				img.src = this.slide_img[ c - 1 ];
			}
		}
		this.loaded = true;
	}

	function preloadnull() {
		this.null_image = arguments[ 0 ] + arguments[ 1 ];
		if ( document.images ) {
			img = new Image();
			img.src = this.null_image;
		}
	}

	function start( image_name ) {
		if ( this.image_id == '' ) { this.image_id = image_name }
		if ( !document[ this.image_id ] ) {
			window.setTimeout( this.instance + '.start()', 100 );
			return false;
		}
		if ( this.loaded && !this.flash_flg ) {
			document[ this.image_id ].src = this.slide_img[ this.current_img ];
			this.current_img++;
			if ( this.slide_img.length == this.current_img ) {
				this.current_img = 0;
			};
		}
		window.setTimeout( this.instance + '.start()', 1000 * this.interval );
	}

	function flash() {
		if ( this.flash_flg ) {
			this.flash_flg = false;
			if ( document.images ) {
				document[ this.image_id ].src = this.slide_img[ this.current_img ];
			}
		} else {
			this.flash_flg = true;
			if ( document.images ) {
				document[ this.image_id ].src = this.null_image;
				window.setTimeout( this.instance + '.flash()', 123 );
			}
		}
	}

	slideshow.prototype.preloadimg = preload;
	slideshow.prototype.preloadnull = preloadnull;
	slideshow.prototype.start = start;
	slideshow.prototype.flash = flash;
	return this;
}

//===================================================

