// Profile image selector code

TheCarbonAccount.picture_input_init = function () {
	// Find any image selector images
	$("img.picture_input").each(function () {
		var self = $(this);
		// We assume the input field is the previous element
		var input = self.prev();
		// And the selection div is the next element (it's hidden, anyway)
		var selector = self.next();
		// Position selector in the right place
		var self_offset = self.position();
		selector.css({
			position: 'absolute',
			top: self_offset.top - 64,
			left: self_offset.left + 2,
			zIndex: 2000
		});
		// Make image input 'clickable'
		self.css({cursor: "pointer"});
		self.click(function () {
			selector.toggle();
		});
		// Make the images in the popup selectable
		selector.children("img").each(function () {
			this.style.cursor = "pointer";
			$(this).click(function () {
				input.attr('value', this.src);
				self.attr('src', this.src);
				selector.hide();
			});
		});
	});
};