var indice = 1;
$(document).ready(function(){
	
	if($.browser.msie && $.browser.version=="6.0"){
		if (DD_belatedPNG) {
			DD_belatedPNG.fix('.pngfix');
		}
	}
	
	$.get('wp-content/themes/kraft/proc/proc_twitter.php',{procesa:'usuario-sintag',name:'mundophilly'},function(data){
		$('#texto_twitter').html(data);
		$(".cajaBoxTwitter").jcarousel({
				vertical		:true,
				visible			:1,
				auto			:6,
				scroll			:1,
				//initCallback	: inicializarCarrusel,
				animation		:"slow",
				buttonNextHTML	: null,
				buttonPrevHTML	: null
		});
	});
	
	
	
	
	var h_1 = 0;
    var h_2 = 0;
    $('.item-boxrecetas').each(function(){
        if ($(this).find('h1').innerHeight() > h_1) {
            h_1 = $(this).find('h1').innerHeight();
        }
        if ($(this).find('.item-boxrecetas-texto').innerHeight() > h_2) {
            h_2 = $(this).find('.item-boxrecetas-texto').innerHeight();
        }
    });
    $('.item-boxrecetas').each(function(){
        $(this).find('h1').css({
            'height': h_1 + 'px'
        });
        $(this).find('.item-boxrecetas-texto').css({
            'height': h_2 + 'px'
        });
    });	
	
	$('input.inputBox').inputBox();
	$('select.selectBox').selectBox();
	
	// Ejecuta el carrusel
	$("#mycarousel").jcarousel({
		scroll: 1,
		wrap: 'last',
		auto: 10,
		initCallback: mycarousel_initCallback,
		itemFirstOutCallback: {
			onBeforeAnimation: function(data) {
				var total = $('.enlace_destacado').length;
				$('.enlace_destacado').removeClass('enlace_seleccionado');
		  		
				if(indice == total) {
					indice = 0;
				}
				$('.enlace_destacado').eq(indice++).addClass('enlace_seleccionado');
		  	}
		},
		
		// Esto le dice al jCarousel que NO autoconstruya los botones de siguiente y anterior
		buttonNextHTML: null,
		buttonPrevHTML: null
	}).css('visibility','visible');
	
	//Ubica el enlace seleccionado en el destacado del home
	$(".enlace_destacado").each(function(i) {
		$(this).click(function(){
			indice = i+1;
			$(".enlace_destacado").removeClass("enlace_seleccionado");
			$(this).addClass("enlace_seleccionado");
		});
	})
	
});

function mycarousel_initCallback(carousel) {
	
	$('.jcarousel-control a').bind('click', function() {
		var id = $(this).attr('id');
		var idNumero = id.split('_');
			
		carousel.scroll($.jcarousel.intval(idNumero[1]));
		return false;
	});

	$('.jcarousel-control a').eq(0).addClass('enlace_seleccionado');
}
