$(document).ready(function() {
	$("#slider").easySlider();
	
	$("#selector_lenguaje")
	/*
	.blur(
		function() {
			$("#elegir_lenguaje").hide();
		}
	)
	*/
	.click(
		function() {
			var $elegir_lenguaje = $("#elegir_lenguaje");
			$elegir_lenguaje.is(":visible") ? $elegir_lenguaje.hide() : $elegir_lenguaje.show();
		}
	);
	
	if (window.ie6 != null && ie6) {
		$("ul.cotton li a.imagen").hover(
			function() {
				$(this).css("cursor", "pointer");
				if ($(this).parent("li").is(".wellness")) {
					$(this).css("background", "url(img/spa/Wellness_Roll.png) no-repeat");
				} else if ($(this).parent("li").is(".recepcion")) {
					$(this).css("background", "url(img/spa/Recepcion_roll.png) no-repeat");
				} else if ($(this).parent("li").is(".resort")) {
					$(this).css("background", "url(img/spa/Resort_roll.png) no-repeat");
				} else if ($(this).parent("li").is(".mantenimiento")) {
					$(this).css("background", "url(img/spa/mantenimiento_roll.png) no-repeat");
				}
			},
			function() {
				if ($(this).parent("li").is(".wellness")) {
					$(this).css("background", "url(img/spa/Wellness.png) no-repeat");
				} else if ($(this).parent("li").is(".recepcion")) {
					$(this).css("background", "url(img/spa/Recepcion.png) no-repeat");
				} else if ($(this).parent("li").is(".resort")) {
					$(this).css("background", "url(img/spa/Resort.png) no-repeat");
				} else if ($(this).parent("li").is(".mantenimiento")) {
					$(this).css("background", "url(img/spa/mantenimiento.png) no-repeat");
				}
			}
		);
	}
	
	// si css ie desplaza todo el cuerpo hacia la derecha
	$("button.boton").hover(
		function() {
			$(this).css("cursor", "pointer");
		},
		function() {
			$(this).css("cursor", "default");
	});
		
	if (window.page != null) {
		switch (page) {
			case "home":
				home();
				break;
			case "catalogos":
				catalogos();
				break;
			case "clausula":
				clausula();
				break;
		}
	}
});

function home() {
	$("#menu_home li a").hover(
		function() {
			$(this).children("span.out").toggle();
			$(this).children("span.in").toggle();
		},
		function() {
			$(this).children("span.out").toggle();
			$(this).children("span.in").toggle();
	});
}

function catalogos() {
	$("form[name=catalogo]").submit(
		function() {
			if ($("div.cuerpoCatalogo li input:checked").size() == 0) {
				$(this).formError(labels["a_Debe seleccionar al menos un cat&aacute;logo"]);
				return false;
			}
			
			if (!$("#nombre").mandatory(labels['a_Nombre'])) return false;
			if (!$("#apellidos").mandatory(labels['a_Apellidos'])) return false;
			if (!$("#sector").mandatory(labels['a_Sector'])) return false;
			if (!$("#email").mandatory('Email')) return false;
			
			if (!$("input[name=acepto]").is(":checked")) {
				$(this).formError(labels["a_Debe aceptar las condiciones generales antes de poder descargar el cat&aacute;logo"]);
				return false;
			}
			
			return true;
		}
	);
	
	$("a#clausula").click(
		function() {
			window.open('clausula','','width=794,height=320');
			return false;
		}
	);
}

function clausula() {
	$("input#enviar").click(
		function() {
			if ($("input[name=leido]").is(":checked")) {
				window.opener.document.getElementById('acepto').value=1;
			}
			window.close();
		}
	);
}