// JavaScript Document
$( document ).ready(function(e) {
	$( ".item_share .like" ).click( function( evt )
	{		
		nu_content = $( this ).parent().parent().attr( "id" );
		params = {
			ajax: 1,
			session: SESSION_ID,
			fb_id: $( this ).attr( "rel" ),
			nu_content: nu_content
		};
		
		if( $( this ).text().indexOf( "Desfazer" ) != - 1 )
		{
			$( this ).text( "Curtir" );
		}
		else
		{
			$( this ).append( "(Desfazer)" );
		}
		
		$.ajax(
		{
			url: BASE_URL + 'async/like',
			type: "POST",
			dataType: "json",
			data: params,
			success: $.proxy( function( response )
			{
				if( response.success )
				{
					
				}
			}, this)
		});
		
		evt.preventDefault();
		return false;
	});
	
	$( ".item_share .share" ).click( function( evt )
	{		
		nu_content = $( this ).parent().parent().parent().attr( "id" );
		
		params = {
			ajax: 1,
			session: SESSION_ID,
			fb_id: $( this ).attr( "rel" ),
			nu_content: nu_content
		};
		
		$( this ).parent().html( "Compartilhando..." );
		$.ajax(
		{
			url: BASE_URL + 'async/share',
			type: "POST",
			dataType: "json",
			data: params,
			success: $.proxy( function( response )
			{
				if( response.success )
				{
					$( this ).parent().html( "" );
					$( "#main" ).after( response.view );
					showModal();
				}
				else
				{
					if( confirm( 'Você não está mais logado. Deseja fazer o login?' ) )
					{
						document.location.href = BASE_URL + 'user/facebooklogin';
					}
				}
			}, this)
		});
		
		evt.preventDefault();
		return false;
	});
	
	$( ".bt_play" ).click( function( e )
	{
		rel = $( this ).children( ".thumb" ).attr( "rel" );
		embed = '<iframe width="460" height="300" src="http://www.youtube.com/embed/' + rel + '?autoplay=1" frameborder="0" allowfullscreen></iframe>';
		
		$( this ).parent().parent().html( embed );
	});
});
