YUI({base: '/public/javascript/yui3/'}).use('node','anim','io', function(Y) {  

	function sendGrade(){
		var grade = this.get('id') ;
		var topic_id = this.get('parentNode').get('parentNode').query('input').get('value') ;
		var good  = this.get('parentNode').get('parentNode').get('children').item(0).query('span') ;
		var bad   = this.get('parentNode').get('parentNode').get('children').item(1).query('span') ;
		var block = this.get('parentNode').get('parentNode')
		var block_height = this.get('parentNode').get('parentNode').get('height')
		
		var cfg = {
			method:'GET',
			headers: { 'X-Transaction': 'GET Example;charset:utf-8'},
			data: 'TOPIC_ID='+topic_id+'&GRADE='+grade,
			on:{
				success:function(id, o, args){
					if(o.responseText !== undefined){
						var strContent = o.responseText ;
						if(strContent.indexOf('RESULT:')>-1){
							
							var block_anim = new Y.Anim({
								node:block,
								duration: 0.5,
								to:{height:0}
							});
							
							var block_back_anim = new Y.Anim({
								node:block,
								duration: 0.5,
								to:{height:30}
							});
							
							block_anim.run() ;
							block_anim.on('end', function() {
								
								var grades_x = strContent.split(':') ;
								good.set('innerHTML',grades_x[1]) ;
								bad.set('innerHTML',grades_x[2]) ;
								block_back_anim.run() ;
								block_back_anim = null ;
								
							})
							
							block_anim = null ;
							
						}
						else{
							alert(strContent);
						}
					}
				},
				failure:function(ioId, o){
					if(o.responseText !== undefined){  
						var s = "<li>Transaction id: " + ioId + "</li>";   
						s += "<li>HTTP status: " + o.status + "</li>";   
						s += "<li>Status code message: " + o.statusText + "</li>";   
						getContent = s ;
						alert(s);
					}
				}
			}
		};
		
		var url = '/forum/topic_grade.asp' ;
		var request = Y.io(url , cfg) ;
	}

	var thumbs = Y.get(document.body).queryAll('.thumbs') ;
	if( thumbs ){
		
		thumbs.on('click',sendGrade)
		
	}
})
