var selected_str = "";
var sid;
var ndx = -1;

function menuClick( e )
{
	if( (selected_str+"_r") != e )
	{
		ndx = $("#" + e).index();
		
		
		$("#menu_right ul li").removeClass('selected');
		$("#menu_right ul li:eq("+ ndx +")").addClass('selected');
		selected_str = e.substring(0, e.indexOf('_'));
		
		//console.log( selected_str );
		
		$("#hslider").stop(true).animate({"margin-top": $("#" + selected_str + "_hs" ).index() * -485},"slow","easeOutExpo");
	}
}
function getsIdByIndex()
{
	if( (ndx + 1) >= $("#menu_right ul li").length ) ndx = -1;
	return $("#menu_right ul li").eq(ndx + 1).attr("id");	
}
function goSlider()
{
	clearTimeout(sid);
	menuClick( getsIdByIndex() );
	sid = setTimeout(goSlider, 10000);
}
function pauseSlider() 
{
	clearTimeout(sid);
	sid = setTimeout(goSlider, 20000);	
}
function tecateIni()
{
	$("#introTecate").delay(2000).animate({"margin-top": "-=485"},"slow","easeOutExpo").delay(2000).queue(function() 
	{
		$("#introTecate").stop(true).animate({"margin-top": "-=485"},"slow","easeOutExpo",function(){$(this).remove()});
		$("#menu_right").fadeIn("slow");
		goSlider();
	});
}
function tecatechk()
{
	clearTimeout(sid);
	if( $("#validador").length == 0 ) tecateIni(); else sid = setTimeout(tecatechk, 500);
}
	
$(document).ready(function()
{
	tecatechk();
	
	$('#menu_right ul li').click(function(){
		menuClick($(this).attr('id'));
		pauseSlider();
	});
});
