$(function() {
	$('#contents').masonry({
		columnWidth: 9,
		itemSelector: '.box:visible',
		animate: true
	});
	
	if($.os.name == 'iphone' || $.os.name == 'ipod' || $.os.name == 'ipad') {
		$('div#whatshinto').html('<p><img src="images/shinto_logo.jpg" width="364" height="205" /></p>');
	} else {
		swfobject.embedSWF("images/shinto.swf", "whatshinto", "364", "205", "9.0.0", "images/expressInstall.swf", {}, {menu:"false", wmode:"transparent"});
	}

	$.ajax({
		url: "http://www.shinto-tsushin.co.jp/cms/whatsnew/feed/",
		async: true,
		cache: false,
		dataType:"xml",
		error: function(){
			$('#whatsnew').css("display", "none");
   		},
		success: function(xml){
			$('#whatsnew').html('');
			$(xml).find('item').each(function(i){
                if ( i > 5 ) {
					return false;
                }
				var title = $(this).find('title').text();
				var url = $(this).find('link').text();
				var arr;
				var date = dateParse($(this).find('pubDate').text());
				$('#whatsnew').append('<dt>□'+date[0]+'</dt><dd><a href="'+url+'">'+title+'</a></dd>');
    		});
		}
	});
});

function dateParse(str){
    var objDate = new Date(str);
    var nowDate = new Date();
    myDay = Math.floor((nowDate.getTime()-objDate.getTime()) / (1000*60*60*24)) + 1;
    if (myDay < 15 ){
        var newMsg = '&nbsp;<img src="./images/new.gif" />';
    } else {
        var newMsg = '';
    }
    var year = objDate.getFullYear();
    var month = objDate.getMonth() + 1;
    var date = objDate.getDate();
    if ( month < 10 ) { month = "0" + month; }
    if ( date < 10 ) { date = "0" + date; }
    str = year + '.' + month + '.' + date;
    rtnValue = new Array(2);
    rtnValue[0] = str;
    rtnValue[1] = newMsg;
    return rtnValue;
}

function remove_newline(text){
	text = text.replace(/\r\n|\n|\<br \/\>|\<div(.+?)\>|\<\/div\>|\<a(.+?)\<\/a\>/g, "");
	return text;
}
