/*
 * 
 *
 * 
 */

/*
*
*
* Version : 1.0
*
*/


(function($) {

jQuery(document).ready(function(){


/***************/
    jQuery.twoauthpopup = function(options)
    {
        options.windowName = options.windowName ||  'ConnectWithOAuth'; // should not include space for IE
        options.windowOptions = options.windowOptions || 'location=0,status=0,width=900,height=500';
        options.callback = options.callback || function(){ window.location.reload(); };
        var that = this;

        that._twoauthWindow = window.open(options.path, options.windowName, options.windowOptions);
/*that._twoauthWindow.opener.$('#twconect').hide('slow');*/
/*that._twoauthWindow.opener.$('#nonconnect').show('slow');*/
        that._twoauthInterval = window.setInterval(function(){
            if (that._twoauthWindow.closed) {
                window.clearInterval(that._twoauthInterval);
                options.callback();
            }
        }, 1000);
    };


/****************/



$(function() {
	setModal();
})
 
function setModal() {
 
	//HTML読み込み時にモーダルウィンドウの位置をセンターに調整
	adjustCenter("a.modal");
 
	//ウィンドウリサイズ時にモーダルウィンドウの位置をセンターに調整
	$(window).resize(function() {
		adjustCenter("a.modal");
	});
 
	//背景がクリックされた時にモーダルウィンドウを閉じる
	$("a.modal").click(function() {
		displayModal(false);
	});
 
	//リンクがクリックされた時にAjaxでコンテンツを読み込む
	$("a.modal").click(function() {
		$("a.modal").load($(this).attr("href"), data="html", onComplete);
		return false;
	});
 
	//コンテンツの読み込み完了時にモーダルウィンドウを開く
	function onComplete() {
		displayModal(true);
		$("div#modal div.container a.close").click(function() {
			displayModal(false);
			return false;
		});
	}
}
 
//モーダルウィンドウを開く
function displayModal(sign) {
	if (sign) {
		$("a.modal").fadeIn(500);
	} else {
		$("a.modal").fadeOut(250);
	}
}
 
//ウィンドウの位置をセンターに調整
function adjustCenter(target) {
	var margin_top = ($(window).height()-$(target).height())/2;
	var margin_left = ($(window).width()-$(target).width())/2;
	$(target).css({top:margin_top+"px", left:margin_left+"px"});
} 





/****************/


$('img#okini').click(function(){
	addBookmark('JAF Mateパーク','http://jafmate.jp/pc/');
	function addBookmark(title,url) {  
		if (window.sidebar) {  
			window.sidebar.addPanel(title, url,"");  
		} else if( document.all ) {  
			window.external.AddFavorite( url, title);  
		} else if( window.opera && window.print ) {  
			return true;  
		}  
	}
});

$('img#cokin').click(function(){
	addBookmark('JAF Mateパーク　カレンダー','http://jafmate.jp/pc/c_calendar/calendar1.htm');
	function addBookmark(title,url) {  
		if (window.sidebar) {  
			window.sidebar.addPanel(title, url,"");  
		} else if( document.all ) {  
			window.external.AddFavorite( url, title);  
		} else if( window.opera && window.print ) {  
			return true;  
		}  
	}
});



$('img.bt1#nologin').click(function(){
/*	alert('ページ上部でログインしてください');*/
/*var id = $(this).attr('id');*/
/*var id = 'ページ上部でログインしてください';*/
/*oge( id );*/
			$(".logintext1").attr({"style":"display:block;"});
			$(".logintext1").css("color","#f70782");
});

function hoge( val ) { alert( val ); }


/*ログイン*/
$('img#neo1').click(function(){
/*	window.open('../neo/neo1/index.html','');*/
	window.open('../neo/neo5/index.html','');
	return false;
	});
$('img.bt2#neo2').click(function(){
/*	alert('１５日からの掲載です。ご期待ください。');*/
	window.open('../neo/neo2/index.html','');
	return false;
	});
$('p.altneo1#neo1').click(function(){
/*	window.open('../neo/neo1/index.html','');*/
	window.open('../neo/neo5/index.html','');
	return false;
	});
$('p.altneo2#neo2').click(function(){
/*	alert('１５日からの掲載です。ご期待ください。');*/
	window.open('../neo/neo2/index.html','');
	return false;
	});

/*NOログイン*/
$('img.bt1#noneo1').click(function(){
	alert('ページ上部でログインしてください');
/*
	$(".logintext1").attr({"style":"display:block;"});
	$(".logintext1").css("color","#f70782");
*/
	});
$('img.bt2#noneo2').click(function(){
/*	alert('１５日からの掲載です。ご期待ください。');*/
	alert('ページ上部でログインしてください');
/*
	$(".logintext1").attr({"style":"display:block;"});
	$(".logintext1").css("color","#f70782");
*/
	});
$('p.noaltneo1').click(function(){
	alert('ページ上部でログインしてください');
/*
	$(".logintext1").attr({"style":"display:block;"});
	$(".logintext1").css("color","#f70782");
*/
	});
$('p.noaltneo2').click(function(){
/*	alert('１５日からの掲載です。ご期待ください。');*/
	alert('ページ上部でログインしてください');
/*
	$(".logintext1").attr({"style":"display:block;"});
	$(".logintext1").css("color","#f70782");
*/
	});

/*ejafログイン*/
$('img.bt#ejaf').click(function(){
	window.open('../ejaf_mate/ejm1/index.html','');
	return false;
	});
$('p.altejaf').click(function(){
	window.open('../ejaf_mate/ejm1/index.html','');
	return false;
	});
/*ejaf_noログイン*/
$('img.bt#noejaf').click(function(){
	alert('ページ上部でログインしてください');
	});
$('p.noaltejaf').click(function(){
	alert('ページ上部でログインしてください');
	});

/*ejaf_photogra_story*/
$('img.bt#photogra_story').click(function(){
	window.open('../photogra_story/ejaf1201/index.html','');
	return false;
	});



/*back図書館_NOログイン*/
$('img#nologback').click(function(){
	alert('ページ上部でログインしてください');
/*
	$(".logintext1").attr({"style":"display:block;"});
	$(".logintext1").css("color","#f70782");
*/
	});




	//初期時のカウンターファイル読み込み
	//同じファイル名だと正常に読み込めないので、ランダムな数字を生成し、パラメータとして付けることで、ユニークな状態にしている。
	$.post("counter.php",{"textdata" : "count01.txt"},displayData1);

	//カウンター追加後の読み込み関数
	function func01(data){
/*		var randnum1 = Math.floor( Math.random() * 10000 );*/
/*		jQuery("#btn01 span").load("./count01.txt?r=" + randnum1);*/
	}
	function displayData1(data) {
		$("#textData1").html(data);
	}

	//カウンター＋1追加処理
	$('img.#btn01').click(function(e){
		//「param1」変数の値と書き込みファイル名の情報をもってpost.phpへ。その後、関数func01を実行
		$("#textData1").html('<img src="tstimg/b01.png" width="21" height="32"><img src="tstimg/b01.png" width="21" height="32"><img src="tstimg/b01.png" width="21" height="32"><img src="tstimg/b01.png" width="21" height="32">');

		if($("img.bt1#btn01").attr("src")!="img/c2_bt1_out.jpg"){
			$.post("post.php" , {"param1": "count01.txt"} , func01);
var name = "click";			// クッキーの名前
var value = "1";					// クッキーの値
var period = 0;					// 有効期限日数

// 有効期限の作成
var nowtime = new Date().getTime();
//var clear_time = new Date(nowtime + (60 * 60 * 24 * 1000 * period));
var clear_time = new Date(nowtime + (10));
var expires = clear_time.toGMTString();

// クッキーの発行（書き込み）
document.cookie = name + "=" + escape(value) + "; expires=" + expires;

//document.cookie = 'visitcount=;';

//document.cookie = 'click=value1;';

/********/
var yDay = new Date;
yDay.setHours(yDay.getHours() - 1); // 有効期限を1時間前に設定
yDay = yDay.toGMTString();          //GMT形式の文字列に変換
//document.cookie = 'visitcount' + "=xxx" + ";expires=" + yDay;
//document.cookie = 'click' + "=xxx" + ";expires=" + yDay;
/********/
		}

		//POSTメソッドで送るデータを定義します
		var data = {"textdata" :"count01.txt"};
		$.ajax({
			type: "POST",
			url: "counter.php",
			data: data,
			success: function(data, dataType) { /** Ajax通信が成功した場合に呼び出される */
			//返ってきたデータの表示（当サンプルだと「OK」か「The parameter of "request" is not found.」）
			$("#textData1").html(data);
			$("img.bt1#btn01").attr({"src":"img/c2_bt1_out.jpg","style":""});
			$("img.bt2#btn02").attr({"src":"img/c2_bt2_out.jpg","style":""});
			$("div.text1").attr({"style":"display:block;"});
			$("div.text1").css("color","#f70782");



			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {  /** Ajax通信が失敗した場合に呼び出される */
			// 通常はここでtextStatusやerrorThrownの値を見て処理を切り分けるか、
			// 単純に通信に失敗した際の処理を記述します。
			this; // thisは他のコールバック関数同様にAJAX通信時のオプションを示します。
			alert('Error : ' + errorThrown);
			}
		}); 
		return false;
	});






	//初期時のカウンターファイル読み込み
	//同じファイル名だと正常に読み込めないので、ランダムな数字を生成し、パラメータとして付けることで、ユニークな状態にしている。
	$.post("counter.php",{"textdata" : "count02.txt"},displayData2);

	//カウンター追加後の読み込み関数
	function func02(data){
/*		var randnum2 = Math.floor( Math.random() * 10000 );*/
/*		jQuery("#btn02 span").load("./count02.txt?r=" + randnum2);*/
	}
	function displayData2(data) {
		$("#textData2").html(data);
	}

	//カウンター＋1追加処理
	$('img.#btn02').click(function(e){
		//「param1」変数の値と書き込みファイル名の情報をもってpost.phpへ。その後、関数func01を実行
		$("#textData2").html('<img src="tstimg/b00.png" width="21" height="32"><img src="tstimg/b00.png" width="21" height="32"><img src="tstimg/b00.png" width="21" height="32"><img src="tstimg/b00.png" width="21" height="32">');

var cookie = document.cookie;
//alert(cookie);
/********/
var yDay = new Date;
yDay.setHours(yDay.getHours() - 1); // 有効期限を1時間前に設定
yDay = yDay.toGMTString();          //GMT形式の文字列に変換
//document.cookie = 'visitcount' + "=xxx" + ";expires=" + yDay;
//alert(yDay);
//document.cookie = 'click' + "=xxx" + ";expires=" + yDay;
/********/

	if($("img.bt2#btn02").attr("src")!="img/c2_bt2_out.jpg"){
		$.post("post.php" , {"param1": "count02.txt"} , func02);
//document.cookie = 'click=1; expires=Tue, 27-Dec-2011 12:09:00 GMT';

var name = "click";			// クッキーの名前
var value = "1";					// クッキーの値
var period = 1;					// 有効期限日数

// 有効期限の作成
var nowtime = new Date().getTime();
//var clear_time = new Date(nowtime + (60 * 60 * 24 * 1000 * period));
var clear_time = new Date(nowtime);
var expires = clear_time.toGMTString();
//alert(expires);

// クッキーの発行（書き込み）
//document.cookie = "'" + name + "=" + value + "; expires=" + expires + "'";
//alert("'" + name + "=" + value + "; expires=" + expires + "'");
//document.cookie = 'click=1; expires=Tue, 27-Dec-2011 11:36:00 GMT';
	}

		//POSTメソッドで送るデータを定義します
		var data = {"textdata" :"count02.txt"};
		$.ajax({
			type: "POST",
			url: "counter.php",
			data: data,
			success: function(data, dataType) { /** Ajax通信が成功した場合に呼び出される */
			//返ってきたデータの表示（当サンプルだと「OK」か「The parameter of "request" is not found.」）
			$("#textData2").html(data);
			$("img.bt1#btn01").attr({"src":"img/c2_bt1_out.jpg","style":""});
			$("img.bt2#btn02").attr({"src":"img/c2_bt2_out.jpg","style":""});
			$("div.text1").attr({"style":"display:block;"});
			$("div.text1").css("color","#f70782");
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {  /** Ajax通信が失敗した場合に呼び出される */
			// 通常はここでtextStatusやerrorThrownの値を見て処理を切り分けるか、
			// 単純に通信に失敗した際の処理を記述します。
			this; // thisは他のコールバック関数同様にAJAX通信時のオプションを示します。
			alert('Error : ' + errorThrown);
			}
		}); 
		return false;
	});



});


$(function(){
var moveInterval = 5;
var slideTime = 'fast';

	$('#loopslider').each(function(){
		var loopsliderWidth = $(this).width();
		var loopsliderHeight = $(this).height();
		$(this).children('ul').wrapAll('<div id="loopslider_wrap"></div>');
/*$('#loopslider').append('<div id="loopright"><img style=" margin-right:20px; margin-top:17px; float:right;" src="img/c3_r.jpg" alt="" width="38" height="225"></div>');*/
/*		$('#loopleft,#loopright').css({opacity:'0.5'});*/

		var listWidth = $('#loopslider_wrap').children('ul').children('li').width();
		var listCount = $('#loopslider_wrap').children('ul').children('li').length;

		var loopWidth = (listWidth)*(listCount);

		$('#loopslider_wrap').css({
			top: '0',
			left: '0',
			width: ((loopWidth) * 2),
			height: (loopsliderHeight),
			overflow: 'hidden',
			position: 'absolute'
		});

		$('#loopslider_wrap ul').css({
			width: (loopWidth)
		});
		$('#loopslider_wrap ul').clone().appendTo('#loopslider_wrap');

		timerLeft();
/*timerRight()*/

		function timerLeft(){
			setTimer = setInterval(function(){loopPositionLeft()},0);
		};

		function loopPositionLeft(){
			clearInterval(setTimer);
			$('#loopslider_wrap').stop().animate({left:'-=' + (moveInterval) + 'px'},slideTime,'linear',function(){
				var posLeft = parseInt($('#loopslider_wrap').css('left'));
				var widthCal = (loopWidth)-((loopWidth)*2);
/*				if (posLeft === widthCal) {*/
				if (posLeft <= widthCal) {
					$('#loopslider_wrap').css({left:'0'});
				}
				timerLeft();

				$(this).click(function(){
/*					$('#loopslider_wrap').css({left:'0'});*/
					$('#loopslider_wrap').stop();
					clearInterval(setTimer);
					slideTime = 'fast';
				},function(){
					loopPositionLeft();

				});
				
$(this).mouseover(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	return false;
});
$(this).mouseout(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	slideTime = 'fast';
	timerRight();
});
/*
				$(this).hover(function(){
					$('#loopslider_wrap').stop();
					clearInterval(setTimer);
					slideTime = 'fast';
				},function(){
					loopPositionLeft();
				});
*/
			});

		};

$('#loopright').mouseover(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	slideTime = 5;
	timerRight();
});
$('#loopright').mouseout(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	slideTime = 'fast';
	timerRight();
});
/*
		$('#loopright').hover(function(){
			$('#loopslider_wrap').stop();
			clearInterval(setTimer);
			slideTime = 5;
			timerRight();
		});
*/

		function timerRight(){
			setTimer = setInterval(function(){loopPositionRight()},0);
		};


		function loopPositionRight(){
			clearInterval(setTimer);
			$('#loopslider_wrap').stop().animate({left:'+=' + (moveInterval) + 'px'},slideTime,'linear',function(){
				var posLeft = parseInt($('#loopslider_wrap').css('left'));
				var widthCal = (loopWidth)-((loopWidth)*2);
				if (posLeft >= 0) {
					$('#loopslider_wrap').css({left:(-(loopWidth))});
				}
				timerRight();

				$(this).click(function(){
/*					$('#loopslider_wrap').css({left:(-(loopWidth))});*/
					$('#loopslider_wrap').stop();
					clearInterval(setTimer);
					slideTime = 'fast';
				},function(){
					loopPositionRight();
				});

$(this).mouseover(function(){
		$('#loopslider_wrap').stop();
		clearInterval(setTimer);
		return false;
});
$(this).mouseout(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	slideTime = 'fast';
	timerLeft();
});
/*
				$(this).hover(function(){
					$('#loopslider_wrap').stop();
					clearInterval(setTimer);
					slideTime = 'fast';
				},function(){
					loopPositionRight();
				});
*/
			});

		};

$('#loopleft').mouseover(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	slideTime = 5;
	timerLeft();
});
$('#loopleft').mouseout(function(){
	$('#loopslider_wrap').stop();
	clearInterval(setTimer);
	slideTime = 'fast';
	timerLeft();
});
/*
		$('#loopleft').hover(function(){
			$('#loopslider_wrap').stop();
			clearInterval(setTimer);
			slideTime = 5;
			timerLeft();
		});
*/
	});
});




/************************************************************/
/************************************************************/


})(jQuery);
