/**
 * common.js
 *
 *  version --- 3.2
 *  updated --- 2011/06/06
 */


/* !stack ------------------------------------------------------------------- */
jQuery(document).ready(function(j$) {
	pageScroll();
	rollover();
	popWindow();
	localNav();
});


/* !isUA -------------------------------------------------------------------- */
var isUA = (function(){
	var ua = navigator.userAgent.toLowerCase();
	indexOfKey = function(key){ return (ua.indexOf(key) != -1)? true: false;}
	var o = {};
	o.ie      = function(){ return indexOfKey("msie"); }
	o.fx      = function(){ return indexOfKey("firefox"); }
	o.chrome  = function(){ return indexOfKey("chrome"); }
	o.opera   = function(){ return indexOfKey("opera"); }
	o.android = function(){ return indexOfKey("android"); }
	o.ipad    = function(){ return indexOfKey("ipad"); }
	o.ipod    = function(){ return indexOfKey("ipod"); }
	o.iphone  = function(){ return indexOfKey("iphone"); }
	return o;
})();
/* !fxPrint ----------------------------------------------------------------- */
(function(){
	setCSS = function(){
		elem = document.createElement('link');
		elem.setAttribute('rel','stylesheet');
		elem.setAttribute('type','text/css');
		elem.setAttribute('media','print');
		elem.setAttribute('href','/hardware/common/css/fx_print.css');
		document.getElementsByTagName('head')[0].appendChild(elem);
	}
	if( isUA.fx() ) window.addEventListener("load",setCSS,false); 
})();
/* !rollover ---------------------------------------------------------------- */
var rollover = function(){
	var suffix = { normal : '_no.', over   : '_on.'}
	j$('a.over, img.over, input.over').each(function(){
		var a = null;
		var img = null;

		var elem = j$(this).get(0);
		if( elem.nodeName.toLowerCase() == 'a' ){
			a = j$(this);
			img = j$('img',this);
		}else if( elem.nodeName.toLowerCase() == 'img' || elem.nodeName.toLowerCase() == 'input' ){
			img = j$(this);
		}

		var src_no = img.attr('src');
		var src_on = src_no.replace(suffix.normal, suffix.over);

		if( elem.nodeName.toLowerCase() == 'a' ){
			a.bind("mouseover focus",function(){ img.attr('src',src_on); })
			 .bind("mouseout blur",  function(){ img.attr('src',src_no); });
		}else if( elem.nodeName.toLowerCase() == 'img' ){
			img.bind("mouseover",function(){ img.attr('src',src_on); })
			   .bind("mouseout", function(){ img.attr('src',src_no); });
		}else if( elem.nodeName.toLowerCase() == 'input' ){
			img.bind("mouseover focus",function(){ img.attr('src',src_on); })
			   .bind("mouseout blur",  function(){ img.attr('src',src_no); });
		}

		var cacheimg = document.createElement('img');
		cacheimg.src = src_on;
	});
};
/* !pageScroll -------------------------------------------------------------- */
var pageScroll = function(){
	jQuery.easing.easeInOutCubic = function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	}; 
	j$('a.scroll, .scroll a, .pageTop a').each(function(){
		j$(this).bind("click keypress",function(e){
			e.preventDefault();
			var target  = j$(this).attr('href');
			var targetY = j$(target).offset().top;
			var parent  = ( isUA.opera() )? (document.compatMode == 'BackCompat') ? 'body': 'html' : 'html,body';
			j$(parent).animate(
				{scrollTop: targetY },
				1000,
				'easeInOutCubic',
				function(){
					location.hash = target;
				}
			);
			return false;
		});
	});
}
/* !localNav ---------------------------------------------------------------- */
var localNav = function(){
	var navClass = document.body.className;
	var parent = j$("#lNavi");
	var routing = [];
	j$("ul ul", parent).hide();
	if( navClass.indexOf("lDef") != -1 ){
		routing[0] = navClass.match(/l[\d]+_[\d]+_[\d]+/);
		routing[1] = navClass.match(/l[\d]+_[\d]+/);
		routing[2] = navClass.match(/l[\d]+/);
		if( routing[0] ){ routing[0].push(routing[0][0].match(/[\d]+/g)) };
		if( routing[1] ){ routing[1].push(routing[1][0].match(/[\d]+/g)) };
		if( routing[2] ){ routing[2].push(routing[2][0].match(/[\d]+/g)) };
		if( routing[0] != null ){
			var e = j$("a.lNav"+routing[0][1][0]+'_'+routing[0][1][1]+'_'+routing[0][1][2], parent);
				e.addClass('current');
				e.parent().parent().show()
				 .parent().parent().show();
		}else if( routing[1] != null ){
			var e = j$("a.lNav"+routing[1][1][0]+'_'+routing[1][1][1], parent);
				e.addClass('current');
				e.next().show();
				e.parent().parent().show();
		}else if( routing[2] != null ){
			var e = j$("a.lNav"+routing[2][1], parent);
				e.addClass('current');
				e.next().show();
		}else{
		}
	}
}
/* !popWindow --------------------------------------------------------------- */
var popWindow = function (){
	var param = null;
	// param[0] = width
	// param[1] = height
	// param[2] = window.name
	j$('a[class^="js_popup"], area[class^="js_popup"]').each(function(i){
		j$(this).click(function(){
			var w = null;
			param = j$(this).attr('class').match(/[0-9]+/g);
			// get window.name
			param[2] = window.name ? window.name+'_' : '';
			w = window.open(this.href, param[2]+'popup'+i,'width='+param[0]+',height='+param[1]+',scrollbars=yes');
			w.focus();
			return false;
		});
	});
}
/* !defFunc ----------------------------------------------------------------- */
var defFunc = (function(){
	Print = function(){ window.print(); return false;}
	Close = function(){ window.close(); return false;}
})();

/*	//	opacityOver
-----------------------------------------------------------------------------------------------------------------*/
j$(function(){

		j$(".opacityOver").fadeTo(1,1);

		j$(".opacityOver").hover(
		  function () {
			j$(this).stop().fadeTo(200, 0.85);
		  },
		  function () {
			j$(this).stop().fadeTo(400, 1);
		  }
		);

		j$("ul#topicPath li.home a img").hover(
		  function () {
			j$(this).stop().fadeTo(200, 0.7);
		  },
		  function () {
			j$(this).stop().fadeTo(400, 1);
		  }
		);

});

/*	//	「戻る」時の不具合 キャッシュクリア
-----------------------------------------------------------------------------------------------------------------*/
window.onunload = function(){}
