// JavaScript Document
var activo="";
var myInterval="";
var contarSlider = 1;
var currentSlider="a";
var currentBack;

$(function(){
	
	
	FB.init({appId: '306593356041545', status: true,
               cookie: true, xfbml: true});
      FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
      });
	  FB.Event.subscribe('auth.sessionChange', function(response) {
	  window.location.reload();
	  });
	
					
	$('.boton').click(function() 
	{
							   
	  if($(activo).attr('id') != ""){
		  
		   $(activo).next().slideToggle('normal');
		   
	  };
					  
	  if($(this).attr('id') == $(activo).attr('id')){
						  
			activo="";
						  
	  }else{
						  
			$(this).next().slideToggle('normal');
			
			 activo=this;	
			 
	  };
							
		return false;
	});
	

 	loadSec('inicio');
	
})	//end dom	

function activarMenu(sec,subsec)
{
	
	if(sec!="")
	{
		$('#'+sec).next().slideToggle('normal');
		$('#'+subsec).next().slideToggle('normal');
	}
}

function videoLightBox(){
	
	if( $('div#overlay').hasClass('overlay') == true )
	{
		$('div#overlay').removeClass('overlay').addClass('overlay_full');				
		
		var alto = $(document).height();
				
		$('div#Lightbox').removeClass('sugerencias').addClass('sugerencias2');
				
		$('div#overlay').css("height", alto+"px");
		
		$('div#infoLight').load('secciones/vdo.php');
	
	}
	else
	{
		$('div#infoLight').html("");
		
		$('div#overlay').removeClass('overlay_full').addClass('overlay');				
		
		$('div#Lightbox').removeClass('sugerencias2').addClass('sugerencias');
		
	}
}



