jQuery(function($){

	
	$('.user-pointer').ifixpng();
	
	$('.actions-ov .mod-action .rep').hover(function(){
		$(this).find('.content').addClass('content-hover');
	},function(){
		$(this).find('.content').removeClass('content-hover');
	});
	
	// Act now - additional information sliders
	$('#action .additional-info .slider').hide();
	$('#action .additional-info h3').click(function(e){
		e.preventDefault();
		if(!$(this).hasClass('active')){
			$(this).addClass('active').next('.slider').slideDown("slow");
		} else {
			$(this).removeClass('active').next('.slider').slideUp("slow");	
		}
	});
	
	// Store pre-written letter
	if($('.act-compose textarea').length){
		var prewritten_subject = $('.act-compose .text[name="letter_subject"]').val();
		var prewritten_body = $('.act-compose textarea').val();
		var current_selection = null;
		
		$('.act-compose input[name="letter_type"]').click(function(){
			if($(this) != current_selection){
				switch($(this).val()){
					case 'pre_written':
						$('.act-compose .text[name="letter_subject"]').val(prewritten_subject);
						$('.act-compose textarea').val(prewritten_body);
						break;
					case 'own_words':
						$('.act-compose .text[name="letter_subject"]').val('').focus();
						$('.act-compose textarea').val('');
						break;
				}
				current_selection = $(this);
			}
		});
	}
	
	// Example to load modal window from petition form submit
	$('.petition-form .submit').click(function(e){
		e.preventDefault();
		
		if(!$('#overlay').length){
			var modal_content = null;
			$.ajax({
				url: '/ajax/12.1.0_tell_multiple_friends.html',
				success:function(data){
					
					$('<div id="overlay"></div>')
						.css({width:$(document).width(), height: $(document).height(),opacity:'0'})
						.appendTo('body')
						.fadeTo("slow",0.6, function(){
							var one_box = $(data).appendTo('body');
							var modal_top = parseInt( $(document).scrollTop() + ( $(window).height() / 2 ) - ( one_box.height() / 2 ) );
							if(modal_top < 0) modal_top = 20;
							var modal_left = parseInt( ( $(window).width() / 2 ) - ( one_box.width() / 2 ) );
							one_box.css({
								display:'block',
								top: modal_top,
								left: modal_left
							});
							
							$('#overlay, #one-box .close-overlay').click(function(e){
								e.preventDefault();
								$('#one-box').remove();
								$('#overlay').fadeTo("slow",0, function(){
								$(this).remove();
							});
							
						});
				});
					
				}
			});
		}
		
	});

});