jQuery(function($) {

	$(".feed_themes div:nth-child(3n)").css("padding-right", "0px").find(".icon_medium").css({
		'position': 'absolute',
		'right': 8
	});
	
	var editIcon = $("#profile_image a.edit_white_div");
	var profileEditDiv = $("#profile_editmenu");
	
	$(editIcon).hide();
	$(profileEditDiv).hide().css('opacity', '0');
	//$(profileEditDiv).hide();
	
	var profile_img = $("#profile_image img");
	var ratio = profile_img.height() / profile_img.width();
	if (profile_img.width() > 225) {
		var new_width = 225;
		var new_height = (new_width * ratio);
		profile_img.height(new_height).width(new_width);
	} else if (profile_img.height() > 300) {
		var new_height = 300;
		var new_width = ratio / new_height;
		profile_img.height(new_height).width(new_width);
	}
	
	$("#profile_image").mouseenter(function() {
		$(editIcon).fadeIn(400);
		$(editIcon).click(function(event) {
			if ($(profileEditDiv).css('opacity') == "0") 
			{
				event.preventDefault();
				$(profileEditDiv).animate({
					right: "-170",
					width: "168",
					opacity: "1"
				}, 800);
				$("#profile_image").css('z-index', '3000');
			}
			else 
			{
				event.preventDefault();
				$(profileEditDiv).animate({
					right: "+170",
					width: "0",
					opacity: "0"
				}, 800);
				$(profileEditDiv).css('display', 'none');
			}
		});
	}).mouseleave(function() {
		if ($(profileEditDiv).css('opacity') == "1") 
		{
			$(profileEditDiv).animate({
				right: "+170",
				width: "0",
				opacity: "0"
			}, 800);
			$(profileEditDiv).css('display', 'none');
		}
		$(editIcon).fadeOut(400);
	});
	
	$(profileEditDiv).mouseleave(function() {
		$(editIcon).fadeOut(400);
		if ($(profileEditDiv).css('opacity') != "0") 
		{
			$(profileEditDiv).animate({
				right: "+170",
				width: "0",
				opacity: "0"
			}, 800);
		}
	});
	
	$("#not_logged_in a.remove").click(function(event) {
		event.preventDefault();
		$(this).parent().slideUp(1000);
	});
	
	$("#user_info-content .content_option a").toggle(function() {
		$("#user_info-content #user_info_more").slideDown();
		$(this).text("Hide");
	}, function() {
		$("#user_info-content #user_info_more").slideUp();
		$(this).text("More");
	});
	
	
	/* collapsing divs below header */
	
	$(".arrow_down, .arrow_collapsed").mouseover(function() {
		$(this).addClass('alternate_static');
	}).mouseleave(function() {
		$(this).removeClass('alternate_static');
	});
	
	$(".arrow_down, .arrow_collapsed").click(function(event) {
		event.preventDefault();
		var currentParent = $(this).parent().attr('id');
		var childToCollapse = currentParent + "-content";
		$("#" + childToCollapse).slideToggle("normal");
		// here we need to put the sideways arrow i
		var className = $(this).attr('class');
		if ((className == "arrow_down alternate_static") || (className == "alternate_static arrow_down")) {
			$(this).removeClass("arrow_down").addClass("arrow_collapsed");
			$(this).parent().find("a.edit_div").hide();
		} else {
			$(this).removeClass("arrow_collapsed").addClass("arrow_down");
			$(this).parent().find("a.edit_div").show();
		}
		
	});
	
	// make admin
	$('#user_space').click(function() {
		
		api.userModify({space: 100}, function(response) {
			if (response.status_valid == 1) 
			{
				//api.ajax_response(response, '+100MB more added to user space successfully.');
				var total_space = parseFloat($('#user_space_total').html());
				$('#user_space_total').html((total_space+100));
			}
		});
		
		return false;
	});
	
	// make admin
	$('#user_admin').click(function() {
		var admin = ($(this).text() == 'Make Admin') ? 'yes' : 'no';
		api.userModify({admin: admin}, function(response) {
			if (response.status_valid == 1) 
			{
				var text = (admin == 'yes') ? 'Remove Admin' : 'Make Admin';
				$('#user_admin a').html(text);
			}
		});
		
		return false;
	});
	
	// band user
	$('#user_band').click(function() {
		var band = ($(this).text() == 'Ban') ? 'yes' : 'no';
		api.userModify({band: band}, function(response) {
			if (response.status_valid == 1) 
			{
				var text = (band == 'yes') ? 'unBan' : 'Ban';
				$('#user_band a').html(text);
			}
		});
		
		return false;
	});
	
	// delete
	$('#user_delete').click(function() {
		
		var answer = confirm("Are you sure you want to delete the user? \n all data will be deleted and there is no undo command for this.");
		
		if (answer)
		{
			api.userDelete(function(response) {
				if (response.status_valid == 1) 
				{
					alert('Successfully deleted the user, now going to home page.');
					window.location = 'http://'+$domain_only;
				}
			});
		}

		return false;
	});

});
