$(document).ready(function() {
	var tiempo1=300;
	var tiempo2=1000;
	var nom;
	var home=true;
	
	
	$('#imagenes').cycle({
		fx: 'scrollHorz',
		easing: 'easeOutQuint',
		timeout:5000,
		before: function() {
			$('#titulos .titulo').replaceWith('<span class="titulo" title="'+$(this).attr('title')+'">'+$(this).attr('title')+'</span>');
			FLIR.replace( 'span.titulo' , new FLIRStyle({ cFont:'rockwelllight' }) );
		}
	});
	
	
	$('#menu2 ul li a').hover(function(){
		if ($(this).parent().is('.no'))
			$(this).parent().stop().animate({backgroundColor:"#000000"},500);
    },function(){
		if ($(this).parent().is('.no'))
		{
			$(this).parent().stop().animate({backgroundColor:"#000000"},100);
			$(this).parent().animate({backgroundColor:"#f6b412"},800);
		}
    });

	$('#menuact ul li a').hover(function(){
		if ($(this).parent().is('.no'))
			$(this).stop().animate({color:"#f6b412"},300);
    },function(){
		if ($(this).parent().is('.no'))
		{
			$(this).stop().animate({color:"#f6b412"},100);
			$(this).animate({color:"#ffffff"},600);
		}
    });

	$('#botactividades').mouseover(function(){
		$('#menuact').stop(true,true).slideDown();
    }).mouseout(function(){
		/*var abierto=false;
		$('#menuact ul li').each(function(){
			if ($(this).is('.activo'))
				abierto=true;
		});
		if (! abierto)*/
			$('#menuact').stop(true,true).slideUp();
    });

	$('#menuact').mouseover(function(){
		$(this).stop().slideDown();
    }).mouseout(function(){
		/*var abierto=false;
		$('#menuact ul li').each(function(){
			if ($(this).is('.activo'))
				abierto=true;
		});
		if (! abierto)*/
			$(this).stop().slideUp();
    });

	$('#menuact ul').mouseover(function(){
		$(this).parent().stop().slideDown();
    }).mouseout(function(){
		//$(this).parent().slideUp();
    });

	$('#menuact ul li a').mouseover(function(){
		$(this).parent().parent().parent().stop().slideDown();
    }).mouseout(function(){
		//$(this).parent().parent().parent().slideUp();
    });
	
	
	$(window).load(function() {
		//var loc=location+"";
		//loc=loc.substr(loc.indexOf('#'),loc.length);
		
		var loc=location.hash+"";
		
		if (loc.length>1)
		{
			nom='#bot'+$(loc).attr('id');

			if ($(nom).parent().is(".no") || $(nom).parent().is(".activosub"))
			{
				desactivar();
				if (nom.length>=16)
				{
					$(nom).css({'color':'#f6b412'});
					//$('#menuact').stop().slideDown();
					
					$('#botactividades').parent().css({'background-color':'#000'});
					$('#botactividades').parent().addClass("activosub");
					$('#botactividades').parent().removeClass("no");
				}
				else
				{
					$(nom).parent().css({'background-color':'#000'});
					//$('#menuact').stop().slideUp();
					
					$('#botactividades').parent().addClass("no");
					$('#botactividades').parent().removeClass("activosub");
				}
				$(nom).parent().addClass("activo");
				$(nom).parent().removeClass("no");

				$(loc).slideDown(600);
				$(loc).parent().find(loc.replace('#','.')).slideDown(600);
				$(loc).find(".visible").stop().css({backgroundColor:"#ccc7c0"});
				$(loc).find(".visible").css({'cursor':'default'});
				$(loc).find(".oculto").slideDown(600);
				$(loc).find(".visible").find(".imgbanner").slideUp(600);
				$(loc).find(".visible").find(".txtbanner").slideUp(600);
				$(loc).find(".visible").find(".txtbannerocu").slideDown(600);

				var cual=$(loc);
				setTimeout(function(){
					var pos=$(cual).position().top;
					$('html,body').animate({scrollTop: pos-120}, 600);
				},800);
				
				
				i=max=0;
				$(cual).find('.oculto .ocu3 img').each(function(){
					max++;
				});

				$(cual).find('.oculto .ocu3').cycle({
					fx: 'scrollHorz',
					easing: 'easeOutQuint',
					timeout:5000,
					before: function() {
						if (i>=max)
							i=0;
						i++;

						$(cual).parent().parent().find('.oculto .ocu1 span.num').replaceWith('<span class="num">'+i+'</span>');
						FLIR.replace( 'span.num' , new FLIRStyle({ cFont:'rockwellextbold' }) );
					}
				});
			}
		}
	});
	
	$('.visible').mouseover(function(){
		nom='#bot'+$(this).parent().attr('id');
		if ($(nom).parent().is(".no") || $(nom).parent().is(".activosub"))
			$(this).stop().animate({backgroundColor:"#f6b412"},tiempo1);
    }).mouseout(function(){
		nom='#bot'+$(this).parent().attr('id');
		if (home || $(nom).parent().is(".activo"))
			$(this).stop().animate({backgroundColor:"#ccc7c0"},tiempo2);
		else
			$(this).stop().animate({backgroundColor:"#fff"},tiempo2);
    });

	$('.visible').click(function(){
		nom='#bot'+$(this).parent().attr('id');
		
		if ($(nom).parent().is(".no") || $(nom).parent().is(".activosub"))
		{
			desactivar();
			if (nom.length>=16)
			{
				$(nom).css({'color':'#f6b412'});
				//$('#menuact').stop().slideDown();
				
				$('#botactividades').parent().css({'background-color':'#000'});
				$('#botactividades').parent().addClass("activosub");
				$('#botactividades').parent().removeClass("no");
			}
			else
			{
				$(nom).parent().css({'background-color':'#000'});
				//$('#menuact').stop().slideUp();
				
				$('#botactividades').parent().addClass("no");
				$('#botactividades').parent().removeClass("activosub");
			}
			$(nom).parent().addClass("activo");
			$(nom).parent().removeClass("no");
			
			var cual=$(this);
			//setTimeout(function(){
				$(cual).stop().css({backgroundColor:"#ccc7c0"});
				$(cual).css({'cursor':'default'});
				$(cual).parent().find(".oculto").slideDown(600);
				$(cual).find(".imgbanner").slideUp(600);
				$(cual).find(".txtbanner").slideUp(600);
				$(cual).find(".txtbannerocu").slideDown(600);
			//},600);
			
			setTimeout(function(){
				var pos=$(cual).parent().position().top;
				$('html,body').animate({scrollTop: pos-120}, 600);
			},600);
			
			
			i=max=0;
			$(this).parent().find('.oculto .ocu3 img').each(function(){
				max++;
			});

			$(this).parent().find('.oculto .ocu3').cycle({
				fx: 'scrollHorz',
				easing: 'easeOutQuint',
				timeout:5000,
				before: function() {
					if (i>=max)
						i=0;
					i++;
					
					$(this).parent().parent().parent().find('.oculto .ocu1 span.num').replaceWith('<span class="num">'+i+'</span>');
					FLIR.replace( 'span.num' , new FLIRStyle({ cFont:'rockwellextbold' }) );
				}
			});
		}
    });

	$('a[href*=#]').click(function() {
	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname)
		{
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length)
			{
				setTimeout(function(){
					var targetOffset = $target.offset().top;
					$('html,body').animate({scrollTop: targetOffset-120}, 1000);
				},600);
				return false;
			}
		}
	});
	
	$('#menu2 ul li a').click(function(){
		if ($(this).parent().is(".no") || $(this).parent().is(".activosub"))
		{
			desactivar();
			$(this).parent().css({'background-color':'#000'});
			$(this).parent().addClass("activo");
			$(this).parent().removeClass("no");
			$(this).parent().removeClass("activosub");
			$('#menuact').stop(true,true).slideUp();
			
			var cual="";
			cual='#'+$(this).attr('id').substr(3,$(this).attr('id').length);
			//setTimeout(function(){
				$(cual).slideDown(600);
				$(cual).parent().find(cual.replace('#','.')).slideDown(600);
				$(cual).find(".visible").css({'cursor':'default'});
				$(cual).find(".visible").stop().animate({backgroundColor:"#ccc7c0"},tiempo1);
				$(cual).find(".oculto").slideDown(600);
				$(cual).find(".visible").find(".imgbanner").slideUp(600);
				$(cual).find(".visible").find(".txtbanner").slideUp(600);
				$(cual).find(".visible").find(".txtbannerocu").slideDown(600);
			//},600);
			
			
			i=max=0;
			$(cual).find('.oculto .ocu3 img').each(function(){
				max++;
			});

			$(cual).find('.oculto .ocu3').cycle({
				fx: 'scrollHorz',
				easing: 'easeOutQuint',
				timeout:5000,
				before: function() {
					if (i>=max)
						i=0;
					i++;
					
					$(cual).parent().parent().find('.oculto .ocu1 span.num').replaceWith('<span class="num">'+i+'</span>');
					FLIR.replace( 'span.num' , new FLIRStyle({ cFont:'rockwellextbold' }) );
				}
			});
		}
    });

	$('#menuact ul li a').click(function(){
		if ($(this).parent().is(".no"))
		{
			desactivar();
			$(this).css({'color':'#f6b412'});
			$(this).parent().addClass("activo");
			$(this).parent().removeClass("no");
			
			$('#botactividades').parent().css({'background-color':'#000'});
			$('#botactividades').parent().addClass("activosub");
			$('#botactividades').parent().removeClass("no");
			
			var cual="";
			cual='#'+$(this).attr('id').substr(3,$(this).attr('id').length);
			//setTimeout(function(){
				$(cual).slideDown(600);
				$(cual).parent().find(cual.replace('#','.')).slideDown(600);
				$(cual).find(".visible").css({'cursor':'default'});
				$(cual).find(".visible").stop().animate({backgroundColor:"#ccc7c0"},tiempo1);
				$(cual).find(".oculto").slideDown(600);
				$(cual).find(".visible").find(".imgbanner").slideUp(600);
				$(cual).find(".visible").find(".txtbanner").slideUp(600);
				$(cual).find(".visible").find(".txtbannerocu").slideDown(600);
			//},600);
			
			
			i=max=0;
			$(cual).find('.oculto .ocu3 img').each(function(){
				max++;
			});

			$(cual).find('.oculto .ocu3').cycle({
				fx: 'scrollHorz',
				easing: 'easeOutQuint',
				timeout:5000,
				before: function() {
					if (i>=max)
						i=0;
					i++;
					
					$(cual).parent().parent().find('.oculto .ocu1 span.num').replaceWith('<span class="num">'+i+'</span>');
					FLIR.replace( 'span.num' , new FLIRStyle({ cFont:'rockwellextbold' }) );
				}
			});
		}
    });

	function desactivar()
	{
		home=false;
		$('.oculto .ocu3').cycle('destroy');
		$('.oculto').slideUp(600);
		$('.imgbanner').slideDown(600);
		$(".txtbanner").slideDown(600);
		$(".txtbannerocu").slideUp(600);
		$('.visible').stop().css({'background-color':'#fff'});
		$('.visible').css({'cursor':'pointer'});
		$('.banoculto').slideUp(600);
		
		$('#menu2 ul li a').each(function(){
			$(this).parent().removeClass("activo");
			$(this).parent().addClass("no");
			$(this).parent().css({'background-color':'#f6b412'});
		});
		
		$('#menuact ul li a').each(function(){
			$(this).parent().removeClass("activo");
			$(this).parent().addClass("no");
			$(this).css({'color':'#fff'});
		});
		
		$('#menunot ul li a').each(function(){
			$(this).parent().removeClass("activo");
			$(this).parent().addClass("no");
			$(this).css({'color':'#fff'});
		});
	}
});