function loadSec(sec)
{
	$.ajax({
 		 url: 'secciones/'+sec+'.php',
  		success: function(data) 
		{
			$('#customCss').attr('href','css/'+sec+'.css');
			
			$('.col_cen').html(data);
			 
			if(currentBack != "noti" && currentBack != "socios" && currentBack != "quienes" && currentBack != "practica" && currentBack != "diferenciador" && currentBack != "cobertura")
			{
			  switch(sec)
			  {
				  case'inicio':
				  
					 myInterval = setInterval(incrementaSlider,15000);
					  
					  loadPic('img_lateral_index');
					  
					  $('#inicio ul#ulInicio').css({width:$("#inicio ul#ulInicio li").length*453});
					  
					  $('#uno a, #dos a, #tres a, #cuatro a, #cinco a').mouseover(function()
					  {
						  
						  if(currentSlider != $(this).attr("id"))
						  {
							  switch($(this).attr("id"))
							  {
								  case "a":
									 $(this).css({backgroundPosition:"-34px -29px"});
								  break;
								  
								  case "b":
									 $(this).css({backgroundPosition:"-114px -29px"});
								  break;
								  
								  case "c":
									 $(this).css({backgroundPosition:"-193px -29px"});
								  break;
								  
								  case "d":
									 $(this).css({backgroundPosition:"-273px -29px"});
								  break;
								  
								  case "e":
									 $(this).css({backgroundPosition:"-352px -29px"});
								  break;
							  }
						  }//end if
						  
					  }).mouseout(function()
					  {
						  if(currentSlider != $(this).attr("id"))
						  {
							  switch($(this).attr("id"))
							  {
								  case "a":
									 $(this).css({backgroundPosition:"-34px 0px"});
								  break;
								  
								  case "b":
									 $(this).css({backgroundPosition:"-114px 0px"});
								  break;
								  
								  case "c":
									 $(this).css({backgroundPosition:"-193px 0px"});
								  break;
								  
								  case "d":
									 $(this).css({backgroundPosition:"-273px 0px"});
								  break;
								  
								  case "e":
									 $(this).css({backgroundPosition:"-352px 0px"});
								  break;
							  }
						  }//end if
						  
					  }).click(function()
					  {
						  
						  if(currentSlider != $(this).attr("id"))
						  {
							   
							  switch(currentSlider)
							  {
								  case "a":
									 $("#"+currentSlider).css({backgroundPosition:" -34px 0px"});
								  break;
								  
								  case "b":
									 $("#"+currentSlider).css({backgroundPosition:"-114px 0px"});
								  break;
								  
								  case "c":
									 $("#"+currentSlider).css({backgroundPosition:"-193px 0px"});
								  break;
								  
								  case "d":
									 $("#"+currentSlider).css({backgroundPosition:"-273px 0px"});
								  break;
								  
								  case "e":
									 $("#"+currentSlider).css({backgroundPosition:"-352px 0px"});
								  break;
							  }
							  
							  currentSlider = $(this).attr("id");
							  
							  switch(currentSlider)
							  {
								  case "a":
									 $(this).css({backgroundPosition:" -34px -29px"});
									 contarSlider = 1;
									 loadSlider();
								  break;
								  
								  case "b":
									 $(this).css({backgroundPosition:"-114px -29px"});
									  contarSlider = 2;
									 loadSlider();
								  break;
								  
								  case "c":
									 $(this).css({backgroundPosition:"-193px -29px"});
									  contarSlider = 3;
									 loadSlider();
								  break;
								  
								  case "d":
									 $(this).css({backgroundPosition:"-273px -29px"});
									  contarSlider = 4;
									 loadSlider();
								  break;
								  
								  case "e":
									 $(this).css({backgroundPosition:"-352px -29px"});
									  contarSlider = 5;
									 loadSlider();
								  break;
							  }
							  
						  }//end if
					  })
					  
				  break;
				  case'noti':
				  case'socios':
				  case'quienes':
				  case'practica':
				  case'diferenciador':
				  case'cobertura':
					  loadPic('img_lateral_cobertura');
				  break;
				  case'ceo':
					  loadPic('img_lateral_ceo');
				  break;
				  case'contacto':
					  loadPic('img_lateral_teclado');
					  
				  $('#btn_Enviar a').click(function()
				  {
					   $('#contForm').submit();
				  })
	
				  $('#contForm').submit(function()
				  {
					  $('#btn_Enviar').css({display:"none"});
				
						  if($('#nombre').val() != "")
						  {
							  if($('#email').val() != "")
							  {
								  if($('#tel').val() != "")
								  {
									  if($('#mensaje').val() != "")
									  {
										 $.ajax({
											  type: "POST",
												  url: 'secciones/mail.php',
												  data: "nombre="+$('#nombre').val()+"&email="+$('#email').val()+"&tel="+$('#tel').val()+"&fecha="+$('#dias').val()+"/"+$('#mes').val()+"/"+$('#horario').val()+"&mensaje="+$('#mensaje').val(),
												  success: function(datos)
												  {
													  $('#nombre, #email,#mensaje,#tel').val("");
														  
													  if(datos == "success")
													  {
														  statusForm = false;
														  $('#msg').html('Tus comentarios han sido enviados, Gracias.');
														  $('#Enviar').css({display:"block"});
													  }
													  else
													  {
														  if(datos == "EL E-MAIL QUE ESCRIBISTE NO EXISTE")
														  $('#msg').text(datos);
														  $('#Enviar').css({display:"block"});
													  }
													  
													  
												   }//end success
											  
											})//end ajax
									  }
									  else
									  {
										  $('#mensaje').text('Inserta tu Mensaje');
									  }
									  
								  }
								  else
								  {
									  $('#tel').val('Inserta tu Telefono');
								  }
								  
							  }
							  else
							  {
								  $('#email').val('Inserta tu E-mail');
							  }
							  
						  }
						  else
						  {
							  $('#nombre').val('Inserta tu Nombre');
						  }
							  return false;
				  });
					  
				  break;
			  }
			}
			
			currentBack = sec;
			
			 $("#"+currentSlider).css({backgroundPosition:" -34px -29px"});
  		}
	});

}

function loadSlider()
{
	clearInterval(myInterval);
	
	switch(currentSlider)
	{
		case "a":
		   $("#"+currentSlider).css({backgroundPosition:" -34px 0px"});
		break;
		
		case "b":
		   $("#"+currentSlider).css({backgroundPosition:"-114px 0px"});
		break;
		
		case "c":
		   $("#"+currentSlider).css({backgroundPosition:"-193px 0px"});
		break;
		
		case "d":
		   $("#"+currentSlider).css({backgroundPosition:"-273px 0px"});
		break;
		
		case "e":
		   $("#"+currentSlider).css({backgroundPosition:"-352px 0px"});
		break;
	}
	
	switch(contarSlider)
	{
		case 1:
		   $("#a").css({backgroundPosition:"-34px -29px"});
		   currentSlider = "a";
		break;
		
		case 2:
		   $("#b").css({backgroundPosition:"-114px -29px"});
		   currentSlider = "b";
		break;
		
		case 3:
		   $("#c").css({backgroundPosition:"-193px -29px"});
		   currentSlider = "c";
		break;
		
		case 4:
		   $("#d").css({backgroundPosition:"-273px -29px"});
		   currentSlider = "d";
		break;
		
		case 5:
		   $("#e").css({backgroundPosition:"-352px -29px"});
		   currentSlider = "e";
		break;
	}
	
	$('#contUL').stop().scrollTo( $('#'+contarSlider), 1000, {axis:"x", onAfter:function(){myInterval = setInterval(incrementaSlider,15000);}});
}

