/*********************************************************************

  グローバル変数定義

*********************************************************************/

var sendFlag = false;
var editFlag = false;

/*********************************************************************

  入力内容チェック

*********************************************************************/

function checkForm(form)
{
	if (form.subj && !form.subj.value) {
		alert('題名が入力されていません。');
		return false;
	}
	if (form.text && !form.text.value) {
		alert('本文が入力されていません。');
		return false;
	}

	if (sendFlag == true) {
		alert('二重投稿は禁止です。');
		return false;
	} else {
		sendFlag = true;
	}

	return true;
}

/*********************************************************************

  ファイル挿入

*********************************************************************/

function insertFile(form)
{
	var text = form.text;
	var file = form.file;

	if (file) {
		file.onchange = function()
		{
			if (file.value) {
				text.focus();

				if (document.selection) {
					document.selection.createRange().text = file.value;
				} else if (text.selectionEnd - text.selectionStart == 0) {
					var before = text.value.substring(0, text.selectionStart);
					var after  = text.value.substring(text.selectionEnd, text.value.length);

					text.value = before + file.value + after;
				} else {
					text.value += file.value;
				}

				text.focus();
			}

			form.file.selectedIndex = 0;
		};
	}

	return;
}

/*********************************************************************

  Cookie取得

*********************************************************************/

function getCookie(form)
{
	if (!document.cookie) {
		return;
	}

	var cookies = document.cookie.split('; ');
	var cookie  = new Array();

	for (var i = 0; i < cookies.length; i++){
		var pair = cookies[i].split('=');
		cookie[pair[0]] = unescape(decodeURI(pair[1]));
	}

	if (form.name && cookie['comment[name]']) {
		form.name.value = cookie['comment[name]'];
	}
	if (form.mail && cookie['comment[mail]']) {
		form.mail.value = cookie['comment[mail]'];
	}
	if (form.url && cookie['comment[url]']) {
		form.url.value = cookie['comment[url]'];
	}
	if (form.name && cookie['comment[name]']) {
		form.save.checked = true;
	}

	return;
}

/*********************************************************************

  処理開始

*********************************************************************/

window.onload = function()
{
	var nodeArticleForm = document.getElementById('article_form');
	var nodeCommentForm = document.getElementById('comment_form');
	var nodeLoginForm   = document.getElementById('login_form');

	if (nodeArticleForm) {
		//入力内容チェック
		nodeArticleForm.onsubmit = function()
		{
			return checkForm(nodeArticleForm);
		};
		nodeArticleForm.text.onkeyup = function()
		{
			if (!editFlag) {
				editFlag = true;
			}
			return;
		};

		//ファイル挿入
		insertFile(nodeArticleForm);
	}

	if (nodeCommentForm) {
		//Cookie取得
		getCookie(nodeCommentForm);
	}

	if (nodeLoginForm) {
		//フォーカス設定
		nodeLoginForm.pwd.focus();
	}

	return;
};
window.onbeforeunload = function()
{
	if (!sendFlag && editFlag) {
		return 'ページを移動した場合、編集中のテキストは破棄されます。';
	}

	return;
};

$(function(){
		   
/*********************************************************************

  矩形の角丸化

*********************************************************************/
$(".crectbox").corner("keep");
$(".safetybox").corner("keep");
$(".flow h3").corner("5px");
$(".archi_box").corner("5px");

/*********************************************************************

  ポップアップ

*********************************************************************/

$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
});

/*********************************************************************

  フェードの処理

*********************************************************************/

$(".fade").load(function(){
	$(this).fadeTo(0, 0.0);
});

$(".fade").hover(
				 
function(){
	$(this).fadeTo(150, 1.0);
},
function(){
	$(this).fadeTo(150, 0.0);
}

);

});

/*********************************************************************

  アニメーションの処理

*********************************************************************/

$(window).load(function(){
	
	$("#inquiry_btn").animate({ width : 160},300,"linear",function(){
	$("#inquiry_btn").animate({ top : 170 },1200,"easeOutBounce");
	});
	
});

/*********************************************************************

  フローティングメニューの処理

*********************************************************************/

$(function() { 
	$(".sidemenu").scrollFollow({});
});

//オプション
$(function() { 
	$(".sidemenu").scrollFollow({
		//アニメーションの速度の設定。0 にするとアニメーションなしになります。
		speed: 500,
		//ブラウザの領域とフロート要素との余白。0にするとぴったりくっつきます。
		offset: 30
	});
});

/*********************************************************************

  初期化処理

*********************************************************************/

$(document).ready( function () {

ml=$("#main_left").height();
mr=$("#main_right").height();
if(ml>mr)$("#main_right").css("height", ml);
if(mr>ml)$("#main_left").css("height", mr);

pl=$("#page_left").height();
pr=$("#page_right").height();
if(pl>pr)$("#page_right").css("height", pl);
if(pr>pl)$("#page_left").css("height", pr);

});