//------ Pager settings ------------------------
var myBlogMaxRows = new Number(15); //maxRow Setting
var myBlogCount = new Number();
var myBlogStart = new Number();
var myBlogPage = new Number(1);
var otherBlogMaxRows = new Number(5); //maxRow Setting
var otherBlogCount = new Number();
var otherBlogStart = new Number();
var otherBlogPage = new Number(1);

//----------------------------------------------

var myCat = new Number();
var noPhoto = 'http://www.monoglobe.jp/images/no_photo_44.gif';
var loadingImg = 'http://www.monoglobe.jp/images/side_loading.gif';

//------ Array Defaults ------------------------
var myBlogData = new Array();
var myEntryIdData = new Array();
var myImageData = new Array();
var myFile1Data = new Array();
var myFile2Data = new Array();
var myFile3Data = new Array();
var myFile4Data = new Array();
var myFile5Data = new Array();
var myFile6Data = new Array();
var myFile7Data = new Array();
var myFile8Data = new Array();
var myFile9Data = new Array();
var myFile10Data = new Array();
var myHrefData = new Array();
var myTitleData = new Array();
var myBodyData = new Array();

var otherBlogData = new Array();
var otherCatIdData = new Array();
var otherImageData = new Array();
var otherFile1Data = new Array();
var otherFile2Data = new Array();
var otherFile31Data = new Array();
var otherFile4Data = new Array();
var otherFile5Data = new Array();
var otherFile6Data = new Array();
var otherFile7Data = new Array();
var otherFile8Data = new Array();
var otherFile9Data = new Array();
var otherFile10Data = new Array();
var otherHrefData = new Array();
var otherTitleData = new Array();
var otherWriterData = new Array();

//----------------------------------------------

