var v_id;
var lastVideo=null;

function abrirVideo(yID){
		v_id=yID;
		lastVideo = $('a#videoBox_'+yID);
		$('div#'+yID)
			.html('')
			.show()
			.flash({swf:'http://www.youtube.com/v/'+yID+'&rel=0&autoplay=0',width:480,height:385})
			.append('<a href="javascript:;" onclick="fecharVideo(\''+yID+'\')" class="close" title="fechar"></a>');					
}
function fecharVideo(yID){
	var videoBox = $('a#videoBox_'+yID);

	$('div#'+yID).hide('def',function(){
		$('div#'+yID).html('');
		$(videoBox).fadeIn();
		lastVideo=null;
	});



}


$(document).ready(function(){
						   
	$('.videoLink').each(function(i,o){		
		$(this).attr('href','javascript:;').click(function(){
			var o = $(this);
																   
			if (lastVideo!=null){
				$('div#'+v_id).hide();
				$(lastVideo).fadeIn();
			}
														   
			v_id = $(this).attr('rel');	
			$(this).hide();
			$('div#'+v_id).html('').show().flash({swf:'http://www.youtube.com/v/'+v_id+'&rel=0&autoplay=1',width:480,height:385}).append('<a href="javascript:;" class="close"></a>');
			
			$('div#'+v_id+' .close').click(function(){$('div#'+v_id).hide('def',function(){$('div#'+v_id).html('');$(o).fadeIn();})});
			lastVideo = o;
			pageTracker._trackPageview('/video/'+v_id);
		});

	})

	$('.twtools a.good').click(function() { pageTracker._trackPageview('voto/good');	});
	$('.twtools a.bad').click(function() { pageTracker._trackPageview('voto/bad');	});
	$('.twtools a.trash').click(function() { pageTracker._trackPageview('voto/trash');	});
	$('#frmsprg').click(function() { pageTracker._trackPageview('formspring');	});
	

	
	var hide_feedback = function(){
		$('.feedback_message').fadeOut();
	};
	setTimeout(hide_feedback,5000);
	setComments();


});


function setComments(){
	$('.comments .showComments').attr('href','javascript:;').click(function(){
		var r = $(this).attr('rel');
		pageTracker._trackPageview('comments/showList/'+r);	
		$('#'+r+' .formComment').hide();
		$('#'+r+' .commentList').fadeIn();
		$('#'+r+' .closeComment').attr('href','javascript:;').click(function(){															
			$('#'+r+' .formComment').hide();
			$('#'+r+' .commentList').hide();		
		});

		
	});	
	$('.comments .showFormComments').attr('href','javascript:;').click(function(){
		var r = $(this).attr('rel');
		pageTracker._trackPageview('comments/showForm/'+r);	
		$('#'+r+' .formComment').fadeIn();
		$('#'+r+' .commentList').hide();
		jQuery.validator.messages.required = "";
		jQuery.validator.messages.email = "";
		$('#'+r+" .formComment").validate({
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					$('#'+r+" label.error").hide();
					$('#'+r+" .feedback").html('Preencha os campos corretamente').show();
				} else {
					$('#'+r+" .feedback").html('');
				}
			},
			submitHandler: function(form) {
				$('#'+r+" .feedback").html('');
				form.submit();
			}
						   
		});
		
		
		$('#'+r+' .cancelFormComment').click(function(){	
				$('#'+r+' .formComment').fadeOut('def',function(){
					 $('#'+r+" label.error").remove();
					 $('#'+r+" .formComment *").removeClass("error");
					 $('#'+r+" .feedback").hide();
				 });
				 pageTracker._trackPageview('comments/cancelForm/'+r);	
		});
	});
}


