// JavaScript Document

$(function(){

	Cufon.replace('.cufon_text_shadow', { fontFamily: 'Cooper Black', textShadow: '#374122 1px 1px' });
	Cufon.replace('.cufon_text_light_shadow', { fontFamily: 'Cooper Black', textShadow: '#ffffff 1px 1px' });
	Cufon.replace('.cufon_text', { fontFamily: 'Cooper Black' });
	Cufon.now();

	$("a[href^=http://]").attr("target", "_blank");

	$('#more_popular_twititionsMonth').click(function(){

		//get current offset
		var offset = ($("#mostPopularUL > ul").length);

		pageoffset = offset * 3;

		$.ajax({
		  url: 'ajax_PopularTwitions/'+pageoffset+'/',
		  success: function(data) {
			// append hidden element to the page
			$(data).appendTo($('#mostPopularUL'));
			// now slide the element
			$('#id_'+pageoffset).slideDown('slow');

			//if we're on an offset of 3 (ie. 10 are going to be on the page) remove the more link
			if(offset == 3){$('#more_popular_twititionsMonth').toggle();}
			if(offset == 1){$('#less_popular_twititionsMonth').toggle();}
		  }
		});

		return false;

	});

	$('#less_popular_twititionsMonth').click(function(){

		//get current offset
		var offset = ($("#mostPopularUL > ul").length);

		if(offset > 1){
			$("#mostPopularUL ul:nth-child("+offset+")").slideUp('slow', function(){

				$("#mostPopularUL ul:nth-child("+offset+")").remove();

			});
			
		}

		if(offset == 2){$('#less_popular_twititionsMonth').toggle();}
		if(offset == 4){$('#more_popular_twititionsMonth').toggle();}
		

		return false;

	});

	
	$('#more_popular_twititionsDay').click(function(){
		
		//get current offset
		var offset = ($("#mostPopularDayUL > ul").length);

		pageoffset = offset * 3;

		$.ajax({
		  url: 'ajax_PopularTwitionsDay/'+pageoffset+'/',
		  success: function(data) {
			// append hidden element to the page
			$(data).appendTo($('#mostPopularDayUL'));
			// now slide the element
			$('#id_'+pageoffset).slideDown('slow');

			//if we're on an offset of 3 (ie. 10 are going to be on the page) remove the more link
			if(offset == 3){$('#more_popular_twititionsDay').toggle();}
			if(offset == 1){$('#less_popular_twititionsDay').toggle();}
		  }
		});

		return false;

	});

	$('#less_popular_twititionsDay').click(function(){

		//get current offset
		var offset = ($("#mostPopularDayUL > ul").length);

		if(offset > 1){
			$("#mostPopularDayUL ul:nth-child("+offset+")").slideUp('slow', function(){

				$("#mostPopularDayUL ul:nth-child("+offset+")").remove();

			});
			
		}

		if(offset == 2){$('#less_popular_twititionsDay').toggle();}
		if(offset == 4){$('#more_popular_twititionsDay').toggle();}
		return false;

	});


});
