
$(function() {
	$("a.thumbnail").fancybox();
	
	$("body").css("display", "block");
	
	pixelsAMover = 0;
	
	virginity = true;
	
	centroLink = new Array();
	
	x = 0;
	$('#menu-frutas').children().each( function(){	// se calcula el centro de cada nombre de fruta
		centroLink[x] = ($(this).position().left + (parseInt($(this).css("width"))/2))-6;
		x++;
	});
	
	vuelta = 0;
	max = x; // Vueltas en los links
	
	$("#arrow").css("display", "block");
	pixelsAMover = centroLink[vuelta] - ($("#arrow").position().left);
	
	$("#arrow").animate({"left": "+="+pixelsAMover+"px"}, 2000);
	
	$("#arrow").css("display", "block");
	setInterval( "slideSwitch()", 5000 );
	
    languages.onselectstart = function(){
		return false;
    } 
	// Firefox
    languages.onmousedown = function(){
		return false;
    }
	
	// More fruits
		$("#mas-frutas").click(function(){
			$("#otras-frutas").toggle();
		});
		
	
});

function slideSwitch() {
	var $active = $('#head-slide IMG.active');

	if ( $active.length == 0 ) $active = $('#head-slide IMG:last');

	var $next =  $active.next().length ? $active.next()
		: $('#head-slide IMG:first');

	$active.addClass('last-active');

	$next.css({
		opacity: 0.0
	})
	
	.addClass('active')
	.animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});
	
	// Programación flecha
	
	if (virginity == true){
		vuelta = 1;
	}
	
	
	pixelsAMover = centroLink[vuelta] - ($("#arrow").position().left);
	
	
	$("#arrow").animate({"left": "+="+pixelsAMover+"px"}, 1000);
	vuelta++;
	
	if (vuelta >= max)
		vuelta = 0;
	if (virginity == true)
		virginity = false;
}


function print_r(theObj){
   if(theObj.constructor == Array || theObj.constructor == Object){
      document.write("<ul>")
      for(var p in theObj){
         if(theObj [p] .constructor == Array || theObj [p] .constructor == Object){
            document.write("<li> ["+p+"]  => "+typeof(theObj)+"</li>");
            document.write("<ul>")
            print_r(theObj [p] );
            document.write("</ul>")
         } else {
            document.write("<li> ["+p+"]  => "+theObj [p] +"</li>");
         }
      }
      document.write("</ul>")
   }
}

