(function(){

	//scrollTo
	$(function(){
		//scrollTo
		$("a:not(.js-positive a)").filter(function(){
			var attr = $(this).attr('href');
			if( typeof attr === 'string' ){
				return attr.match(/^#[a-zH-Z]/);
			}
			return false;
		}).click(function(){
			var target;
			target = $( $(this).attr('href') );
			if (target.length == 0) return;
			$('html,body').animate({scrollTop: $(target).offset().top }, 450, "easeOutQuart");
			return false;
		});
	});


	// topicpath
	$(function(){
		/* Japanese : 4byte */
		/* English  : 2byte */
		var maxbyte  = 36;
		$('#topicpath ul.group').addClass('steadfast');
		$('#topicpath li a,#topicpath li span').each(function(){
			var count    = 0,
				rtext    = '',
				text     = '';

			text = $(this).text();
			for (var i=0,l=text.length; l>i; i++) {
				var t = text.charAt(i);
				n = escape(t);
				if(n.length < 4){
					count++;
				}else{
					count+=2;
				}
				if(count<maxbyte){
					rtext += t;
				}else{
					rtext += "…";
					break;
				}
			}
			$(this).attr('title',text);
			$(this).html(rtext);
		});		
	});


	// lv4 navigation
	$(function(){
		$('table.content-navi a').each(function(){
			var href = this.getAttribute('href');
			$(this.parentNode).hover(function(){
				$(this).addClass('hover');
			},
			function(){
				$(this).removeClass('hover');
			});
			$(this.parentNode).bind('click',function(){
				window.location = href;
			});
		});
	});

	// ie6 check
	function ie6() {
		if(this.ie6 !== undefined) return this.ie6;
		if(!jQuery.support.opacity){
			if(!jQuery.support.style){
				if (typeof document.documentElement.style.maxHeight == "undefined") {
					this.ie6 = true;
					return true;
				}
			}
		}
		this.ie6 = false;
		return false;
	}



	/* popup window */
	$(function(){
		/* example
			classname : {
				'name': 'xxxx',
				'width': pixels,
				'height': pixels,
				'toolbar': [=yes|no]|[=1|0],
				'location': [=yes|no]|[=1|0],
				'directories': [=yes|no]|[=1|0],
				'status': [=yes|no]|[=1|0],
				'scrollbars': [=yes|no]|[=1|0],
				'resizable': [=yes|no]|[=1|0],
				'titlebar': [=yes|no]|[=1|0],
				'fullscreen': [=yes|no]|[=1|0],
				'left': pixels,
				'top': pixels
			}
		*/
		var windowOpenObject = {
			win_faq : {
				'name': 'faq',
				'width': '650',
				'height': '500',
				'location': '1',
				'status': '1',
				'scrollbars': '1',
				'resizable': '1'
			},
			win_webcatalog_f : {
				'name'       : 'facture',
				'width'      : '1024',
				'height'     : '768',
				'toolbar'    : '0',
				'location'   : '0',
				'status'     : '1',
				'menubar'    : '0',
				'scrollbars' : '0',
				'resizable'  : '1'
			},
			win_webcatalog_s : {
				'name'       : 'stationery',
				'width'      : '1024',
				'height'     : '740',
				'toolbar'    : '0',
				'location'   : '0',
				'status'     : '1',
				'menubar'    : '0',
				'scrollbars' : '0',
				'resizable'  : '1'
			}
		},
		$cls,
		param;

		for( var cls in windowOpenObject ){
			(function(cls){
				$cls  = $("."+cls);
				$cls.bind('click',(function(){
					param = windowOpenObject[cls];
					var link,
						name,
						opt;
					name  = param.name;
					link = this.getAttribute('href');
					opt = (
						(param.width       ? 'width=' + param.width + ',':'') + 
						(param.height      ? 'height=' + param.height + ',':'') + 
						(param.toolbar     ? 'toolbar=' + param.toolbar + ',':'') + 
						(param.location    ? 'location=' + param.location + ',':'') + 
						(param.directories ? 'directories=' + param.directories + ',':'') + 
						(param.status      ? 'status=' + param.status + ',':'') + 
						(param.menubar     ? 'menubar=' + param.menubar + ',':'') + 
						(param.scrollbars  ? 'scrollbars=' + param.scrollbars + ',':'') + 
						(param.resizable   ? 'resizable=' + param.resizable + ',':'') + 
						(param.titlebar    ? 'titlebar=' + param.titlebar + ',':'') + 
						(param.fullscreen  ? 'fullscreen=' + param.fullscreen + ',':'') + 
						(param.left        ? 'left=' + param.left + ',':'') + 
						(param.top         ? 'top=' + param.top :'')
					);
					window.open(link, name, opt).focus();
					return false;
				}));
			})(cls);
		}
	});
})();

// ImageLoader
function ImageLoader ( target, timeout, fnSuccess, fnTimeout ){
	var _arrObjPath    = [],
		_arrPathLength = 0,
		_arrPathLoader = [],
		_arrPath       = [],
		_cnt           = 0,
		timeid         = 0,
		updatekey      = '';

	if(typeof fnSuccess !== 'function') return false;
	if(typeof fnTimeout === 'function' && !isNaN(timeout)) timeid = setTimeout(_timeout,timeout);
	// object -> array
	function object_change_array( t , a ){
		for( var i in t ) {
			if( typeof t[i] == 'object' ) {
				a.concat(object_change_array( t[i] , a ));
			} else {
				a.push(t[i]);
			}
		}
		return a;
	}
	_arrPath = object_change_array( target, _arrPath );
	_arrPathLength = _arrPath.length-1;

	//set updatekey
	if(navigator.userAgent.toLowerCase().indexOf('msie') != -1){
		updatekey = '?key=' + new Date().getTime();
	}
	for(var i=0, l=_arrPathLength; l>=i; i++){
		_arrPathLoader[i] = new ImageLoader(_arrPath[i]);
	}
	function ImageLoader(src){
		var image = new Image();
		image.src = src + updatekey;
		image.onload = onLoad;
		_arrObjPath[_arrObjPath.length] = image;
	}
	function onLoad(){
		_cnt++;
		if( _arrPathLength === _cnt ) _success();
	}
	function _success(){
		clear();
		fnSuccess(_arrObjPath);
	}
	function _timeout(){
		clear();
		fnTimeout(_arrObjPath);
	}
	function clear(){
		clearTimeout(timeid);
	}
	return _arrObjPath;
}
ImageLoader.prototype = {};

//aside
$(function() {
  
   $('img.fade').hover(function () {
        $(this).stop().fadeTo('slow', 0.8);
    }, function () {
        $(this).stop().fadeTo('slow', 1.0);
    });
  
});
