$(document).ready(function(){

//############## AVISO ###############//
	
	$("#fondoAviso").css({opacity:"0.9"});
	
	$("#avisoWrapper").click(function(){
		$(this).fadeOut(500);
	});
	
	$(".logoPie").click(function(){
		document.location = "Content/Scripts/salir.php";
	});
	
//############## NOTICIAS ################//
	$(".titular_mininoticia a").click(function(){
		var id = $(this).attr("id");
		var u = "Content/Scripts/noticia.php?id_noticia="+id;
		$(".noticias_Left").load(u);
	});
	
	$(".meses_Wrapper a").hover(
		function(){
			$(this).css({textDecoration:"underline"});
		},
		function(){
			$(this).css({textDecoration:"none"});
		}	
	).click(function(){
		var mes = $(this).attr("id");
		document.location="index.php?seccion=noticias&accion=ver_noticia&id_noticia="+mes;
	});
		
	$(".meses_Wrapper#activo").slideDown("1000");
	
	$(".cab_anio").click(function(){
		$(".cab_anio").next().slideUp("1000");
		
		if($(this).next().css("display") == "none"){
			$(this).next().slideDown("1000");
		}
	});

//############### BANNER ####################//	
	$("#banner_Wrapper").cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 1500
	});
	
//############## MOVIMIENTO CARTELES PORTADA ################//
	$(".cartel").cycle({
		fx: 'fade',
		timeout: 3500,
		speed: 500
	});
	
	$(".etiquetas").cycle({
		fx: 'fade',
		timeout: 3500,
		speed: 500
	});

	
	
//############### SOCIOS ####################//
	$("#b_submit_socios").hover(
		function(){
			$(this).find("img").stop().animate({opacity:"0.0"},250);	
		},
		function(){
			$(this).find("img").stop().animate({opacity:"1.0"},250);
		}	
	).click(function(){
		if($("#nombre").attr("value")==""){
			alert("El campo \"Nombre y apellidos\" está vacío");
		} else if($("#anio").attr("value")=="" || $("#dia").attr("value")=="" || $("#mes").attr("value")=="" ){
			alert("Hay que indicar una fecha de nacimiento");
		} else if($("#direccion").attr("value")==""){
			alert("El campo \"Dirección postal\" está vacío");
		} else if($("#cp").attr("value")==""){
			alert("El campo \"Código postal\" está vacío");
		} else if($("#localidad").attr("value")==""){
			alert("El campo \"Localidad\" está vacío");
		} else if($("#provincia").attr("value")==""){
			alert("El campo \"Provincia\" está vacío");
		} else if($("#movil").attr("value")==""){
			alert("El campo \"Móvil\" está vacío");
		} else if($("#email").attr("value")==""){
			alert("El campo \"Correo electrónico\" está vacío");
		} else {
			$("#formulario_socios").submit();	
		}
	});
	
	$("#b_borrar_socios").hover(
		function(){
			$(this).find("img").stop().animate({opacity:"0.0"},250);	
		},
		function(){
			$(this).find("img").stop().animate({opacity:"1.0"},250);
		}	
	).click(function(){
		$("#formulario_socios input").attr("value","");
	});
	
//############# INICIALIZACIÓN DE OBJETO AJAX de Javi ;) #############//
/*
function SetXmlHttpObject() {  
    
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        
        __http_request = new XMLHttpRequest();
        
        if (__http_request.overrideMimeType) {
            __http_request.overrideMimeType('text/xml');             
        }
        
        __http_request.open('GET', __xmlFile, false);
        __http_request.send(null);
   
    } else if (window.ActiveXObject) { // IE
   
        try {
            __http_request = new ActiveXObject('Microsoft.XMLDOM');
            __http_request.async = false;
            __http_request.load(__xmlFile);
        } catch (e) {
            try {
                __http_request = new ActiveXObject('Microsoft.XMLHTTP');
                __http_request.async = false;
                __http_request.load(__xmlFile);
            } catch (e) {
                try {
                    __http_request = new ActiveXObject('Msxml2.XMLHTTP');
                    __http_request.async = false;
                    __http_request.load(__xmlFile);
                } catch (e) {
                
                }
            }
        }
    }
}

*/

//################# COMPORTAMIENTOS GLOBALES DE INICIO ############//

     $("#firma").hover(
     	function(){$("#firma img").attr("src","Content/Images/b_infodelmedia_blanco.png");},
     	function(){$("#firma img").attr("src","Content/Images/b_infodelmedia.png");}     
     );
   
  	
/*################# BOTONES CARTELERA #################*/

$(".cartelera_botones_Wrapper div").hover(
	function(){
		$(this).find("img").stop().animate({opacity:"0"},200);	
	},
	function(){
		$(this).find("img").stop().animate({opacity:"1"},200);	
	}
).click(function(){
	$("#info_"+$(this).parent().attr("id")).html($(this).find(".info").html())
	.find("img").css("opacity","1");
	$("#info_"+$(this).parent().attr("id"))
	.find("embed").attr("width","690")
		.attr("height","411")
	.find("object").attr("width","690")
		.attr("height","411");
	
});
 
