var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26668290-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


$(function(){
	bodyID= $('body').attr('id');
	bodyCL= $('body').attr('class');
	
	$('ul#topic-path li').css('display','inline');
	$('ul#topic-path li a').after('<span>&nbsp;&gt;</span>');

	$('ul#gNav li').each(function(){
		if(bodyID == $(this).attr('id').split('-')[1]){
			$(this).find('img').css('visibility','hidden');
		}
	});

	$('#sNav dd').each(function(){
		if(bodyCL == $(this).attr('class').split('-')[1]){
			$(this).find('img').css('visibility','hidden');
		}
	});
	
	if($('.pageTop')){
		$('.pageTop').click(function(){
			$('html,body').animate({ scrollTop: 0 }, 300);
		});
	}

});



 
/* swapImg */

jQuery.fn.extend({
	swapImg: $(document).ready(function(){
		return $('.swapImg').each(function(){
			$(this).hover(
				function(){
					$(this).attr('src',$(this).attr('src').replace('_no.','_ro.'));
				},
				function(){
					$(this).attr('src',$(this).attr('src').replace('_ro.','_no.'));
				}
			);
		});
	})
});




/*-- RSS Read --*/
function rssRead(xmlId,xmlPath,trgt,dispNo){
	
	//LoadingID
	loadMsg = xmlId.split('#')[1] + 'Load';
	
	//remove
	if($('ul#' + xmlId.split('#')[1] + 'List')){
		$('ul#' + xmlId.split('#')[1] + 'List').remove();
	}
	//remove
	if($(xmlId + 'Load')){
		$(xmlId + 'Load').remove();
	}
	
	//Loading Img
	$(xmlId).ready(function (){
		var month_en = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		var month_jp = new Array('1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月');
		
		$.ajax({
			url: xmlPath,
			type: 'GET',
			dataType: 'xml',
//			cache: false,
			timeout: 10000,
			error: function(){
				$(xmlId + 'Load').remove();
				$(xmlId).html('Error loading XML doc').appendTo(xmlId);
			},
			success: function(xml){
				ulId = xmlId.split('#')[1];
				$('<ul id="' +ulId+ 'List" class="rssDisp"></ul>').appendTo(xmlId);
				items = $(xml).find('item').slice(0,dispNo);
		    	items.each(function(){
		    		rssLnk = $(this).find('link:first').text();
		    		rssTtl = $(this).find('title:first').text();
		    		rssDsc = $(this).find('description:first').text();
		    		rssPub = $(this).find('pubDate:first').text();
		    		for(m=0; m<month_en.length; m++){
		    			if(rssPub.split(' ')[2] == month_en[m]){
		    				wMonth = month_jp[m];
		    			}
		    		}
		    		if(rssLnk != ''){
			    	$('<li></li>')
						.html('<dl><dt><span>■'+ rssPub.split(' ')[3] +'年'+ wMonth + rssPub.split(' ')[1] +'日' + '</span></dt><dd><a href="' +rssLnk+ '" target="'+rssDsc+'">' +rssTtl+ '</a></dd></dl>')
						.appendTo('#' +ulId+ 'List');
					}else{
			    	$('<li></li>')
						.html('<dl><dt><span>■'+ rssPub.split(' ')[3] +'年'+ wMonth + rssPub.split(' ')[1] +'日' + '</span></dt><dd>' +rssTtl+ '</dd></dl>')
						.appendTo('#' +ulId+ 'List');
					}
			    });
				$(xmlId + 'Load').remove();
			}
		});
	});
}
