	var cortina = false;

	function abrirCortina(direccion)
	{
			$(".sidebar").show();
			$(".contenido").hide().html("<div style='margin-left:325px;margin-top:15%;'><img src='../imagenes/assets/cargando.gif' /></div>");		
			$(".fondo").animate({"left": "+=747px"}, "slow" , function() {
				$(".contenido").show();
				$.ajax({
				  url: direccion,
				  cache: false,
				  success: function(html){
					$(".contenido").empty();
					$(".contenido").append(html);
					$(".imgInferior").delay(500).fadeIn('fast');
					$(".enviarEmail").delay(500).fadeIn('fast');
				  }
				});
			});
			cortina = true;
	}
	
	$(document).ready(function () {

		
		$('#ver li a').hover(
			
			function ()
			{
				if(!($(this).attr("id") == "directors"))
				{
					if(!($(this).attr("id") == "production"))
					{
						if (!($(this).hasClass("seleccion")))
						{
							height = $(this).height() * (1);
							$(this).stop().animate({'backgroundPosition':'(0 ' + -height + ')'}, {duration:200});	
						}
					}
				}
			}, 
			
			function () 
			{
				if(!($(this).attr("id") == "directors"))
				{
					if(!($(this).attr("id") == "production"))
					{
						if (!($(this).hasClass("seleccion")))
						{
							$(this).stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
						}	
					}
				}
			}
		);
		
		// PARA DIRECTORS
		
		$('#directors').hover(
			
			function ()
			{
				if($('#menuDirectores').css("display") == "none")
				{
						height = $('#directors').height() * (1);
						$('#directors').stop().animate({'backgroundPosition':'(0 ' + -height + ')'}, {duration:200});	
				}
			}, 
			
			function () 
			{
				if($('#menuDirectores').css("display") == "none")
				{
					// SOLO VUELVO AL NEGRO SIEMPRE Y CUANDO NO ESTE SELECCIONADO NINGUN ITEM INTERNO
					if ($(".txtSeleccionado").length == 0) 
					{
						$('#directors').stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
					}
				}
			}
		);
		
		// PARA PRODUCTION
		
		$('#production').hover(
			
			function ()
			{
				if($('#productionSubMenu').css("display") == "none")
				{
					height = $('#production').height() * (1);
					$('#production').stop().animate({'backgroundPosition':'(0 ' + -height + ')'}, {duration:200});	
				}
			}, 
			
			function () 
			{
				if($('#productionSubMenu').css("display") == "none")
				{
					// SOLO VUELVO AL NEGRO SIEMPRE Y CUANDO NO ESTE SELECCIONADO NINGUN ITEM INTERNO
					if ($(".txtSeleccionado2").length == 0) 
					{
						$('#production').stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
					}
				}
			}
		);
				
	});	
	
	
	function cambiarSeleccion(a)
	{	
			removerSeleccion();
			
			if(a == "#home")
			{				
				cambio();
				if (cortina == false)
				{
					abrirCortina("sub_index.php");
				}
				else
				{
				$('.contenido').slideUp("slow", function() {
					$('.contenido').empty().show().html("<div style='margin-left:320px;margin-top:15%;'><img src='../imagenes/assets/cargando.gif' /></div>");	
					$.ajax({
					  	url: "sub_index.php",
					  	cache: false,
					  	success: function(html)
						{
							$(".contenido").empty();
							$(".contenido").append(html);
						}
					});	
				});
				}
			}
			
			
			if(a == "#reel")
			{
				cambio();
				if (cortina == false)
				{
					abrirCortina("reel/index.php");
				}
				else
				{
				$('.contenido').slideUp("slow", function() {
					$('.contenido').empty().show().html("<div style='margin-left:320px;margin-top:15%;'><img src='../imagenes/assets/cargando.gif' /></div>");	
					$.ajax({
					  	url: "reel/index.php",
					  	cache: false,
					  	success: function(html)
						{
							$(".contenido").empty();
							$(".contenido").append(html);
						}
					});
				});
				}
			}
			
			if(a == "#metropost")
			{
				cambio();
				if (cortina == false)
				{
					abrirCortina("metropost/index.php");
				}
				else
				{
				$('.contenido').slideUp("slow", function() {
					$('.contenido').empty().show().html("<div style='margin-left:320px;margin-top:15%;'><img src='../imagenes/assets/cargando.gif' /></div>");		
					$.ajax({
					  	url: "metropost/index.php",
					  	cache: false,
					  	success: function(html)
						{
							$(".contenido").empty();
							$(".contenido").append(html);
						}
					});
				});
				}
			}
			
			if(a == "#about")
			{
				cambio();
				if (cortina == false)
				{
					abrirCortina("about/index.php");
				}
				else
				{
				$metro.contenido.slideUp("slow", function() {
					$metro.contenido.empty().show().html("<div style='margin-left:320px;margin-top:15%;'><img src='../imagenes/assets/cargando.gif' /></div>");		
					$.ajax({
					  	url: "about/index.php",
					  	cache: false,
					  	success: function(html)
						{
							$(".contenido").empty();
							$(".contenido").append(html);
						}
					});
				});
				}
			}
			
			function cambio()
			// SE APLICA SOLO A LOS ELEMENTOS QUE NO SON SUBMENU
			{
				$('#menuDirectores').slideUp('slow');
				$('#productionSubMenu').slideUp('slow');
				$metro.production.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
				$metro.directors.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
				$(''+a+'').addClass('seleccion');
				height = $(''+a+'').height() * (1);
				$(''+a+'').stop().animate({'backgroundPosition':'(0 ' + -height + ')'}, {duration:200});
			}
			
	}
		
	
	function removerSeleccion()
	// REMUEVE CLASES Y DEVUELVE LOS ITEM A NEGRO (0)
	{
		$('.txtSeleccionado').addClass("txtMenuInterno");
		$('.txtSeleccionado').removeClass("txtSeleccionado");
		$('.txtSeleccionado2').addClass("txtMenuInterno2");
		$('.txtSeleccionado2').removeClass("txtSeleccionado2");
		
		// HOME
		if($metro.inicio.hasClass('seleccion'))
		{
			$metro.inicio.removeClass('seleccion');
			$metro.inicio.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
		}
		// DIRECTORES
		if($metro.directors.hasClass('seleccion'))
		{
			$metro.directors.removeClass('seleccion');
			$metro.directors.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
		}
		// PRODUCCION
		if($metro.production.hasClass('seleccion'))
		{
			$metro.production.removeClass('seleccion');
			$metro.production.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
		}		
		// REEL
		if($metro.reel.hasClass('seleccion'))
		{
			$metro.reel.removeClass('seleccion');
			$metro.reel.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
		}
		// METROPOST
		if($metro.metropost.hasClass('seleccion'))
		{
			$metro.metropost.removeClass('seleccion');
			$metro.metropost.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
		}		
		// ABOUT
		if($metro.about.hasClass('seleccion'))
		{
			$metro.about.removeClass('seleccion');
			$metro.about.stop().animate({'backgroundPosition':'(0 0)'}, {duration:200});
		}	
	}