$(".b_comprar_entradas").hover(
	function(){
		$(this).find("img").stop().animate({opacity:"0"},200);	
	},
	function(){
		$(this).find("img").stop().animate({opacity:"1"},200);
	}
);
	
//############### SCROLL ANCLA ################//

$(function(){
$("body").css({"overflowX":"hidden"});

$('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) {
      var targetOffset = $target.offset().top;
      $('html,body').animate({scrollTop: targetOffset}, 750);
      return false;
    }
  }
});
});


/*################# VÍDEO NOTICIA #################*/
	$(".foto_noticia embed").attr("width","590")
		.attr("height","351");
	$(".foto_noticia object").attr("width","590")
		.attr("height","351");	

/*################# CARTELERA PORTADA #################*/
	
//	ajustar_columnas();

/*------------ AJUSTE DE ALTURA DE COLUMNAS -----------*/	
	function ajustar_columnas(){

		var altura_peli = $("#columnaPeli").height();
		var altura_noticias = $("#columnaNoticias").height();
		var altura_estrenos = $("#columnaEstrenos").height();
		var mayor1 = 0;
		var mayor2 = 0;
		var mayor_total = 0;
		
		if(altura_peli > altura_noticias){
			mayor1 = altura_peli;
		} else {
			mayor1 = altura_noticias;	
		}
		if(mayor1 > altura_estrenos){
			mayor_total = mayor1;
		} else {
			mayor_total = altura_estrenos;
		}
		
		mayor_total = "1200px";
		
		$("#columnaPeli").height(mayor_total);
		$("#columnaNoticias").height(mayor_total);
		$("#columnaEstrenos").height(mayor_total);
		
	}
/*----------------------------------------------------*/	

	$(".salaWrapper").hover(
		function(){
			var sala = $(this).attr("id");
			$("#"+sala+" .salaVertical img").attr("src","Content/Images/"+sala+"_vertical_hover.png");
			$("#"+sala+" .salaVertical").stop().animate({
				marginBottom: "10px"
			},250);
		},
		function(){
			var sala = $(this).attr("id");
			$("#"+sala+" .salaVertical img").attr("src","Content/Images/"+sala+"_vertical.png");
			$("#"+sala+" .salaVertical").stop().animate({
				marginBottom: "0px"
			},250);
		}
	);/*.click(function(){
		var sala = $(this).attr("id");
		$(".fichaWrapper").hide();
		$("#ficha_"+sala).show();
   		
   		ajustar_columnas();
   				
   	});
	*/
	$(".cartel img").click(function(){
		var id_pelicula = $(this).attr("id");
		$("#columnaPeli").load("Content/Scripts/ficha.php?id_pelicula="+id_pelicula);
	});

	var id_peli_sala1 = $("#id_peli_sala1").attr("value");
	$("#columnaPeli").load("Content/Scripts/ficha.php?id_pelicula="+id_peli_sala1);
	

/*################# MENÚ PRINCIPAL #################*/
	
	$("#logoAlbeniz").click(function(){
		document.location = "index.php?seccion=home";
	});

	$(".punto_menu img").css({opacity:"0.0"});
	$("#punto_"+$("#seccion").attr("value")+" img").css({opacity: "1.0"});
	$("#punto_"+$("#seccion").attr("value")+" img").show();
	
	$("#menu li").hover(
		function(){
			var id = $(this).attr("id");
			$(".punto_menu img").stop().animate({opacity: "0.0"}, 250);
			$("#punto_"+id+" img").stop().animate({opacity: "1.0"}, 250);	
		},
		
		function(){
			var actual = $("#seccion").attr("value");
			var este = $(this).attr("id");
			if(actual != este){
				var id = $(this).attr("id");
				$("#punto_"+actual+" img").stop().animate({opacity: "1.0"}, 250);
				$("#punto_"+id+" img").stop().animate({opacity: "0.0"},250);
			} else {
				$("#punto_"+actual+" img").css({opacity: "1.0"},250);
			}
		}
	).click(function(){
		
		var id = $(this).attr("id");	
		$("#seccion").attr("value",id);
		
		var actual = $("#seccion").attr("value");
		$("#punto_"+actual+" img").stop().animate({opacity: "1.0"},250);
		
		document.location = "index.php?seccion="+id;

	});
	
	//$("#contenido").height( $("#seccion_"+seccion).height());
		
		
	/*################# PRÓXIMOS ESTRENOS #################*/
	$("#b_proximamente").click(function(){
		document.location = "index.php?seccion=proximamente";	
	});
	
	$(".cartel_estrenos").click(function(){
		var id_pelicula = $(this).attr("id");
		$("#columnaPeli").load("Content/Scripts/ficha_proximamente.php?id_pelicula="+id_pelicula);
	});
});




















