var About_Me = {

	months : ['', 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня',
			'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'],
	original_position : '',
	/*
	 * show_form : function() { $('#about_me_empty').hide();
	 * $('#about_me_text').hide(); $('#about_me_form').show(); },
	 */
	cancel : function() {
		/*
		 * if (this.original_position === 'empty') { $('#about_me_text').hide();
		 * $('#about_me_form').hide(); $('#about_me_empty').show(); } else if
		 * (this.original_position === 'text') { $('#about_me_form').hide();
		 * $('#about_me_empty').hide(); $('#about_me_text').show();
		 * $('#about_bottom_actions').show(); }
		 */
		$('#u_about_gadget_edit').hide();
		$('#u_about_gadget').show();
	},
	edit : function() {
		/*
		 * $('#about_me_text').hide(); $('#about_me_form').show();
		 * $('#about_bottom_actions').hide();
		 */

		$('#u_about_gadget_edit').show();
		$('#u_about_gadget').hide();
	},
	save : function() {
		$('#about_me_form').ajaxSubmit({
					dataType : 'xml',
					cache : false,
					success : function(xml) {
						if ($(xml).find('ok').length) {

							// $('#gadget-about').get('/ajax_about_gadget/');

							$.ajax({
										type : 'GET',
										url : '/ajax_about_gadget/',
										cache : false,
										success : function(xml) {
											$('#u_about').html(xml);
											// this.original_position == 'text';
										}
									});

						}
					}
				});
	},
	clear : function() {
		$.ajax({
			type : 'GET',
			url : '/remove_details/',
			cache : false,
			dataType : 'xml',
			success : function(xml) {
				if ($(xml).find('ok').length) {
					this.original_position == 'empty';
					$('#about_me_form').resetForm();

					reset_counters(Array('#about_me_name_counter'), Array('28'));
					reset_counters(Array('#about_me_city_counter'), Array('28'));
					reset_counters(Array('#about_me_motto_counter'),
							Array('60'));
					reset_counters(Array('#about_me_additional_counter'),
							Array('160'));

					$('#about_me_name').bind('keyup', {
								text_element_id : '#about_me_name',
								counter_element_id : '#about_me_name_counter',
								max_length : 28
							}, handle_textfield_keyup_event);
					$('#about_me_city').bind('keyup', {
								text_element_id : '#about_me_city',
								counter_element_id : '#about_me_city_counter',
								max_length : 28
							}, handle_textfield_keyup_event);
					$('#about_me_motto').bind('keyup', {
								text_element_id : '#about_me_motto',
								counter_element_id : '#about_me_motto_counter',
								max_length : 60
							}, handle_textfield_keyup_event);
					$('#about_me_additional').bind('keyup', {
								text_element_id : '#about_me_additional',
								counter_element_id : '#about_me_additional_counter',
								max_length : 160
							}, handle_textfield_keyup_event);

					$('#about_me_text').hide();
					$('#about_me_empty').show();
				}
			}
		});
	}
};

