$('window').load(function(){
	/*posicion del footer*/
	var Wheight = $(window).height(); //TAMANO DE VENTANA
	var Bheight = $('body').height(); //TAMANO DEL BODY
	//SI EL BODY ES INFERIOR A LA VENTANA SE POSICIONA ABAJO DEL TODO EL FOOTER
	if (Bheight < Wheight) {
		$('.footer').css({'position': 'absolute', 'bottom': '0'});
	};
});

$('document').ready(function(){

	/*hace linkables los tr*/
	$('.linked').click(function(){
		window.location = $(this).attr('href');
	});

	// Show hide help sections
	$('.close-help-action').click(function(e) {
		$(this).closest('.close-help-box').hide(500);
	});
	$('.show-help-action').click(function(e) {
		$('.close-help-box').show(500);
	});

	/*oculta sub-box*/
	$('.sub-box').hide();
	/*oculta/muestra sub-box al hacer click en boton desplegable*/
	$('.price-player .show-sub-box').toggle(
		function(){
			$(this).closest('.box-content').siblings('.sub-box').slideDown(200);
			$(this).removeClass('down').addClass('up');
		},
		function(){
		$(this).closest('.box-content').siblings('.sub-box').slideUp(200);
		$(this).removeClass('up').addClass('down');
	});

	$('#list-position .system-position a').click(function(e){
		e.preventDefault();
		$('.system-position a.blue').removeClass('blue').addClass('grey');
		$(this).removeClass('grey').addClass('blue');
		var system = $(this).attr('href');
		$('.visible').fadeOut('slow', function(){
			$(this).removeClass('visible').addClass('hidden');
			$(system).fadeIn('slow').addClass('visible');
		});
		// remove all forecolor on the table
		$('#row-player tr').removeClass('bl-blue');

		// add class to current player on the campo
		$(system + ' li').each(function(){
			$('#row-player-' + $(this).attr('player')).addClass('bl-blue');
		});
		//return(false);
	});

	// ------manager section-----
	// ajax proccess
	$('#ajax-proccess').ajaxStart(function(e){
		$(this).show();
	});
	$('#ajax-proccess').ajaxStop(function(e){
		$(this).hide();
	});

	// ------message section-----
	// show and hide private flag
	$('#message_private_flag').live('click', function(e){
		//e.preventDefault();
		if ($('#message_private_flag').is(':checked')) {
			$('#message_private_flag').attr('checked', 'checked');

			$('#message_private_flag_text').show();
			$('#id_manager').show();
		} else {
			$('#message_private_flag').removeAttr('checked');
			$('#message_private_flag_text').hide();
			$('#id_manager').hide();
		}
	});

	// show and hide new-message form
	$('#show-new-message').click(function(e) {
		e.preventDefault();
		$('#new-message').slideDown();
	});
	$('#hide-new-message').live('click', function(e) {
		e.preventDefault();
		$('#new-message').slideUp();
	});

	/*muestra comentarios en pantalla tablon*/
	$('.show-answers').live('click', function(e) {
		e.preventDefault();
		if ($(this).hasClass('down')) {
			$(this).removeClass('down').addClass('up').closest('tr').next('tr').find('.answers').slideDown(800);
		} else {
			$(this).removeClass('up').addClass('down').closest('tr').next('tr').find('.answers').slideUp(800);
			$(this).parents('tr').next().find('.exclamation').removeClass('exclamation')
		}
	});


	/*muestra/cierra caja respuesta en pantalla tablon*/
	$('.show-reply').live('click', function(e) {
			e.preventDefault();
			//var controlador = $(this).closest('tr').next('tr').find('.reply').hasClass('close');
			//if (controlador == true) {
			$(this).closest('tr').next('tr').find('.reply').slideDown(800).addClass('open').removeClass('close');
			$(this).hide();
			//}
			//else {
			//	$(this).text('responder').closest('tr').next('tr').find('.reply').slideUp(800).addClass('close').removeClass('open');
			//}
			return(false);
		}
	);

	// ------team section-----
	$('.cancel-reply').click(function(e) {
		e.preventDefault();
		$(this).parents('div').first().hide();
		$('.show-reply').show();
	});

	$('#compare-statistics-purchased').click(function(e){
		e.preventDefault();
		$('.specific-statistics').toggle();

	});
	$('#compare-statistics-on-assigment').click(function(e){
		e.preventDefault();
		$('.specific-statistics').toggle();

	});
	$('#compare-statistics-assign').click(function(e){
		e.preventDefault();
		$('.specific-statistics').toggle();

	});


    // show and hide new-message form
	$('#show-player-transfer-form').click(function(e) {
		e.preventDefault();
		$('#player-transfer-form').show();
	});
	$('#hide-player-transfer-form').live('click', function(e) {
		e.preventDefault();
		$('#player-transfer-form').hide();
	});
});

