var timer=1;
function changebg()
{
	allFadeOut();
	timer=timer+1;	
	$('#imgindbg'+timer).fadeIn(1500, function() {return false;});
	if(timer==4)
	{
		timer=1;
	}
}
function allFadeOut()
{
			for (i=1; i<=4; i++)
			{
				$('#imgindbg'+i).fadeOut();
				
			}
}
function updateBackground() {

  screenWidth = $(window).width();
  screenHeight = $(window).height();
  
  bg = $("#imgindbg1");
  update(bg);
  bg = $("#imgindbg2");
  update(bg);
  bg = $("#imgindbg3");
  update(bg);
  bg = $("#imgindbg4");
  update(bg);

}

function update(bg)
{

 // Proporcion horizontal/vertical
  ratio = 1;

  if (screenWidth/screenHeight > ratio) {
     $(bg).height("auto");
  $(bg).width("100%");
  } else {
    $(bg).width("auto");
    $(bg).height("100%");
  }

  if ($(bg).width() < 0) {
		$(bg).css('left', (screenWidth - $(bg).width()) / 2);

  }

}

var contador=0;
$(document).ready(function() {
		var id = setInterval("changebg()",4000);
	updateBackground();
	$(window).bind("resize", function() {
		updateBackground();
	});	
		// Team Cycle
	$('#carrousel').cycle({
		fx: 'fade'
	});
	//Rollovers menu superior		
	$('#menu_superior ul li:has(ul)').hover( 
      function(e) 
      { 

         $(this).find('ul').css({display: "block"}); 
      }, 
      function(e) 
      { 
         $(this).find('ul').css({display: "none"}); 
      } 
	); 
	//Rollovers menu superior eng	
	$('#menu_superior_eng ul li:has(ul)').hover( 
      function(e) 
      { 

         $(this).find('ul').css({display: "block"}); 
      }, 
      function(e) 
      { 
         $(this).find('ul').css({display: "none"}); 
      } 
	); 
	}); 
	$(function() {
	
		// menu lateral functions
		//MouseOverPeliculas
		$( "#peliculas" ).mouseover(function() {
			if(document.getElementById('content_peliculas').style.display =='block')
			{	
			}else{
				openMenu('#content_peliculas');
				document.getElementById('peliculas').className='peliculas_active';
			}
			return false;
		});
		
		//MouseOverPublicaciones
		$( "#publicaciones" ).mouseover(function() {
			if(document.getElementById('content_publicaciones').style.display =='block')
			{	
			}else{
				openMenu('#content_publicaciones');	
				document.getElementById('publicaciones').className='publicaciones_active';
			}
			return false;
		});
		//MouseOverLujuria
		$( "#lujuria" ).mouseover(function() {
			if(document.getElementById('content_lujuria').style.display =='block')
			{	
			}else{
				
				openMenu('#content_lujuria');		
				document.getElementById('lujuria').className='lujuria_active';
			}
			return false;
		});
		
		function openMenu(x)
		{
			document.getElementById('lujuria').className='lujuria';
			document.getElementById('publicaciones').className='publicaciones';
			document.getElementById('peliculas').className='peliculas';
			$( "#content_lujuria" ).hide();
			$( "#content_peliculas" ).hide();
			$( "#content_publicaciones" ).hide();
			// get effect type from 
			var selectedEffect = 'slide';
			// most effect types need no options passed by default
			var options = {};
			// run the effect
			$(x).show( selectedEffect, options, 800 );
		}
		$( "#close_peliculas" ).click(function() {		
			$( "#content_peliculas" ).hide();
			document.getElementById('peliculas').className='peliculas';
		});
		$( "#close_publicacion" ).click(function() {		
			$( "#content_publicaciones" ).hide();
			document.getElementById('publicaciones').className='publicaciones';
		});
		$( "#close_lujuria" ).click(function() {	
			document.getElementById('lujuria').className='lujuria';
			$( "#content_lujuria" ).hide();
		});
		
		
			// menu lateral functions eng
		//MouseOverPeliculas
		$( "#peliculas_eng" ).mouseover(function() {
			if(document.getElementById('content_peliculas_eng').style.display =='block')
			{	
			}else{
				openMenuEng('#content_peliculas_eng');
				document.getElementById('peliculas_eng').className='peliculas_active';
			}
			return false;
		});
		
		//MouseOverPublicaciones
		$( "#publicaciones_eng" ).mouseover(function() {
			if(document.getElementById('content_publicaciones_eng').style.display =='block')
			{	
			}else{
				openMenuEng('#content_publicaciones_eng');	
				document.getElementById('publicaciones_eng').className='publicaciones_active';
			}
			return false;
		});
		//MouseOverLujuria
		$( "#lujuria_eng" ).mouseover(function() {
			if(document.getElementById('content_lujuria_eng').style.display =='block')
			{	
			}else{
				
				openMenuEng('#content_lujuria_eng');		
				document.getElementById('lujuria_eng').className='lujuria_active';
			}
			return false;
		});
		
		function openMenuEng(x)
		{
			document.getElementById('lujuria_eng').className='lujuria';
			document.getElementById('publicaciones_eng').className='publicaciones';
			document.getElementById('peliculas_eng').className='peliculas';
			$( "#content_lujuria_eng" ).hide();
			$( "#content_peliculas_eng" ).hide();
			$( "#content_publicaciones_eng" ).hide();
			// get effect type from 
			var selectedEffect = 'slide';
			// most effect types need no options passed by default
			var options = {};
			// run the effect
			$(x).show( selectedEffect, options, 800 );
		}
		$( "#close_peliculas_eng" ).click(function() {		
			$( "#content_peliculas_eng" ).hide();
			document.getElementById('peliculas_eng').className='peliculas';
		});
		$( "#close_publicacion_eng" ).click(function() {		
			$( "#content_publicaciones_eng" ).hide();
			document.getElementById('publicaciones_eng').className='publicaciones';
		});
		$( "#close_lujuria_eng" ).click(function() {	
			document.getElementById('lujuria_eng').className='lujuria';
			$( "#content_lujuria_eng" ).hide();
		});
			
		
		/*********************** nosotros effects english ******************/
		
		$("#inferior_nosotros_eng" ).click(function() { 
			var timeFadeOut=900;
		
			$('#inferior_nosotros_eng').fadeOut(timeFadeOut, function() {	});
			$('#inferior_nosotros_up_eng').fadeIn(timeFadeOut, function() {	});
			
		});
		$( "#title_nosotros_up_eng" ).click(function() { 
			var timeFadeOut=900;
			$('#inferior_nosotros_up_eng').fadeOut(timeFadeOut, function() {	});
			$('#inferior_nosotros_eng').fadeIn(timeFadeOut, function() {	});
		
		});
		/*********************** nosotros effects ******************/
		
		$("#inferior_nosotros" ).click(function() { 
			var timeFadeOut=900;
		
			$('#inferior_nosotros').fadeOut(timeFadeOut, function() {	});
			$('#inferior_nosotros_up').fadeIn(timeFadeOut, function() {	});
			
		});
		$( "#title_nosotros_up" ).click(function() { 
			var timeFadeOut=900;
			$('#inferior_nosotros_up').fadeOut(timeFadeOut, function() {	});
			$('#inferior_nosotros').fadeIn(timeFadeOut, function() {	});
		
		});
		
		/******************* inferior erika english ****************/
			$("#inferior_erika_eng" ).click(function() { 
			var timeFadeOut=900;
		
			$('#inferior_erika_eng').fadeOut(timeFadeOut, function() {	});
			$('#inferior_erika_up_eng').fadeIn(timeFadeOut, function() {	});
			
		});
		$( "#title_erika_up_eng" ).click(function() { 
			var timeFadeOut=900;
			$('#inferior_erika_up_eng').fadeOut(timeFadeOut, function() {	});
			$('#inferior_erika_eng').fadeIn(timeFadeOut, function() {	});
		
		});
		
		/******************* inferior erika ****************/
			$("#inferior_erika" ).click(function() { 
			var timeFadeOut=900;
		
			$('#inferior_erika').fadeOut(timeFadeOut, function() {	});
			$('#inferior_erika_up').fadeIn(timeFadeOut, function() {	});
			
		});
		$( "#title_erika_up" ).click(function() { 
			var timeFadeOut=900;
			$('#inferior_erika_up').fadeOut(timeFadeOut, function() {	});
			$('#inferior_erika').fadeIn(timeFadeOut, function() {	});
		
		});
		
		
	});
