$(document).ready(inicializarEventos);

$ancho_logo = 504;
$alto_logo = 48;

$anima = false;
$indica = true;

function inicializarEventos(){

	$alto = $(document).height();

	
	$("body").click(onCastellano);
	imageresize();
	
	$( "#content" ).draggable();
	centrarContent();
	
    
	
	$(window).bind("resize", function(){		
		imageresize();
	});
	
	$(".colabora").click(function(){
		
		return false;
	});
	$(".colabora p.mas").mouseenter(onCreditos);
	$(".colabora p.mas").mouseleave(offCreditos);
}

function onCreditos(){
	
	if(!$anima && !($(".colabora .datos").is (":visible"))){
		$anima = true;
		$(".colabora .datos").fadeIn("slow", finAnimacion);
	}
	
}
function offCreditos(){
	
	if(!$anima && ($(".colabora .datos").is (":visible"))){
		$anima = true;
		$(".colabora .datos").fadeOut("slow",finAnimacion);
	}
	
}

function imageresize(){
	
	$ancho = $(window).width() /3;
	$radio = $ancho/2;
	 
	$radio = parseInt($radio);
	// Cambio de tama–o del cirvulo naranja
	
	$("#img_brand").attr("style", "width:"+$ancho+"px; height:"+$ancho+"px;");
	
	
	$(".brand").attr("style", "width:"+$ancho+"px; height:"+$ancho+"px;z-index:10;");
	 
	// Cambio del logo
	$logo = $(".brand h3 img");
	 
	$ancho = $(window).width() /4;
	 
	 
	$(".brand h3 img").attr("style", "width:"+$ancho+"px; height:"+($ancho*$alto_logo/$ancho_logo)+"px;z-index:10;");
	$(".brand h3").attr("style", "margin-left:12%;z-index:10;");
	$(".brand p.descrip").attr("style","font-size:"+$ancho*1.1/$ancho_logo+"em; width:"+($ancho*2/3)+"px;z-index:10;");
	
	$(".brand p.moveit").attr("style","font-size:"+$ancho*0.8/$ancho_logo+"em;z-index:10;display:none;");
	 
	$(".brand ul.idioma").attr("style","font-size:"+$ancho*1.1/$ancho_logo+"em; z-index:10;");
	 
	$ancho_circulo =  $("#img_brand").width();
	$espacio = $ancho_circulo / 6;
	$ancho_colabora = $(".colabora").width();
	
	$(".colabora").attr("style","left:-"+($ancho_colabora-$espacio)+"px;z-index:100;");
	$("#draggable").attr("style","z-index:5;")
	
	 
}


function centrarContent(){
	
	// Obtenemos el ancho del circulo y el del navegador
	$ancho_circulo =  $("#img_brand").width();
	$ancho_window = $(window).width();

	$pos_left = ($ancho_window / 2)-$ancho_circulo + ($ancho_window * 2.7 / 100);
	
	if($pos_left < 0 ){
		$pos_left = 0;
	}
		
	$("#content").attr("style","left:"+$pos_left+"px;");
	
	
	$espacio = $ancho_circulo / 7;
	$ancho_colabora = $(".colabora").width();
	
	$(".colabora").attr("style","left:-"+($ancho_colabora-$espacio)+"px;z-index:100;");
	
	$("#img_brand").mouseenter(onIndica);
	$("#img_brand").mouseleave(offIndica);
}
function onIndica(){	
	if($indica){		
		$("#moveit").fadeIn("slow");		
		setTimeout("paraIndica()",5000);
	}
}

function paraIndica(){
	
	$indica = false;
	
	$("#moveit").fadeOut("slow");
	
}

function offIndica(){
	
	
}

function onCastellano(){
	
	document.location.href = "home.php?lang=es";
	
}

function finAnimacion(){	
	$anima = false;

}