function myBlogListLoad(){
	var myBlogListPath = './index.xml';
	var myBlogResult = '';
	var myPagerDisplay = '';

	myBlogDisplay = function(){
		$("#my-archive").html(myBlogResult);
		$("#my-archive-pager").html(myPagerDisplay);
	},

	myBlogResponseXML = function(XML){
		myBlogCount = '';

		myBlogData = new Array();
		myEntryIdData = new Array();
		myImageData = new Array();
		myFile1Data = new Array();
		myFile2Data = new Array();
		myFile3Data = new Array();
		myFile4Data = new Array();
		myFile5Data = new Array();
		myFile6Data = new Array();
		myFile7Data = new Array();
		myFile8Data = new Array();
		myFile9Data = new Array();
		myFile10Data = new Array();
		myHrefData = new Array();
		myTitleData = new Array();
		myBodyData = new Array();


		$(XML).find("Blog").each(function(){
			myEntryIdData.push($(this).find("EntryId").text());
			myImageData.push($(this).find("Images").text());
			myFile1Data.push($(this).find("Files1").text());
			myFile2Data.push($(this).find("Files2").text());
			myFile3Data.push($(this).find("Files3").text());
			myFile4Data.push($(this).find("Files4").text());
			myFile5Data.push($(this).find("Files5").text());
			myFile6Data.push($(this).find("Files6").text());
			myFile7Data.push($(this).find("Files7").text());
			myFile8Data.push($(this).find("Files8").text());
			myFile9Data.push($(this).find("Files9").text());
			myFile10Data.push($(this).find("Files10").text());
			myHrefData.push($(this).find("Hrefs").text());
			myTitleData.push($(this).find("Titles").text());
			myBodyData.push($(this).find("Body").text());
			myBlogCount++;
		});

		myBlogStart=0;
		myBlogPager(myBlogPage);
	},

	myBlogPager = function(myBlogPage){
		myBlogResult = '';
		myPagerDisplay = '';

		myBlogPage = Number(myBlogPage);
		if(myBlogCount > myBlogMaxRows){
			myBlogStart = (myBlogPage-1)*myBlogMaxRows;
			if(myBlogPage*myBlogMaxRows>myBlogCount){
				limit = myBlogCount;
			}else{
				limit = myBlogMaxRows*myBlogPage;
			}
		}else{
			myBlogStart=0;
			limit = myBlogCount;
		}

		var vReg = new RegExp('flv$');
		var aReg = new RegExp('mp3$');
		var pReg = new RegExp('(jpg|jpeg|gif|png)$');

		var nextRows = ((myBlogPage+1)*myBlogMaxRows > myBlogCount)? myBlogCount-(myBlogPage*myBlogMaxRows) : (myBlogPage+1)*myBlogMaxRows-(myBlogPage*myBlogMaxRows);
		if(myBlogCount > myBlogMaxRows && myBlogPage == 1){
			myPagerDisplay = '<a href="javascript:void(0)" onclick="myBlogPager(\''+(myBlogPage+1)+'\');return false;">次の'+nextRows+'件を見る</a>';
		}else if(myBlogCount > myBlogMaxRows && myBlogPage > 1 && myBlogPage*myBlogMaxRows<myBlogCount){
			myPagerDisplay = '<a href="javascript:void(0)" onclick="myBlogPager(\''+(myBlogPage-1)+'\');return false;">前の'+myBlogMaxRows+'件を見る</a> | <a href="javascript:void(0)" onclick="myBlogPager(\''+(myBlogPage+1)+'\');return false;">次の'+nextRows+'件を見る</a>';
		}else if(myBlogCount > myBlogMaxRows && myBlogPage > 1 && myBlogPage*myBlogMaxRows>=myBlogCount){
			myPagerDisplay = '<a href="javascript:void(0)" onclick="myBlogPager(\''+(myBlogPage-1)+'\');return false;">前の'+myBlogMaxRows+'件を見る</a>';
		}

		for(i=myBlogStart;i<limit;i++){
			var incVideo = '';
			var incAudio = '';
			var incPhoto = '';

			if(myFile1Data[i].match(vReg)) incVideo = true;
			if(myFile1Data[i].match(aReg)) incAudio = true;
			if(myFile1Data[i].match(pReg)) incPhoto = true;
			if(myFile2Data[i].match(vReg)) incVideo = true;
			if(myFile2Data[i].match(aReg)) incAudio = true;
			if(myFile2Data[i].match(pReg)) incPhoto = true;
			if(myFile3Data[i].match(vReg)) incVideo = true;
			if(myFile3Data[i].match(aReg)) incAudio = true;
			if(myFile3Data[i].match(pReg)) incPhoto = true;
			if(myFile4Data[i].match(vReg)) incVideo = true;
			if(myFile4Data[i].match(aReg)) incAudio = true;
			if(myFile4Data[i].match(pReg)) incPhoto = true;
			if(myFile5Data[i].match(vReg)) incVideo = true;
			if(myFile5Data[i].match(aReg)) incAudio = true;
			if(myFile5Data[i].match(pReg)) incPhoto = true;
			if(myFile6Data[i].match(vReg)) incVideo = true;
			if(myFile6Data[i].match(aReg)) incAudio = true;
			if(myFile6Data[i].match(pReg)) incPhoto = true;
			if(myFile7Data[i].match(vReg)) incVideo = true;
			if(myFile7Data[i].match(aReg)) incAudio = true;
			if(myFile7Data[i].match(pReg)) incPhoto = true;
			if(myFile8Data[i].match(vReg)) incVideo = true;
			if(myFile8Data[i].match(aReg)) incAudio = true;
			if(myFile8Data[i].match(pReg)) incPhoto = true;
			if(myFile9Data[i].match(vReg)) incVideo = true;
			if(myFile9Data[i].match(aReg)) incAudio = true;
			if(myFile9Data[i].match(pReg)) incPhoto = true;
			if(myFile10Data[i].match(vReg)) incVideo = true;
			if(myFile10Data[i].match(aReg)) incAudio = true;
			if(myFile10Data[i].match(pReg)) incPhoto = true;

			var icon01 = (incVideo) ? 'http://www.monoglobe.jp/images/icon01_true.gif':'http://www.monoglobe.jp/images/icon01_none.gif';
			var icon02 = (incAudio) ? 'http://www.monoglobe.jp/images/icon02_true.gif':'http://www.monoglobe.jp/images/icon02_none.gif';
			var icon03 = (incPhoto) ? 'http://www.monoglobe.jp/images/icon03_true.gif':'http://www.monoglobe.jp/images/icon03_none.gif';

			var thumbNail = (myImageData[i] != '') ? myImageData[i] : noPhoto ;
			myBlogResult += '		<div class="side-wrap clearfix">';
			myBlogResult += '			<div class="side-thumb-img"><a href="'+myHrefData[i]+'"><img src="'+thumbNail+'" alt="'+myTitleData[i]+'" /></a></div>';
			myBlogResult += '			<div class="side-entry-cap">';
			myBlogResult += '				<p><a href="'+myHrefData[i]+'">'+myTitleData[i]+'</a></p>';
			myBlogResult += '				<p><img src="'+icon01+'" alt="" /><img src="http://www.monoglobe.jp/images/tab_line02.gif" alt="" /><img src="'+icon02+'" alt="" /><img src="http://www.monoglobe.jp/images/tab_line02.gif" alt="" /><img src="'+icon03+'" alt="" /></p>';
			myBlogResult += '				<p>'+myBodyData[i]+'</p>';
			myBlogResult += '		</div>';
			myBlogResult += '	</div>';
		}

		myBlogDisplay();

	},

	myBlogPreLoad = function(){
		myBlogResult = '';
		myBlogResult = '		<div class="loading"><img src="'+loadingImg+'" alt="loading..."></div>';
		myBlogDisplay();
	}

	$.ajax({url:myBlogListPath,type:'get',dataType:'xml',cache:false,data:{},
		beforeSend:myBlogPreLoad,
		success:myBlogResponseXML,
		error:function(){ window.alert('error!'); }
	});
}

