var GoogleAjaxFeedApi_maregAndSort = function(name)
{ this.name = name; this.timerId; this.idView = null; this.sortKey = null; this.sortMode = "desc"; this.tag = ""; this.arrayRssUrl = new Array(); this.arrayMergeRss = new Array(); this.arrayRss = new Array(); this.flgLast = false; this.set_idView = function(idView)
{ this.idView = idView;}
this.set_sortKey = function(sortKey)
{ this.sortKey = sortKey;}
this.set_sortMode = function(sortMode)
{ this.sortMode = sortMode;}
this.add_feed = function(url, acq, siteName)
{ this.arrayRssUrl.push( {"url" : url, "acq" : acq, siteName : siteName} );}
this.batch = function()
{ for(var y = 0, cnt = this.arrayRssUrl.length; y < cnt; y++)
{ this.open_feed(y);}
this.timerId = setInterval( this.name + ".merge();", 100);}
this.open_feed = function(y)
{ this.arrayRss[y] = new Array(); var name = this.name; var feed = new google.feeds.Feed(this.arrayRssUrl[y].url); feed.setNumEntries(this.arrayRssUrl[y].acq); feed.load
( function(result)
{ if(!result.error)
{ eval( name + ".feed2array(result, y)" );}
} );}
this.feed2array = function(result, y)
{ var year; var month; var day; var time; var week; var tmp; for(var x = 0, cnt = result.feed.entries.length; x < cnt; x++)
{ this.arrayRssUrl[y].title = result.feed.title; this.arrayRssUrl[y].link = result.feed.link; this.arrayRssUrl[y].description = result.feed.description; this.arrayRssUrl[y].author = result.feed.author; var entry = result.feed.entries[x]; tmp = entry.publishedDate.split(' '); month = tmp[2]; switch(month)
{ case 'Jan': month = '00'; break; case 'Feb': month = '01'; break; case 'Mar': month = '02'; break; case 'Apr': month = '03'; break; case 'May': month = '04'; break; case 'Jun': month = '05'; break; case 'Jul': month = '06'; break; case 'Aug': month = '07'; break; case 'Sep': month = '08'; break; case 'Oct': month = '09'; break; case 'Nov': month = '10'; break; case 'Dec': month = '11'; break;}
var dArr = entry.publishedDate.split(' '); var tArr = dArr[4].split( ':' ); var GlobalDate = new Date( Date.UTC(dArr[3], month, dArr[1], tArr[0], tArr[1], tArr[2]) ); var LocalDate = new Date
( GlobalDate.getFullYear(), GlobalDate.getMonth(), GlobalDate.getDate(), GlobalDate.getHours() + 7, GlobalDate.getMinutes(), GlobalDate.getSeconds() ); LocalDate+= ""; tmp = LocalDate.split(' '); if( LocalDate.match(/UTC/) )
{ year = tmp[5]; month = tmp[1]; day = tmp[2]; time = tmp[3]; tmp[99] = tmp[3].replace(/:/g, ""); week = tmp[0].replace(/,/g, "");}
else if( LocalDate.match(/GMT/) )
{ year = tmp[3]; month = tmp[1]; day = tmp[2]; time = tmp[4]; tmp[99] = tmp[4].replace(/:/g, ""); week = tmp[0].replace(/,/g, "");}
switch(day)
{ case "0" :
case "1" :
case "2" :
case "3" :
case "4" :
case "5" :
case "6" :
case "7" :
case "8" :
case "9" : day = "0" + day;}
switch(month)
{ case 'Jan': month = '01'; break; case 'Feb': month = '02'; break; case 'Mar': month = '03'; break; case 'Apr': month = '04'; break; case 'May': month = '05'; break; case 'Jun': month = '06'; break; case 'Jul': month = '07'; break; case 'Aug': month = '08'; break; case 'Sep': month = '09'; break; case 'Oct': month = '10'; break; case 'Nov': month = '11'; break; case 'Dec': month = '12'; break;}
this.arrayRss[y][x] = {}; this.arrayRss[y][x].rssNo = y; this.arrayRss[y][x].date = year + month + day; this.arrayRss[y][x].datetime = year + month + day + tmp[99]; this.arrayRss[y][x].year = year; this.arrayRss[y][x].month = month; this.arrayRss[y][x].day = day; this.arrayRss[y][x].time = time; this.arrayRss[y][x].week = week; this.arrayRss[y][x].title = entry.title; this.arrayRss[y][x].link = entry.link; this.arrayRss[y][x].content = entry.content; this.arrayRss[y][x].contentSnippet = entry.contentSnippet;}
if(y == this.arrayRssUrl.length - 1)
{ this.flgLast = true;}
}
this.merge = function()
{ if(true != this.flgLast)
{ return;}
clearInterval(this.timerId); var sortKey = this.sortKey; var sortMode= this.sortMode; for(var y = 0, cntY = this.arrayRss.length; y < cntY; y++)
{ for(var x = 0, cntX = this.arrayRss[y].length; x < cntX; x++)
{ this.arrayMergeRss.push(this.arrayRss[y][x]);}
}
this.arrayMergeRss.sort
( function(a, b)
{ if("asc" === sortMode)
{ return a[sortKey] < b[sortKey] ? -1 : 1;}
else
{ return a[sortKey] > b[sortKey] ? -1 : 1;}
} ); this.make_tag();}
this.make_tag = function()
{ this.tag = ""; for(var y = 0, cnt = this.arrayMergeRss.length; y < cnt; y++)
{ this.tag+= this.arrayMergeRss[y].date + "->[" + this.arrayRssUrl[ this.arrayMergeRss[y].rssNo ].siteName + "]" + this.arrayMergeRss[y].title + "\n";}
alert(this.tag);}
}

