addLoadEvent(preloader);
$(document).ready(function() {
	$('.menuItem').click(function(e) { 
		e.preventDefault(); 
	});
	$('.next').click(function(e) { 
		e.preventDefault(); 
	});
	$('.prev').click(function(e) { 
		e.preventDefault(); 
	});
	setSlides();
});

function resetMenu(page) {
	$('.menuItem').removeClass('activeMenuItem');
	if (page == 'inicio') {
		$('#mainMenu_1').addClass('activeMenuItem');
	}
	if (page == 'galeria') {
		$('#mainMenu_2').addClass('activeMenuItem');
	}
	if (page == 'hacemos') {
		$('#mainMenu_3').addClass('activeMenuItem');
	}
	if (page == 'contactar') {
		$('#mainMenu_5').addClass('activeMenuItem');
	}
}

function setSlides() {
	$("#slides").slides({
		play: 5000,
		pause: 2500,
		preload: true,
		hoverPause: true,
		generateNextPrev: false,
		generatePagination: true
  });
}


function selectPage(page) {
	resetMenu(page);
	if ($('#body').is(':visible')) {
		$('#body').slideUp('slow', function() {
			$.ajax({
			type: 'post',
			url: 'funciones/llamadas_ajax.php',
				data : 
				{ 	'accion' : 'load_page',
					'ajaxCall': 'yes',
					'page': page
					
				},
				success: function(data) {
					$('#body').html(data).slideDown('fast');
					setSlides();

				}
			});
		});
	}
	else {
		$.ajax({
			type: 'post',
			url: 'funciones/llamadas_ajax.php',
				data : 
				{ 	'accion' : 'load_page',
					'ajaxCall': 'yes',
					'page': page
					
				},
				success: function(data) {
					$('#body').html(data).slideDown('fast');
					setSlides();
				}
		});
	}
}

function submitMail() {
	var tel = document.getElementById('tel').value;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var msg = document.getElementById('msg').value;
	var code = document.getElementById('code').value;
	currentAjaxRequest = $.ajax({
				type:'POST',
				url: 'funciones/llamadas_ajax.php',
				data : 
				{ 	'gest_correo' : 'true',
					'idioma': 'es',
					'name': name,
					'telephone': tel,
					'email': email,
					'mensaje': msg,
					'codigo': code
				},
				success: function(data) {
					$('#body').html(data);
					$('#submit_button').hover(function() {
					$(this)
						.stop(true)
						.animate({ 'background-color': "#d88c2a" }, 1)
						.animate({ 'color': "#ffffff" }, 1);
					}, function() {
						$(this)
						.stop(true)
						.animate({ 'background-color': "#d9d9d9" }, 1000)
						.animate({ 'color': "#000000" }, 1);
					});
				}
	});
	return false;
}

function clearErrorMsg() {
	$('#error_msg_box').empty();
}

function preloader() {
	if (document.images) {
		var img1 = new Image();
		var img2 = new Image();
		var img4 = new Image();
		img1.src = "./imagenes/sitio/1.png";
		img2.src = "./imagenes/sitio/2.png";
		img3.src = "./imagenes/sitio/3.png";
		img4.src = "./imagenes/sitio/3.png";
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function pageTitles(page) {
	$('title').remove();
	return;
}	

