// JavaScript Document

/*アーカイブリンク セレクトメニュー*/

function archive_check(chk_item){
	menu = document.archive_menu.elements[chk_item];
	set = menu.options[menu.selectedIndex].value;
	/*alert(vale);*/
	if(set == '' || set =='選択してください' ){
		return false; // 送信を中止
	}else{
		return  true;
	}
}
function archive_date(){
	if(archive_check('date')){
		document.archive_menu.submit();
	}
}


/*[MS-IE] XML Caching                         */
/* get xml url edit [xxxxxxxxx.xml?timecunt]  */
function xml2IE(xml_uri){
	var add_string = "";
	if(navigator.userAgent.indexOf("MSIE") >= 0){
		var now = new Date();
		if(xml_uri.indexOf("?",0) < 0){
			add_string = '?time="'+now.getTime()+'"';
		}
		else{
			add_string = '&time="'+now.getTime()+'"';
		}
	}
	return xml_uri+add_string;
}

//同カテゴリ リスト・カウンター
var list_count = 0;
//自己ファイル名
var path = location.pathname;
var path_list = path.split("/");
var this_file = path_list.pop();

/*同カテゴリ リンクリスト・フィルター*/
var linklist_filter= function(dataSet, row, rowNumber)
{
	file_work = row["file"].split("/");
	file_work = file_work.pop();
	if(this_file == file_work){
		//自己ファイルは対象外
		return null; // Return null to remove the row from the data set.
	}else{
		//リンク件数+1
		list_count++;
		if( list_count > 10){
			//表示件数以上、不要
			return null; // Return null to remove the row from the data set.
		}
	}
	//日付の後ろの時刻を削除する
	date_work =row["@date"];
	date_work = date_work.split(" ");
	row["@date"] = date_work[0];
	//ファイルパスを調整
	row["file"] = "../../" + row["file"];
	
	return row; // Return the row to keep it in the data set.

}

//2011.09.01 xmlラッパーphp
var wwwMain = "http://www.tsurube.com/";
//var count_xml = "http://www.tsurube.com/archives/count_list.xml";
var count_xml = wwwMain+"archives/xml-list.php?xml=count";
count_xml = xml2IE(count_xml);

var total_counts = new Spry.Data.XMLDataSet(count_xml, "counts/total");
var monthly_list = new Spry.Data.XMLDataSet(count_xml, "counts/monthly/month");

if(my_category == undefined){
	var my_category = '';
}
if(my_category != ''){
//	var newest_xml = "http://www.tsurube.com/archives/category_newest.xml";
	var newest_xml = wwwMain+"archives/xml-list.php?xml=newest";
	newest_xml = xml2IE(newest_xml);
	var category_list = new Spry.Data.XMLDataSet(newest_xml, "newest/category[@value='"+my_category+"']/item");
	category_list.filterData(linklist_filter);
}

/*Spry項目を表示*/
function spry_dat_disp(){
	var spry_dat = $$("span.spry_dat");
		spry_dat.each(
		function(obj){
				obj.style.display ='inline';
			}
		);
	var archive_list = $("archive");
	archive_list.style.display ="block";
    
	if(my_category != ''){
		var same_list = $("same_list");
		same_list.style.display ="block";
	}
	
}
Event.observe(window, 'load', spry_dat_disp, false);

//headlineImage--------------------------
function headlineImageDispReset(){
	var flg=true;
	if($$("#blog_text .headline p.caption").length>0){
		flg=false;
	}
	if(flg){
		$$("#blog_text .headline img:not(.tate)").each(function(n){
		if(n.getWidth()<n.getHeight()){
				n.addClassName('tate');
			}
		});
		$$("#blog_text .headline a").each(function(n){
			cap=n.getAttribute("caption");
			if(cap.length>0){
				new Insertion.After(n, '<p class="caption">'+cap+'</p>');
			}
		});
	}
}
Spry.Utils.addLoadListener(headlineImageDispReset);
