var current_flv_id;

function flv_show_comments(id) {
    if($('CommentProto')) {
	CommentProto = $('CommentProto');
	if(CommentProto)
    	    CommentProto.removeAttribute('id');
    }
    if(!CommentProto)
	return;
    var all_c = $('AllComments');
    $A(all_c.childNodes).each(function(node){
	if(node != CommentProto)
	    all_c.removeChild(node);
	
    });
    var randpar = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
    new Ajax.Request(
        '/comments',
            {
               method: 'get',
               parameters: { action: 'get', file_id: id, rand: randpar },
               onSuccess: function(oReq) {
                    eval('data='+oReq.responseText);
                    if(data.status == 'OK') {
                        for(var i=0;i < data.comments.length;i++) {
                            comment(data.comments[i].date,data.comments[i].nickname,data.comments[i].note);
                        }
                    }
               },
               onFailure: function () { }
            }
        );
}

function play(id,name,description) {
    $('song_name').update(name);
    $('song_description').update(description);
    if(!description) {
        $('song_descr_tr').hide();
    }
    else {
	$('song_description').update(description);
        $('song_descr_tr').show();
    }
    $('song_id').href = "/" + id;
    $('flash_video').update(
        "<object height=\"450\" width=\"600\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,19,0\"" +
         "classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\">"+
         "<param value=\"true\" name=\"allowFullScreen\"/>"+
         "<param value=\"way=http://wyw.webfile.ru/video/"+id+
         "&swf=http://webfile.ru/flash/player.swf&w=400&h=340&skin=white&pic=http://webfile.ru/images/wyw/wf_video.gif&comment="+
         name+"&autoplay=0&tools=1&volume=70\" name=\"FlashVars\"/>"+
         "<param value=\"http://webfile.ru/flash/player.swf\" name=\"movie\"/>"+
         "<param value=\"#ebedda\" name=\"bgcolor\"/>"+
         "<embed height=\"450\" width=\"600\" type=\"application/x-shockwave-flash\""+
         "flashvars=\"way=http://wyw.webfile.ru/video/"+
         id+"&skin=white&pic=http://webfile.ru/images/wyw/wf_video.gif&comment="+
         name+"&autoplay=0&tools=1&volume=70\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\""+
         "quality=\"high\" bgcolor=\"#ebedda\" allowfullscreen=\"true\" src=\"http://webfile.ru/flash/player.swf\"/>"+
         "</object>");
    current_flv_id = id;
    flv_show_comments(id);
}

function flv_add_comment() {
    var randpar = Math.round(10000*Math.random())+'0'+Math.round(10000*Math.random());
    var nick = "";
    if($('nickname') && $('nickname').value)
        nick = $('nickname').value;
    var email = "";
    if($('email') && $('email').value)
        email = $('email').value;

    new Ajax.Request(
        '/comments',
        {
            method: 'get',
            parameters: { action: 'add', file_id: current_flv_id, note: $('new_comment').value, nick: nick, email: email, rand: randpar },
            onSuccess: function(oReq) {
                eval('data='+oReq.responseText);
                if(data.status == 'OK')
                  {
                    var now = get_date();
                    if(!nick)
                        nick = 'anonymous';
                    comment(now,nick,$('new_comment').value);
                    $('new_comment').value='';
                    $('email').value='';
                  }
                else
                  {
                    alert('Ошибка');
                  }
            },
            onFailure: function () { alert('Ошибка'); }
        }
    );
    return false;
}

