$(function(){
	$.ajax({
    url: '/xml/news_all.xml',
    type: 'GET',
    dataType: 'xml',
    timeout: 1000,
    error: function(){
        alert('Error loading XML document');
    },
    success: function(xml){
		$(xml).find('entry').each(function(){
			var MAX_CONTENT_LENGTH = 28;
			var regexp = new RegExp(/<.*?>/g);
			var title = $(this).find('title').text().replace(regexp, '');
			var title = title.length > MAX_CONTENT_LENGTH ?
				title.substr(0, MAX_CONTENT_LENGTH) + '…' : title;
			var date = $(this).find('date').text();
			var url = $(this).find('url').text();
			var category = $(this).find('category').text();
			var categoryIcon;
			if(category=="学園"){
				categoryIcon = '<img src="/share/images/icon_school.gif" width="43" height="15" alt="学園" class="icon" />'
			}else if(category=="入試"){
				categoryIcon = '<img src="/share/images/icon_test.gif" width="43" height="15" alt="入試" class="icon" />'
			}else if(category=="就職"){
				categoryIcon = '<img src="/share/images/icon_recruit.gif" width="43" height="15" alt="就職" class="icon" />'
			}else if(category=="クラブ"){
				categoryIcon = '<img src="/share/images/icon_club.gif" width="43" height="15" alt="クラブ" class="icon" />'
			}else if(category=="図書館"){
				categoryIcon = '<img src="/share/images/icon_library.gif" width="43" height="15" alt="図書館" class="icon" />'
			}
			var newNum = $(this).attr('new');
			var newIcon;
			if(newNum!=0){
				newIcon = '<img src="/share/news/images/newsslide_icon_new.gif" alt="new" width="30" height="15" class="new" />';
			}else{
				newIcon = '';
			}
			$('#news ul').append('<li>'+date+categoryIcon+'<br /><a href="'+url+'">'+title+'</a>'+newIcon+'</li>');
    	});
		
		$('#news ul').bxSlider({
			mode: 'vertical',
			controls: false,
			pager: false,
			auto: true,
			speed: 500,
			pause: 7000
		});
	}
	});
});