Gifts = {
	// gift_to_present : function() {
	//
	// var gift_id = $(this).attr('id').split('_').pop();
	//
	// $.ajax({
	// type : 'GET',
	// url : '/gifts/information_to_present/',
	// cache : true,
	// data : {
	// gift_id : gift_id
	// },
	// success : function(html) {
	//
	// $('#gifts_step1').hide();
	// $('#gifts_step2 .gift_info').html(html);
	// $('#gifts_step2 #send_gift').click(Gifts.present);
	// $('#present_comment').bind('keyup', { text_element_id :
	// '#present_comment', counter_element_id : '#present_comment_counter',
	// max_length: 160 }, handle_textfield_keyup_event);
	// $('#gifts_step2').show();
	// }
	// });
	//
	// return false;
	//
	// },
	// gift_presented : function() {
	// var gift_id = $(this).attr('id').split('_').pop();
	//
	// $.ajax({
	// type : 'GET',
	// url : '/gifts/presented_information/',
	// cache : true,
	// data : {
	// gift_id : gift_id
	// },
	// success : function(html) {
	//
	// //$('#gifts_step1').hide();
	// //$('#gifts_step2 .gift_info').html(html);
	// //$('#gifts_step2 #send_gift').click(Gifts.present);
	// //$('#present_comment').bind('keyup', { text_element_id :
	// '#present_comment', counter_element_id : '#present_comment_counter',
	// max_length: 160 }, handle_textfield_keyup_event);
	// //$('#gifts_step2').show();
	// //$('#presented_gifts_dialog').html(html);
	// //$('#presented_gifts_dialog').show();
	// }
	// });
	//
	// return false;
	// },
	present : function() {
		$('#gift_form a').attr('onclick', '');
		$('#gift_form a').unbind('click').click(empty);
		$('#gift_form').ajaxSubmit({
			dataType : 'xml',
			cache : false,
			success : function(xml) {
				if ($(xml).find('ok').length) {
					Gifts.close();
					$.ajax({
						type : 'GET',
						url : '/gifts/ajax_get/',
						cache : false,
						success : function(html) {
							$('#ajax_gifts').hide();
							$('#ajax_gifts').html(html);
							$('#ajax_gifts').fadeIn(500);

							tb_init('#ajax_gifts a.thickbox, #ajax_gifts area.thickbox, #ajax_gifts input.thickbox');

							// $('#gifts-prev').click(Gifts.next);

							// $('#gifts-next').click(Gifts.prev);
						}
					});
				}
			}
		});

		return false;
	},
	close : function() {
		// $('#gifts_step2').hide();
		// $('#gifts_step1').show();
		// tb_hide('#gifts_dialog');
		// $('#gifts_dialog').hide();
		// $('#gifts_dialog').dialog('close');
		tb_remove('#gifts_dialog');
	}
	/*
	 * next: function() { $.ajax({ type : 'GET', url : '/gifts/ajax_get/' +
	 * (parseInt($('#gifts_page').val())-1), data : { },
	 *
	 * cache : false, success : function(html) { $('#ajax_gifts').hide();
	 * $('#ajax_gifts').html(html); $('#ajax_gifts').fadeIn(500);
	 *
	 * tb_init('#ajax_gifts a.thickbox, #ajax_gifts area.thickbox, #ajax_gifts
	 * input.thickbox');
	 *
	 * $('#gifts-prev').click(Gifts.next);
	 *
	 * $('#gifts-next').click(Gifts.prev);
	 *  } }); return false;
	 *  }, prev: function() { $.ajax({ type : 'GET', url : '/gifts/ajax_get/' +
	 * (parseInt($('#gifts_page').val()) + 1), data : { },
	 *
	 * cache : false, success : function(html) { $('#ajax_gifts').hide();
	 * $('#ajax_gifts').html(html); $('#ajax_gifts').fadeIn(500);
	 *
	 * tb_init('#ajax_gifts a.thickbox, #ajax_gifts area.thickbox, #ajax_gifts
	 * input.thickbox');
	 *
	 * $('#gifts-prev').click(Gifts.next);
	 *
	 * $('#gifts-next').click(Gifts.prev);
	 *  } }); return false; }
	 */
	// show: function() {
	// tb_show('#gifts_dialog');
	// $('#gifts_dialog').dialog({
	// modal: true,
	// close: Gifts.close
	// });
	// $('#gifts_dialog').show();
	// return false;
	// }/*,
	// back: function() {
	// $('#gifts_step1').show();
	// tb_remove();
	// tb_show(null,
	// '#TB_inline?width=30&height=30&modal=true&inlineId=gifts_dialog', false);
	// }
}

var gadget_photoalbums_prev = function() {
	$.ajax({
		type : 'GET',
		url : '/ajax_photoalbums_gadget/',
		data : {
			current_page : parseInt($('#photoalbums_gadget input[type=hidden]')
					.val(), 10)
					- 1
		},

		success : function(html) {
			$('#photoalbums_gadget').before(html).remove();

			$('#photoalbums_gadget .arrowleft').click(gadget_photoalbums_prev);

			$('#photoalbums_gadget .arrowright').click(gadget_photoalbums_next);
		}
	});

	return false;
}

var gadget_photoalbums_next = function() {
	$.ajax({
		type : 'GET',
		url : '/ajax_photoalbums_gadget/',
		data : {
			current_page : parseInt($('#photoalbums_gadget input[type=hidden]')
					.val(), 10)
					+ 1
		},

		success : function(html) {
			$('#photoalbums_gadget').before(html).remove();

			$('#photoalbums_gadget .arrowleft').click(gadget_photoalbums_prev);

			$('#photoalbums_gadget .arrowright').click(gadget_photoalbums_next);
		}
	});

	return false;
}

