// JavaScript Document
//facebook rssを取得
google.load("feeds", "1");
function initialize() {
	var feed = new google.feeds.Feed("http://www.facebook.com/feeds/page.php?id=100882733333029&format=atom10");
	feed.setNumEntries(2);
	feed.load(dispfeed);

function dispfeed(result){
  if (!result.error){
	for (var i = 0; i < result.feed.entries.length; i++) {
	  var entry = result.feed.entries[i];
	  var title = entry.title;
	  var link = entry.link;
	  var content = entry.content;
	  var publishedDate = entry.publishedDate;
	  var dd = new Date(entry.publishedDate); // now
	  var yearNum = dd.getYear();
	  if (yearNum < 2000) yearNum += 1900;
	  var date = yearNum + "."+(dd.getMonth()+1)+"."+dd.getDate()+" at " +dd.getHours()+":"+dd.getMinutes();
	  //alert(content);
	  var passage = '<div class="article">' + '<div class="honbun">' + content + '</div><div class="date">' + date + '</div></div>';
	  $("#wallInner").append(passage);
	}
  }
	$('#wallInner a').each(function(){
		$(this).attr("target","_blank");
	});
	
	setPosition();
	$('#photo img:nth-child(1)').fadeIn(500);
	setPosition();


}
}
google.setOnLoadCallback(initialize);



var rH;
var rW;
var bH;
var bW;
var flag = false;


function setPosition() {
	//高さ、幅を取得
	hH = $('#header').height();
	fH = $('#footer').height();
	rH = $('#right').height();
	rW = $('#right').width();
	bH = $('body').height();
	bW = $('body').width();
	
	if(hH + fH + rH < bH){
		rH = bH - fH - hH - 1;
		flag = true;
	}
	
	//alert(flag);
	
	changeWidth();
	changeWidth();
}

window.onresize = setPosition;

function changeWidth(){
	
	if(flag == true){
		$('#right #rightInner').css("height",rH);
	}
	$('#upLayer').css("width",bW - rW);
	$('#upLayer').css("height",rH);
	$('#photo').css("width",bW - rW);
	$('#photo').css("height",rH);
	$('#photoDot').css("width",bW - rW);
	$('#photoDot').css("height",rH);
	
	$('#photo img').each(function(){
		
		var photoSize = 600;//写真サイズ
		var tH = $(this).height();
		var tW = $(this).width();
		var scaleW = (bW - rW) / photoSize;

		if(scaleW * photoSize < rH){
			$(this).css("height", rH);
			$(this).css("width", "auto");
		}else{
			$(this).css("width", bW - rW);
			$(this).css("height", "auto");
		}
		
		$(this).css("left",(bW - rW - tW)/2);
		//$(this).css("top",(rH - tH)/2);
		
	}
	);
	
};

//写真差し替え

var cnt = 0;
var cntB = 0;
var interval = 4;

$(function(){
	//z-indexを設定
	$('#photo img:nth-child(1)').css("z-index","15");
	$('#photo img:nth-child(2)').css("z-index","14");
	$('#photo img:nth-child(3)').css("z-index","13");
	$('#photo img:nth-child(4)').css("z-index","12");
	$('#photo img:nth-child(5)').css("z-index","11");
	
	//一旦消去
	$('#upLayer ul ul').each(function(){
		$(this).css("display","none");
	});
	
	$('#gn2').mouseover(function(){
		$('#sub2').css("display","block");
	}).mouseout(function(){
		$('#sub2').css("display","none");
	});
	$('#gn3').mouseover(function(){
		$('#sub3').css("display","block");
	}).mouseout(function(){
		$('#sub3').css("display","none");
	});
	$('#gn4').mouseover(function(){
		//$('#sub4').css("display","block");
	}).mouseout(function(){
		//$('#sub4').css("display","none");
	});
	
	$('#photo img').each(function(){
		$(this).css("display","none");
	});

	
});
	
	  
function count(){
	cnt += 1;
	//setPosition();
	
	if(cnt == 1){
		setPosition();
		$('#photo img:nth-child(1)').fadeIn(500);
	}else if(cnt == 1 + interval){
		$('#photo img:nth-child(1)').fadeOut(500);
		$('#photo img:nth-child(2)').fadeIn(0);
		$('#photo img:nth-child(3)').fadeIn(0);
		$('#photo img:nth-child(4)').fadeIn(0);
		$('#photo img:nth-child(5)').fadeIn(0);
		setPosition();
	}else if(cnt == 1 + interval * 2){
		$('#photo img:nth-child(2)').fadeOut(500);
		setPosition();
	}else if(cnt == 1 + interval * 3){
		$('#photo img:nth-child(3)').fadeOut(500);
		setPosition();
	}else if(cnt == 1 + interval * 4){
		$('#photo img:nth-child(4)').fadeOut(500);
		setPosition();
	}else if(cnt == 1 + interval * 5){
		$('#photo img:nth-child(1)').fadeIn(500);
		setPosition();
		cnt = 0;
	}
	
	//$("#test").html(cnt);
	
	setTimeout( function(){count()},2000 );
}
count();

//サブメニュー


