
	$(document).ready(function(){
		$('form.comment-form textarea, textarea.autoresize').autoResize({
			onResize: function(){},
			animate: false,
			animateCallback: function(){},
			animateDuration: 0,
			extraSpace: 0
		});
		
		$('a.like, a.dislike').click(function(e){
			var element = $(this).parent().find('.the_count');
			$.ajax({
				url: $(this).attr('href'),
				dataType: "text",
				success: function(data) {
					element.html(data);
				}
			});
			
			$(this).blur();
			return false;
		});
		
		$('fieldset.form-optional').each(function(){
			var id = $(this).attr('id');
			
			$('a.form-optional-link[rel='+id+']').click(function(){
				
				$('fieldset#'+id).slideToggle(100);
				
				return false;
			});
		});
		
		//-- jQuery cycle, features on the frontpage
		$('.fader ul').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed: 400,
			timeout: 4000,
			pause: true,
			next: '#cycle-next',
			prev: '#cycle-prev'
		});
		
		$('.fader').hover(
			function(){
				$('.fader #cycle-prev, .fader #cycle-next').fadeIn(100);
			},
			function(){
				$('.fader #cycle-prev, .fader #cycle-next').fadeOut(100);
			}
		);
		
		//-- The follow/unfollow
		$('a.follow').click(function(e){
			var link = $(this);
			var text_container = $(this).children('span');
			var url = $(this).attr('href');
			$.ajax({
				url: url,
				dataType: "json",
				success: function(data) {
					text_container.html(data.text);
					link.attr('href',data.url);
					link.removeClass('simple');
					link.removeClass('plus');
					link.addClass(data['class']);
				}
			});
			
			$(this).blur();
			return false;
		});
		
		//-- Add wish functionality
		$('a.add-wish').click(function(e){
			var link = $(this);
			var url = $(this).attr('href');
			$.ajax({
				url: url,
				//dataType: "text",
				success: function(data) {
					var form = $('<div id="add-wish-form-div" style="display: none;">'+data+'</div>');
					link.after(form);
					link.hide();
					form.slideDown(200);
				}
			});
			
			$(this).blur();
			return false;
		});
		
		//-- Block / finalize sponsorship
		$('a.accept-sponsor, a.finalize-sponsor').click(function(e){
			var link = $(this);
			var url = $(this).attr('href');
			$.ajax({
				url: url,
				dataType: "json",
				success: function(data) {
					if ( link.attr('class') == 'accept-sponsor' )
						link.remove();
					if ( link.attr('class') == 'finalize-sponsor' )
						link.parents('div.queue_item').remove();
				}
			});
			
			$(this).blur();
			return false;
		});
	});
	
	//-- Reposition the footer on short pages
	$(window).load(function(){
		repositionFooter();
	});
	
	$(window).resize(function(){
		repositionFooter();
	});
	
	function repositionFooter()
	{
		var doc = $('body').height();
		
		var sum = 0;
		sum = sum +( parseInt($('#header-area').css('margin-top')) + parseInt($('#header-area').css('padding-top')) + $('#header-area').height() + parseInt($('#header-area').css('padding-bottom')) + parseInt($('#header-area').css('margin-bottom')) );
		sum = sum +( parseInt($('#center-area').css('margin-top')) + parseInt($('#center-area').css('padding-top')) + $('#center-area').height() + parseInt($('#center-area').css('padding-bottom')) + parseInt($('#center-area').css('margin-bottom')) );
		sum = sum +( parseInt($('#footer-area').css('margin-top')) + parseInt($('#footer-area').css('padding-top')) + $('#footer-area').height() + parseInt($('#footer-area').css('padding-bottom')) + parseInt($('#footer-area').css('margin-bottom')) );
		
		var win = $(window).height();
		
		if ( doc != sum && sum < doc )
		{
			diff = doc - sum;
			var new_height = $('#footer-area').height()+diff;
			
			//alert('doc:'+doc+', sum:'+sum+', win:'+win+', diff:'+diff+', height:'+new_height);
			
			if ( !$.browser.msie )
			{
				$('#footer-area').css('height','auto !important');
				$('#footer-area').css('min-height',new_height+'px');
			}
			$('#footer-area').css('height',new_height+'px');
			
		}
		else if ( sum > doc )
		{
			$('#footer-area').css('height','250px');
			$('#footer-area').css('min-height','250px');
		}
	}