var gadget_new_reload = function() {

	$.ajax({
				data : {},
				url : '/ajax_get_new/',
				type : 'GET',
				dataType : 'html',
				cache : false,
				success : function(html) {
					$('#gadget-new').before(html).remove();
					$('#gadget-new #what_new').hide();
					$('#gadget-new #what_new').fadeIn(500);

					$('#refresh_new').click(gadget_new_reload);
				}

			});

	return false;

}

$(document).ready(function() {

    $('.carousel ul').jcarousel({
        scroll : 6
    });

	/* Табы с полями для записи сообщений */

	$("#action_tabs > ul").tabs({
				selected : null
			});

	$('#action_tabs > ul').bind('tabsselect', (function() {

		$('#menuelement_0').removeClass('ui-tabs-selected');

		$('#quotation').hide();
		$('#bug').hide();
	}));

	$('#action_tabs ul.menu li[class!=first]').click(function() {

				var tab = $(this).attr('id').split('_').pop();

				alert(tab);

				$("#action_tabs > ul").tabs({
							select : tab
						});

				return false;
			});

	$("#action_tabs a.switcher.quotation").click(function() {
				$('#idea').hide();
				$('#bug').hide();
				$('#quotation').show();

				return false;
			});

	$("#action_tabs a.switcher.idea").click(function() {
				$('#idea').show();
				$('#bug').hide();
				$('#quotation').hide();

				return false;
			});

	$("#action_tabs a.switcher.bug").click(function() {
				$('#bug').show();
				$('#idea').hide();
				$('#quotation').hide();

				return false;
			});

	/* / Табы с полями для записи сообщений */

	/* Подсказки */

	/*
	 * $("#reward img").tooltip({ track : true, delay : 0, showURL : false,
	 * opacity : 1, fixPNG : true, showBody : " - ", top : 10, left : 10 });
	 */

	$("#awards img").tooltip({
				track : true,
				delay : 0,
				showURL : false,
				opacity : 1,
				fixPNG : true,
				showBody : " - ",
				top : 10,
				left : 10,
				bodyHandler : function() {
					return $(this).attr('u_hint');
				},
				extraClass : 'tooltip_username'
			});

	$(".gadget .line_ico span").tooltip({
				track : true,
				delay : 0,
				showURL : false,
				opacity : 1,
				fixPNG : true,
				showBody : " - ",
				top : 10,
				left : 10
			});
	/* / Подсказки */

	/* Информация о пользователе */

	$('#refresh_new').click(gadget_new_reload);

	$('#photoalbums_gadget .arrowleft').click(gadget_photoalbums_prev);

	$('#photoalbums_gadget .arrowright').click(gadget_photoalbums_next);
	/* / Информация о пользователе */

	/* Подарки */

	$('#gifts_step1 ul li a').click(Gifts.gift_to_present);
	$('#send_gift').click(Gifts.present);

	$('#gifts-prev').click(Gifts.next);

	$('#gifts-next').click(Gifts.prev);

	$('#u_gadget_friends_link').click(function() {
		$('#u_gadget_enemies').hide();
		$('#u_gadget_friends').show();

		$(this).removeClass('noselect');
		$('#u_gadget_enemies_link').addClass('noselect');

		return false;
	});

    $('#u_gadget_enemies_link').click(function() {
        $('#u_gadget_friends').hide();
        $('#u_gadget_enemies').show();

        $(this).removeClass('noselect');
        $('#u_gadget_friends_link').addClass('noselect');

        return false;
    });

    $('#u_gadget_general_link').click(function() {
		$('#u_gadget_prof').hide();
		$('#u_gadget_general').show();

		$(this).removeClass('noselect');
		$('#u_gadget_prof_link').addClass('noselect');

		return false;
	});

    $('#u_gadget_prof_link').click(function() {
        $('#u_gadget_general').hide();
        $('#u_gadget_prof').show();

        $(this).removeClass('noselect');
        $('#u_gadget_general_link').addClass('noselect');

        return false;
    });





		// $('#gifts .clip a').click(Gifts.gift_presented);

		// $('#gifts_dialog').dialog();

		// $('#make_present').click(Gifts.show);

		// $('#make_present').click(function() {
		// $('.ui-dialog').height(500)
		// return false;
		// });

	});