function columnas(group){
	var tallest = 0;
	group.each(function(e){
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
};
function columnaDcha() {
		var altoDcha = $('.side_ri').height();
		var altoMain = $('.principal').height();
		if (altoDcha > altoMain) {
			$('.principal').height(altoDcha + 40);
		}
}
function columnaIzqda() {
    var altoIzqda = $('.side_le').height();
    var altoMain = $('.main').height();
    if (altoMain > altoIzqda) {
        $('.side_le').height(altoMain);
    } else {
        $('.main').height(altoIzqda);
    }
}

function validate_checkAccept(sender, e) {    
    var chb = document.getElementById("ctl00_content_checkAccept");
    e.IsValid = chb.checked == true;
}

function validate_checkAcceptNuevo(sender, e) {
    var chb = document.getElementById("checkAccept");
    e.IsValid = chb.checked == true;
}


function media() {
    $('.sin_boton .social ul li:first').css({ 'width':'33%' });
    $('a.social_media').each(function() {
        var enlace = $(this);
        var padre = $(this).parent();
        var hijo = $(this).siblings('ul');
        hijo.css({ 'visibility': 'hidden' });
        $(this).toggle(
			function() {
			    $(this).addClass('hover');
			    $(hijo).css({ 'visibility': 'visible' });
		    
			    return false;
			},
			function() {
			    $(this).removeClass('hover');
			    $(hijo).css({ 'visibility': 'hidden' });
			    return false;
			}
		);
        if ($('a.social_media').size() > 1) {
            $(hijo).mouseleave(function() {
                $(enlace).removeClass('hover');
                $(hijo).css({ 'visibility': 'hidden' });
            });
        }
    });
//    var imagenWidth = $('.destacado .social .imagen').width();
//    var paddingCont = (imagenWidth + 15);
//    $('.destacado .social .contenido').css({ 'padding-left': paddingCont });
};
function anchoPrincipal(){
	var ancho = $('div.principal').width();
	var ajuste = ancho + 1;
	$('div#nav li ul').css({'width':ajuste});
};
function alturaModal(){
	var h =  $(document).height();
	$('.modal_flotante').css({'height': h, 'opacity':0.6})
}
function alturaSocial() {
	$('.modulo .social').each(function() {
		$(this).height($(this).parent().height());
	});
}

function tooltipFavorito() {
	$('.favorito a').hover(function() {
		$(this).parent().siblings('.caja_tooltip').children('.tooltip').show(250);
	}, function() {
		$(this).parent().siblings('.caja_tooltip').children('.tooltip').hide(250);
	});
}

function ratings() {
	$(".rating li").live("mouseover", function() {
		var objThis = $(this);
		var parent = objThis.parent();
		if (parent.attr("Votado") == null) {
			objThis.attr("class", "filledRatingStar").text("Voto");
			objThis.prevAll().attr("class", "filledRatingStar").text("Voto");
			objThis.nextAll().attr("class", "emptyRatingStar").text("Sin Voto");
		}
	});
	
	$(".rating li").live("click", function(e) {
		if ($(this).parent().attr("Votado") == null) {
			$(this).parent().attr("Votado", true);
			var asociado = $(this).parent().attr("ih_asociado");
			document.getElementById(asociado).value = $(this).prevAll().length + 1;
		}
	});
	
	$(".rating").live("mouseout", function(e) {
		if ($(this).attr("Votado") == null) {
			$(this).children().attr("class", "emptyRatingStar").text("Sin Voto");
		}
	});
}

function cerrarModal() {
	location.href = $('.modal_login .cerrarModal').attr("href");
};

function numeroDeLista() {
	var $lista = $('.articulo ol');
	$lista.each(function() {
		var e = parseFloat($(this).children('li').size());
		for ( i=1; i<=e; i++ ) {
			var html = '<div class="numero">'+ i +'</div';
			$(this).children('li').eq(i-1).prepend(html);
		}
	});
}

function acordeon(){
	if ($('div.acordeon li').hasClass('active'))
	{
	    $('div.acordeon > ul > li > ul').hide();
	    $('div.acordeon li.active').children().show();
		$('div.acordeon li.active').parents('ul:has(li.active)').show();
		return false;
	}
	else
	{
		$('div.acordeon > ul > li > ul').hide();
		//$('div.acordeon > ul > li > a').bind('click',function(event){$(this).next('ul').toggle();return false;});		
	}
};

function acordeonplus() {
    if ($('div.acordeonplus li').hasClass('active')) {
        $('div.acordeonplus > ul > li > ul').hide();
        //$('div.acordeonplus li.active').children().show();
        $('div.acordeonplus li.active').parents('ul:has(li.active)').show();
        return false;
    }
    else {
        $('div.acordeonplus > ul > li > ul').hide();
        $('div.acordeonplus > ul > li > a').bind('click',function(event){$(this).next('ul').toggle();return false;});		
    }
};

function falsoFile() {
	$('.registro input[type=file]').each(function() {
		var $fileFalso = $(this);
		$fileFalso.css({'opacity': 0});
		var $inputFalso = $('<div class="f_falso"></div>');
		$fileFalso.before($inputFalso);
		$inputFalso.html('<input type="text" class="f_input f_medio" /><div class="acciones"><p class="boton medio"><span><a href="#">Examinar</a></span></p></div>');
		var $f_inputFalso  = $inputFalso.find(':text');
		var $reset = $inputFalso.find(':reset');
		$(this).width($inputFalso.width()).height($inputFalso.height());
		$(this).change(function(e){
		  $in=$(this);
		  $f_inputFalso.attr("value",$in.val()).attr("disabled", "disabled");
		});
	});
}
function hrLadoDcho() {
    var $hr = $('.side_ri > .hr_doble:last');
    if ($hr.next().is('.cuenta')) {
    } else {
        $hr.remove();
    };
}
function alaCola(self) {
    self.insertAfter($('div.main > div:last')).before('<div class="hr"></div>').show();
}



$(document).ready(function() {
    media();
    anchoPrincipal();
    alturaModal();
    tooltipFavorito();
    alturaSocial();
    ratings();
    numeroDeLista();
    acordeon();
    acordeonplus();
    if ($(".home div.categorias").length) { alaCola($('.home div.categorias')); }
    columnas($('.tabla_comunidad > div').not('div.limpiar'));
    columnas($('.home #escuela > div'));
    //  columnaIzqda();
  falsoFile();
    hrLadoDcho();

    //Colocacion de fondo de login
    var alturaLogin = ($('#login .container').height()) + 16;
    var alturaTools = $('#tools').innerHeight();
    $('.fondo_login').css({ 'opacity': 0.3, 'height': alturaLogin });
    $('#login').css('top', alturaTools);
    //Colocacion de fondo de destacado en Recetas y Menus
    var alturaDestacado = ($('.destacado .info .inner').height());
    $('.destacado .fondo .inner').css({ 'opacity': .7, 'height': alturaDestacado });

    //Identificacion de elementos primeros, últimos, arreglo de flotaciones...
    $('.side_ri > div:first').addClass('primero');
    $('.modulo .edicion li').addClass('over');
    $('.modulo .edicion li .f_input').addClass('over');
    $('ul.sub li:last').addClass('last');
    $('div.productos div:odd').after('<div class="limpiar" style="float:none;"></div>');
    $('span[disabled]').addClass('disabled').removeAttr('disabled');

    //Pijamas
    $('.recetas > ul > li:odd').addClass('altern');
    $('.articulo > table > tbody > tr:nth-child(2n)').addClass('altern');
    $('.resultados tr:even').children(':even').addClass('altern');
    $('.resultados tr:odd').children(':odd').addClass('altern');
})

$(window).load(function() {
    columnaDcha();
    $('.tercio .f_ri_t .social').show();
});


//$(function() {
//    $("form input").keypress(function(e) {
//        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {            
//            eval($("#ctl00_lnkAcceder").attr("href"));
//            return true;
//        }
//    });
//});