function otherBlogListLoad(){
	var otherBlogListPath = 'http://www.monoglobe.jp/renewal/side_tab_blog.xml';
	var otherBlogResult = '';
	var otherPagerDisplay = '';

	otherBlogDisplay = function(){
		$("#other-archive").html(otherBlogResult);
		$("#other-archive-pager").html(otherPagerDisplay);
	},

	otherBlogResponseXML = function(XML){
		otherBlogCount = '';

		otherBlogData = new Array();
		otherCatIdData = new Array();
		otherImageData = new Array();
		otherFile1Data = new Array();
		otherFile2Data = new Array();
		otherFile3Data = new Array();
		otherFile4Data = new Array();
		otherFile5Data = new Array();
		otherFile6Data = new Array();
		otherFile7Data = new Array();
		otherFile8Data = new Array();
		otherFile9Data = new Array();
		otherFile10Data = new Array();
		otherHrefData = new Array();
		otherTitleData = new Array();
		otherWriterData = new Array();


		$(XML).find("Blog").each(function(){
			if($(this).find("CatId").text() != myCat){
				otherCatIdData.push($(this).find("CatId").text());
				otherImageData.push($(this).find("Images").text());
				otherFile1Data.push($(this).find("Files1").text());
				otherFile2Data.push($(this).find("Files2").text());
				otherFile3Data.push($(this).find("Files3").text());
				otherFile4Data.push($(this).find("Files4").text());
				otherFile5Data.push($(this).find("Files5").text());
				otherFile6Data.push($(this).find("Files6").text());
				otherFile7Data.push($(this).find("Files7").text());
				otherFile8Data.push($(this).find("Files8").text());
				otherFile9Data.push($(this).find("Files9").text());
				otherFile10Data.push($(this).find("Files10").text());
				otherHrefData.push($(this).find("Hrefs").text());
				otherTitleData.push($(this).find("Titles").text());
				otherWriterData.push($(this).find("Writer").text());
				otherBlogCount++;
			}
		});

		otherBlogStart=0;
		otherBlogPager(otherBlogPage);
	},

	otherBlogPager = function(otherBlogPage){
		otherBlogResult = '';
		otherPagerDisplay = '';

		otherBlogPage = Number(otherBlogPage);
		if(otherBlogCount > otherBlogMaxRows){
			otherBlogStart = (otherBlogPage-1)*otherBlogMaxRows;
			if(otherBlogPage*otherBlogMaxRows>otherBlogCount){
				limit = otherBlogCount;
			}else{
				limit = otherBlogMaxRows*otherBlogPage;
			}
		}else{
			otherBlogStart=0;
			limit = otherBlogCount;
		}

		var vReg = new RegExp('flv$');
		var aReg = new RegExp('mp3$');
		var pReg = new RegExp('(jpg|jpeg|gif|png)$');

		var nextRows = ((otherBlogPage+1)*otherBlogMaxRows > otherBlogCount)? otherBlogCount-(otherBlogPage*otherBlogMaxRows) : (otherBlogPage+1)*otherBlogMaxRows-(otherBlogPage*otherBlogMaxRows);
		if(otherBlogCount > otherBlogMaxRows && otherBlogPage == 1){
			otherPagerDisplay = '<a href="javascript:void(0)" onclick="otherBlogPager(\''+(otherBlogPage+1)+'\');return false;">次の'+nextRows+'件を見る</a>';
		}else if(otherBlogCount > otherBlogMaxRows && otherBlogPage > 1 && otherBlogPage*otherBlogMaxRows<otherBlogCount){
			otherPagerDisplay = '<a href="javascript:void(0)" onclick="otherBlogPager(\''+(otherBlogPage-1)+'\');return false;">前の'+otherBlogMaxRows+'件を見る</a> | <a href="javascript:void(0)" onclick="otherBlogPager(\''+(otherBlogPage+1)+'\');return false;">次の'+nextRows+'件を見る</a>';
		}else if(otherBlogCount > otherBlogMaxRows && otherBlogPage > 1 && otherBlogPage*otherBlogMaxRows>=otherBlogCount){
			otherPagerDisplay = '<a href="javascript:void(0)" onclick="otherBlogPager(\''+(otherBlogPage-1)+'\');return false;">前の'+otherBlogMaxRows+'件を見る</a>';
		}

		for(i=otherBlogStart;i<limit;i++){
			var incVideo = '';
			var incAudio = '';
			var incPhoto = '';

			if(otherFile1Data[i].match(vReg)) incVideo = true;
			if(otherFile1Data[i].match(aReg)) incAudio = true;
			if(otherFile1Data[i].match(pReg)) incPhoto = true;
			if(otherFile2Data[i].match(vReg)) incVideo = true;
			if(otherFile2Data[i].match(aReg)) incAudio = true;
			if(otherFile2Data[i].match(pReg)) incPhoto = true;
			if(otherFile3Data[i].match(vReg)) incVideo = true;
			if(otherFile3Data[i].match(aReg)) incAudio = true;
			if(otherFile3Data[i].match(pReg)) incPhoto = true;
			if(otherFile4Data[i].match(vReg)) incVideo = true;
			if(otherFile4Data[i].match(aReg)) incAudio = true;
			if(otherFile4Data[i].match(pReg)) incPhoto = true;
			if(otherFile5Data[i].match(vReg)) incVideo = true;
			if(otherFile5Data[i].match(aReg)) incAudio = true;
			if(otherFile5Data[i].match(pReg)) incPhoto = true;
			if(otherFile6Data[i].match(vReg)) incVideo = true;
			if(otherFile6Data[i].match(aReg)) incAudio = true;
			if(otherFile6Data[i].match(pReg)) incPhoto = true;
			if(otherFile7Data[i].match(vReg)) incVideo = true;
			if(otherFile7Data[i].match(aReg)) incAudio = true;
			if(otherFile7Data[i].match(pReg)) incPhoto = true;
			if(otherFile8Data[i].match(vReg)) incVideo = true;
			if(otherFile8Data[i].match(aReg)) incAudio = true;
			if(otherFile8Data[i].match(pReg)) incPhoto = true;
			if(otherFile9Data[i].match(vReg)) incVideo = true;
			if(otherFile9Data[i].match(aReg)) incAudio = true;
			if(otherFile9Data[i].match(pReg)) incPhoto = true;
			if(otherFile10Data[i].match(vReg)) incVideo = true;
			if(otherFile10Data[i].match(aReg)) incAudio = true;
			if(otherFile10Data[i].match(pReg)) incPhoto = true;

			var icon01 = (incVideo) ? 'http://www.monoglobe.jp/images/icon01_true.gif':'http://www.monoglobe.jp/images/icon01_none.gif';
			var icon02 = (incAudio) ? 'http://www.monoglobe.jp/images/icon02_true.gif':'http://www.monoglobe.jp/images/icon02_none.gif';
			var icon03 = (incPhoto) ? 'http://www.monoglobe.jp/images/icon03_true.gif':'http://www.monoglobe.jp/images/icon03_none.gif';

			var thumbNail = (otherImageData[i] != '') ? otherImageData[i] : noPhoto ;
			otherBlogResult += '		<div class="side-wrap clearfix">';
			otherBlogResult += '			<div class="side-thumb-img"><a href="'+otherHrefData[i]+'"><img src="'+thumbNail+'" alt="'+otherTitleData[i]+'" /></a></div>';
			otherBlogResult += '			<div class="side-entry-cap">';
			otherBlogResult += '				<p>'+otherWriterData[i]+'</p>';
			otherBlogResult += '				<p><img src="'+icon01+'" alt="" /><img src="http://www.monoglobe.jp/images/tab_line02.gif" alt="" /><img src="'+icon02+'" alt="" /><img src="http://www.monoglobe.jp/images/tab_line02.gif" alt="" /><img src="'+icon03+'" alt="" /></p>';
			otherBlogResult += '				<p><a href="'+otherHrefData[i]+'">'+otherTitleData[i]+'</a></p>';
			otherBlogResult += '		</div>';
			otherBlogResult += '	</div>';
		}

		otherBlogDisplay();

	},

	otherBlogPreLoad = function(){
		otherBlogResult = '';
		otherBlogResult = '		<div class="loading"><img src="'+loadingImg+'" alt="loading..."></div>';
		otherBlogDisplay();
	}

	$.ajax({url:otherBlogListPath,type:'get',dataType:'xml',cache:false,data:{},
		beforeSend:otherBlogPreLoad,
		success:otherBlogResponseXML,
		error:function(){ window.alert('error!'); }
	});
}

function myCategoryObtain(){
	var sc = new Array();
	sc = document.getElementsByTagName('script');

	for(i=0;i<sc.length;i++){
		var p = sc[i].getAttribute('src');
		var pReg = new RegExp('blogRightColumn\.js\?.*$');
		if(p && p.match(pReg)){
			var usr = p.split('?');
			myCat = usr[1].slice(usr[1].indexOf('=')+1);
			otherBlogListLoad();
		}
	}
}

jQuery.event.add(window,"load",function(){
	myBlogListLoad();
	myCategoryObtain();
});
