Community = {
	
	Init : function()
	{
		$('div.profile_results').css('opacity', 0);
				
	}
	
}

Community.Profile = {
    
  Search : function(type, value, event) {

    /////////////////////////////////////////////////////////////
    // prevent default event
    
    event.preventDefault();
    
		if($('div.profile_results').is(':visible'))
		{
			$('div.profile_results').animate({ height : 'toggle', opacity: 0 }, { easing: 'easeOutExpo', duration: 500 });
		}
		
    /////////////////////////////////////////////////////////////
    // remove error class
    
    $('input#searchprofile').removeClass('error');
    
    /////////////////////////////////////////////////////////////
    // bind focus event to clear errors on fresh submit

		$('input#searchprofile').bind('focus', function()
    {
      $('input#searchprofile').removeClass('error');
      
			if($(this).val() == 'Bitte geben Sie mindestens 3 Zeichen an.')
			{
        $(this).val('')
      }
    });

    /////////////////////////////////////////////////////////////
    // prevent inputs with less than 3 charakters

    if($('input#searchprofile').val() == 'Bitte geben Sie mindestens 3 Zeichen an.')
    {
      $('input#searchprofile').val('');
        return false;
    }   
    
    /////////////////////////////////////////////////////////////
    // add loading class to input field

		$('div.profile_search form.form input.text').addClass('load');
    
		if(type == 'keyword')
		{
			var keyword = $('input#searchprofile').val();
		
			if(keyword.length < 3) {
				$('input#searchprofile').val('Bitte geben Sie mindestens 3 Zeichen an.');
					$('div.profile_search form.form input.text').removeClass('load');
						$('input#searchprofile').addClass('error');
							return false;
			}
			
  	  /////////////////////////////////////////////////////////////
	    // set a small timeout to prevent screenflickering
			
			setTimeout(function()
			{
				jQuery.post("index.php?article_id=134",
				{
					networksearchtype : $('div.profile_search').attr('id'),
					searchbykeyword   : keyword
				},
				function(data)
				{
					$('div.profile_results').empty();
					$('div.profile_results').append(data);
					$('table.profile_results_table tr td').eq(3).css('border', 'none');
					$('div.profile_results').animate({ height : 'toggle', opacity: 1 }, { duration: 500 });
					$('div.profile_search form.form input.text').removeClass('load');
				});
			}, 1000);
		
		} else if (type == 'tag')
		{
			$('input#searchprofile').val('');
			
			var tag = value;

  	  /////////////////////////////////////////////////////////////
	    // set a small timeout to prevent screenflickering
			
			setTimeout(function()
			{
				jQuery.post("index.php?article_id=134",
				{
					networktagtype : $('div.profile_tags').attr('id'),
					searchbytag : tag
				},
				function(data)
				{
					$('div.profile_results').empty();
					$('div.profile_results').append(data);
					$('table.profile_results_table tr td').eq(3).css('border', 'none');
					$('div.profile_results').animate({ height : 'toggle', opacity: 1 }, { duration: 500 });
					$('div.profile_search form.form input.text').removeClass('load');
				});
			}, 1000);
		} else
		{
		 return false;
		}
		
		return false;
      
  },

  Paginate : function(type, value, page, event) {

    /////////////////////////////////////////////////////////////
    // prevent default event
    
    event.preventDefault();
        
		if(type == 'keyword')
		{
    	/////////////////////////////////////////////////////////////
    	// add loading class to input field

			$('table.profile_results_pagination p').addClass('load');
			$('table.profile_results_table td').animate({ opacity : 0.25 }, 500);
			
			var keyword = value;
		
  	  /////////////////////////////////////////////////////////////
	    // set a small timeout to prevent screenflickering
			
			setTimeout(function()
			{
				jQuery.post("index.php?article_id=134",
				{
					networksearchtype : $('div.profile_search').attr('id'),
					searchbykeyword : keyword,
					next : page
				},
				function(data)
				{
					$('div.profile_results').empty();
					$('div.profile_results').append(data);
					$('table.profile_results_table tr td').eq(3).css('border', 'none');
					$('table.profile_results_table td').css({ opacity : 0.25 }).animate({ opacity : 1 }, 500);
				})
			}, 1000);
		
		} else if (type == 'tag')
		{
    	/////////////////////////////////////////////////////////////
    	// add loading class to input field

			$('table.profile_results_pagination p').addClass('load');
			$('table.profile_results_table td').animate({ opacity : 0.25 }, 500);

			var tag = value;

  	  /////////////////////////////////////////////////////////////
	    // set a small timeout to prevent screenflickering
			
			setTimeout(function()
			{
				jQuery.post("index.php?article_id=134",
				{
					networktagtype : $('div.profile_tags').attr('id'),
					searchbytag : tag,
					next : page
				},
				function(data)
				{
					$('div.profile_results').empty();
					$('div.profile_results').append(data);
					$('table.profile_results_table tr td').eq(3).css('border', 'none');
					$('table.profile_results_table td').css({ opacity : 0.25 }).animate({ opacity : 1 }, 500);
				});
			}, 1000);
		} else if (type == 'newest')
		{
    	/////////////////////////////////////////////////////////////
    	// add loading class to input field

			$('table.profile_activists_pagination p').addClass('load');
			$('table.profile_activists_results td').animate({ opacity : 0.25 }, 500);
			
  	  /////////////////////////////////////////////////////////////
	    // set a small timeout to prevent screenflickering
			
			setTimeout(function()
			{
				jQuery.post("index.php?article_id=135",
				{
					networktype : $('div.profile_network').attr('id'),
					next : page
				},
				function(data)
				{
					$('div.profile_network').empty();
					$('div.profile_network').append(data);
					$('table.profile_activists_results tr td').eq(3).css('border', 'none');
					$('table.profile_activists_results td').css({ opacity : 0.25 }).animate({ opacity : 1 }, 500);
				});
			}, 1000);
			
		}else
		{
		 return false;
		}
		
		return false;
      
  },
	
	ToggleActivists : function(element, event)
	{
		event.preventDefault();
		
		var container = $('div.profile_network');
		
		$(element).toggleClass('open');
		
		if(container.is(':visible')) {
			container.animate({ height : 'toggle', opacity: 0 }, { easing: 'easeOutExpo', duration: 500 });
		} else {
			container.animate({ height : 'toggle', opacity: 1 }, { easing: 'easeOutExpo', duration: 500 });
		}
	},
	
	ToggleResults : function(element, event)
	{
		event.preventDefault();
		
		var container = $('div.profile_results');
		
		if(container.is(':visible')) {
			container.animate({ height : 'toggle', opacity: 0 }, { easing: 'easeOutExpo', duration: 500 });
		} else {
			container.animate({ height : 'toggle', opacity: 1 }, { easing: 'easeOutExpo', duration: 500 });
		}
	}

}