function incrementaSlider()
{
	
	clearInterval(myInterval);
	
	if(contarSlider < $("#inicio ul#ulInicio li").length)
	{
		contarSlider++;
	}
	else
	{
		contarSlider = 1;
	}
	loadSlider();
}

function loadPic(cualpic)
{
	
	  $("#loadBan").replaceWith('<div id="loadBan" class="loading"></div>');
	  
	  var img = new Image();

	  // wrap our new image in jQuery, then:
	  $(img)
		// once the image has loaded, execute this code
		.load(function () {
		  // set the image hidden by default    
		  $(this).hide();
		
		  // with the holding div #loader, apply:
		  $('#loadBan')
		     // remove the loading class (so no background spinner), 
			.removeClass('loading')
			// then insert our image
			.append(this);
		
		  // fade our image in to create a nice effect
		  $(this).fadeIn(500);
		})
		
		// if there was an error loading the image, react accordingly
		.error(function () {
		  // notify the user that the image could not be loaded
		}).attr( {src: 'images_lrc/'+cualpic+'.png'});
		
}


var currentIdNot = "";
var activoNot="";

function loadNot(idNot)
{
	

		$.ajax({
		
				url:'secciones/noti.php?id_not='+idNot,
				
				success: function(msg){
					
				 $('.col_cen').html(msg)
				 
				},
				
				complete:function(success){
				
					
				$('.boton').click(function() {
						
						if($(activoNot).attr('id') != ""){
							
							$(activoNot).next().slideToggle('normal');

						};
						
						if($(this).attr('id') == $(activoNot).attr('id')){
							
							activoNot="";
							
						}else{
							
							$(this).next().slideToggle('normal',function(){ showText();});

							 activoNot=this;	

							};
						
						return false;
				});//END CLICK CLASS BOTON
					
			
				   if(noti && noti != ""){
					  sub_activoNot=activarMenu(noti);
					  currentIdNot = noti;
					  activoNot = sub_activoNot;
					  showText();
					  
				   }//end if nota
		   }//END COMPLETE
		})//END AJAX


}//END LOADSEM

function activarMenu(sec)
{
		
	if(sec!="none"){
		
		$('#sec'+sec).next().slideToggle('normal');
		
		return $("#sec"+sec+".boton");
		
	}
}

function showText()
{
		
    $('.cont_texto').css( {visibility: "visible"});	
}

var activoPag="";
function paginacion(num)
{
	 $.ajax({
		
				url:'secciones/noti.php?pagina='+num,
				
				success: function(msg){
					
				 $('.col_cen').html(msg)
				 
				},
				
				complete:function(success){
	
				$('.boton').click(function() {
						
						if($(activoPag).attr('id') != ""){
							
							$(activoPag).next().slideToggle('normal');
						
						};
						
						if($(this).attr('id') == $(activoPag).attr('id')){
							
							activoPag="";
							
						}else{
							
							$(this).next().slideToggle('normal',function(){showText();});

							 activoPag=this;	
 
							};

						return false;
				});//END CLICK CLASS BOTON
					
		   }//END COMPLETE
		})//END AJAX
	 
}

function showBtnEnviar(
){
	$('#btn_Enviar').css({display:"block"});
}

function publish(titulo,mensaje){
	FB.ui(
		  {
		  method: 'stream.publish',
		  message: mensaje,
		  attachment: {
		  name: titulo,
		  caption: 'www.lrc.com.mx',
		  media: [{
			   type: 'image', src:'http://www.lrc.com.mx/images/foto_share_fb.jpg', 
		       href: 'http://www.lrc.com.mx'}],
		  description: (
					  'Expertos en ingenieria financiera'
					   ),
					   href: 'http://www.lrc.com.mx'
				   },
		  user_message_prompt: 'Comparte tus imagen'
				   },
				   
		  function(response) {
			   if (response && response.post_id) {
				  // alert('La foto se ha publicado exitosamente.');
			   } else {
				   //alert('No se pudo completar');
			   }
		   }
		);
}
