
// ajax function
function load_file(divName,fileURL) {
	$("#"+divName).load(fileURL);
}



// set easeout
jQuery.easing.quart = function (x, t, b, c, d) {
	
	return -c * ((t = t / d - 1) * t * t * t - 1) + b;
};



var height_all,height_view,maxY, goto_id, shiftY, targetY, t, t1, t2;

function heightfix() {

	var section_height = $('#section').height();
	var side_height = $('#side').height();

	if ((section_height - side_height) < 110) $('.section_heightfix').height((side_height + 110)-section_height);
}

// ready command
$(document).ready(function(){

	height_all  = $('#wrap1').height();
	height_view = $(window).height();
	maxY = height_all - height_view;
	
	shiftY = 0;

	// 外部読み込みするページ

	load_file("common","http://www.youyou.co.jp/only/common/bar.html");
	load_file("update_contents","modify_update.htm");
	load_file("onlycom_contents","modify_onlycom.htm");

	// ローカルナビの直後にcrearfix追加
	$('#nav_local').after('<br class="clear">');

	// リスト内偶数番目のtdはセンタリング
/*
	$("#list table").each(function(){
		jQuery(this).find("td:even").addClass("c_name");
		jQuery(this).find("td:odd").addClass("c_no");
	});
*/
	// リスト偶数番目のdivの後にcrearfix追加
	$(".wrap_list:odd").after('<hr class="clear">');
	
	// ボタンクラスの中にタグを追加してボタン化する

	t1 = '<span class="button_l">&nbsp;</span><span class="button_c">';
	t2 = '</span><span class="go">&nbsp;</span>';

	$('.button_go').each( function() {
		
		t = $(this).text();
		$(this).html( $(this).html().replace(t, t1+t+t2) );
//		$(this).after('<br class="clear">');
	});


	t2 = '</span><span class="mail">&nbsp;</span>';

	$('.button_mail').each( function() {

		t = $(this).text();
		$(this).html( $(this).html().replace(t, t1+t+t2) );
//		$(this).after('<br class="clear">');
	});

	$('.buttons').after('<br class="clear">');


	// smooth scroll 2.0

	$('a[href^=#], area[href^=#]').each( function() {
		
		goto_id = $(this).attr("href").split("#");
		
		if (goto_id[0] == "") {
		
			if (goto_id[1] == "") {
				
				$(this).click(function () {
						
					$('html, body').animate({
						scrollTop: 0
					}, 800, 'quart');
						
					return false;
				});
			
			} else {
	
				if ($("#"+goto_id[1]).size() > 0) {
					
					var targetOffset = Math.min( $("#"+goto_id[1]).offset().top - shiftY, maxY);
					
					if (targetOffset < 0) {targetOffset = 0;}
	
					$(this).click(function () {
							
						$('html, body').animate({
							scrollTop: targetOffset
						}, 800, 'quart');
							
						return false;
					});
				}
			}
		}
	});

	if (location.hash) {
	
		var hash = location.hash;
		
		window.scroll(0,0);
		
		$('a[href=' + hash + ']').click();
	}

});



// onload commands
jQuery.event.add(window, "load", function() {
	
	heightfix();	
});
