$(document).ready(function(){
	
window.onresize=Resize;
function Resize(){
	var windowWidth=document.body.clientWidth;
	var windowHeight=document.body.clientHeight;
	//document.body.style.fontSize=(windowWidth/75)+'px';
	document.body.style.fontSize=(windowWidth/90)+'px';
	var heightImg= $(".background img").height();
	var widthImg= $(".background img").width();
	
	if(heightImg < windowHeight)
		$(".background img").css({'width':'auto','height':'100%'});
	if(widthImg < windowWidth)
		$(".background img").css({'width':'100%','height':'auto'});

}
Resize();
	
	
	var url=window.location.href;
	var section = url.split('#');
	section=section[1];
	if(section=='about' || section=='servicios' || section=='instalaciones' || section =='instalaciones' || section=='reel' || section =='contacto' || section =='login')
		$("#"+section+'Section').addClass('active '+section+'Section');
	getSection(section+'Section');
	
	
	$('.menuItem').click(function(){
		if (!$(this).is('.active')) {
			var section = $(this).attr('id');
			var color=$('.menuItem.active').attr('id');
			var active=$('.menuItem.active').size();
			if(active > 0)
				$('.menuItem.active').removeClass('active '+color).animate({'padding-top':'1em'},function(){getSection(section);});
			else
				getSection(section);
			$(this).addClass('active '+section);	
		}
	});
	
	$('.menuItem').hover(function(){
		if (!$(this).is('.active')) {
			var padding_top = "4em";
			if (!$(this).is(':animated')) {
				$(this).addClass($(this).attr('id'));
				$(this).animate({
					'padding-top': padding_top
				});
				
			}
		}
	},function(){
		if (!$(this).is('.active')) {
			$(this).removeClass($(this).attr('id'));
			var padding_top = "1em";
			$(this).animate({
				'padding-top': padding_top
			});
		}
	});
});

function getSection(section){
	$.post("php/section.php", {
		section:section
	}, function(response){
		$('#content').html(response);
		if(section == 'instalacionesSection')
			$.getScript('js/instalaciones.js');
		else if(section =='reelSection'){
			//$.getScript('js/video.js');
			$.getScript('js/reel.js');
		}
		else if(section =='serviciosSection'){
			$.getScript('js/servicios.js');
		}
		else if(section =='contactoSection'){
			$.getScript('js/contacto.js');
		}
	});
}


