/* 
 * Twitterからのストリームを表示
 */
function startStream()
{
    getStream();
    if (hash != '') {
        getStreamHash(hash);
    }
    timer = setTimeout("startStream()", 60 * 1000);
}

function getStream()
{
    var url = '/comike/stream/get';
    var pars = '';
    Element.show('loading');
    var myAjax = new Ajax.Request(
        url, {
            method: 'post',
        	parameters: pars,
            onComplete: function(req) {
                Element.update('stream', req.responseText);
                Element.hide('loading');
            }
        }
    );
}

function getStreamHash(tag)
{
    var url = '/comike/stream/get';
    var pars = 'tag=' + encodeURIComponent(tag);
    Element.show('loading');
    var myAjax = new Ajax.Request(
        url, {
            method: 'post',
        	parameters: pars,
            onComplete: function(req) {
                Element.update('stream-circle', req.responseText);
                Element.hide('loading');
            }
        }
    );
    $('stream-tab2-more').setAttribute('href', 
    		'http://search.twitter.com/search?ors='
    		+ encodeURIComponent('http://twitcomike.jp/' + tag) + '+'
    		+ encodeURIComponent('http://twitcmap.jp/' + tag)
    );
}

function addChat(status)
{
    var url = '/comike/stream/add';
    var pars = 'status=' + encodeURIComponent(status);
    // 現在選択しているタブがサークル情報の場合、サークルURLも付加する
    var alltab = tabView.get('tabs');
    var acttab = tabView.get('activeTab');
    if (alltab[1] == acttab) {
        pars += '&tag=' + encodeURIComponent(hash);
        if ($('addinfo').checked) {
            pars += '&addinfo=1';
        }
    }
    
    Element.show('loading');
    var myAjax = new Ajax.Request(
        url, {
            method: 'post',
        	parameters: pars,
            onComplete: function(req) {
                new Insertion.Top('stream-lines', req.responseText);
                // もしタグ指定で発言した場合、サークルの方にも追加する
                if (req.responseText.match(/<\!\-\- (.+) \-\->/)) {
                    new Insertion.Top('stream-lines-circle', req.responseText);
                }
                $('status').value = '';
                $('status2').value = '';
                Element.hide('loading');
            }
        }
    );
}

