// Easingの追加
jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

//
// 画像の先読み
//
jQuery.preloadImages = function(arguments)
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", temp_dir + arguments[i]);
	}
};

args = new Array("/images/header_menu1_on.gif",
								 "/images/header_menu2_on.gif",
								 "/images/header_menu3_on.gif",
								 "/images/header_menu4_on.gif",
								 "/images/header_menu5_on.gif",
								 "/images/header_menu6_on.gif");
jQuery.preloadImages(args);


/*-------------------------------------
 ページ読み込み中
-------------------------------------*/
jQuery(document).ready(function(){
	//
	// <a href="#***">の場合、スクロール処理を追加
	//
	jQuery('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
				return false;
			}
		}
	});

	//
	// <a rel="blank">の時は別ウィンドウで表示させる
	//
	jQuery("a").each(function(){
		if(jQuery(this).attr("rel") == "blank") {
			jQuery(this).attr("target", "_blank");
		}
	});

	//
	// id = trackbackurl に処理を追加
	//
	jQuery("#trackbackurl").bind("click", function(){
  	jQuery(this).get(0).select();
	});

	//
	// ロールオーバーの処理
	//
	jQuery("img.rollover").mouseover(function(){
		jQuery(this).attr("src",jQuery(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	}).mouseout(function(){
		jQuery(this).attr("src",jQuery(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).each(function(){
		jQuery("<img>").attr("src",jQuery(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	});

	jQuery("input:text,textarea").focus(function() { jQuery(this).removeClass("blur"); jQuery(this).addClass("focus"); }).blur(function() { jQuery(this).removeClass("focus"); jQuery(this).addClass("blur"); });

	if(jQuery.cookie('item')) {
		jQuery("input[name=your-subject]").val(jQuery.cookie('item') + "に関するお問い合わせ");
		jQuery.cookie('item', "",{path:"/",expires:-1, domain: "k1factory.jp"});
	}

});


function show_frame(val) {
	var obj = "#" + val;
	jQuery("#bgframe").width(jQuery(document).width());
	jQuery("#bgframe").height(jQuery(document).height());
	var top = Math.floor((jQuery(window).height() - jQuery(obj).height()) / 2) + jQuery(document).scrollTop();
	var left = Math.floor((jQuery(window).width() - jQuery(obj).width()) / 2) + jQuery(document).scrollLeft();
	jQuery(obj).css("top", top + "px");
	jQuery(obj).css("left", left + "px");
	jQuery("#bgframe").fadeTo("normal", 0.75);
	jQuery(obj).fadeIn();
}

function hide_frame() {
	jQuery("#bgframe").fadeOut();
	jQuery(".forward").fadeOut();
}

function print_r( obj, maxlevel, maxitem ) {
    if (!maxlevel)  maxlevel = 4;
    if (!maxitem)   maxitem = 150;
    var txt = "";
    var count_obj = 0;
    function _output(str) {
      　txt += str + "<br/>";
    }
    function _print_r(obj, name, level) {
        var s = "";
        if (obj == undefined || level > maxlevel) return;
        for (var i = 0; i < level; i++) { s += " | "; }
        s += " - " + name + ":" + typeof(obj) + "=" + obj;
        _output(s);
        if (name == "document" || typeof(obj) != "object") return;
        for (var key in obj ) {
            if (count_obj++ > maxitem) return;
            _print_r(obj[key], key, level + 1);
        }
    }
    _print_r(obj, "*", 0);
    return txt;
}

/* 加工実績からのお問い合わせ */
function item_question(val) {
	if(jQuery.cookie('item')) jQuery.cookie('item', null);
	jQuery.cookie('item', val,{ expires: 14, path: '/', domain: "k1factory.jp" });

	location.href = "http://www.k1factory.jp/contact";
}

/* 販売製品の追加 */
function add_order(id, name, amount, val) {
	if(id == undefined || name == undefined || amount == undefined || val == undefined) return;

	var order = new Array();

	if(jQuery.cookie('order')) {
		order = jQuery.cookie('order').split('&');
		var cnt = order.length;
		var bl = true;
		for(var i=0; i<cnt; i++) {
			var data = order[i].split(',');
			if(data[0] == id) {
				order[i] = id + "," + name + "," + amount + "," + val;
				bl = false;
			}
		}
		if(bl) {
			order.push(id + "," + name + "," + amount + "," + val);
		}
	} else {
		order.push(id + "," + name + "," + amount + "," + val);
	}
	var data = order.join('&');
	jQuery.cookie('order', data,{ expires: 14, path: '/', domain: "k1factory.jp" });

	location.href = "http://www.k1factory.jp/order-sales";
}


/* FAQ 回答のスライド処理 */
function slide_content(id) {
	var obj = jQuery(id).next();
	if(obj.text() == "[ 続きを読む ]") {
		jQuery(id).animate({
			height: "100%"
		}, 500);
		obj.text("[ 折りたたむ ]");
	} else {
		jQuery(id).animate({
			height: "3em"
		}, 500);
		obj.text("[ 続きを読む ]");
	}
}

function delComma(xstr){
	//カンマ区切りの数値から数値のみを取り出し、Float型に変換
	matchstr = new RegExp("[^\,]", "g");
	strArray = xstr.match(matchstr);
	r_str = strArray.join("");
	return parseFloat(r_str);
}

function insertComma(str) {
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}

function strToNum(xstr){
	//数値のみを取り出してInt型に変換
	matchstr = new RegExp("[0-9]+", "g");
	strArray = xstr.match(matchstr);
	if(strArray == null) {
		r_str = "0";
	} else {
		r_str = strArray.join("");
	}
	return parseInt(r_str);
}

function Fulltohalf(data){
	han = "0123456789.,-+";
	zen = "０１２３４５６７８９．，－＋";
	str = "";

	for (i=0; i<data.length; i++) {
		c = data.charAt(i);
		n = zen.indexOf(c,0);
		v = han.indexOf(c,0);
		if (n >= 0) {
			c = han.charAt(n);
		}
		str += c;
	} 
	return str;
}

function numeralsOnly(evt){
	//数字のみ入力許可
	//使用方法 onkeypress="return numeralsOnly(event);"
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if(charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46 && charCode != 45){
		return false;
	}
	return true;
}

