//url del sitio
var urlSite = "http://www.lahora.com.ec/index.php/";
var urlBase = "http://www.lahora.com.ec/";
var urlImages = "http://images.lahora.com.ec/";

/*var urlSite = "http://192.168.0.253/~carlita/laHora/index.php/";
var urlBase = "http://192.168.0.253/~carlita/laHora/";
var urlImages = "http://192.168.0.253/~carlita/laHora/"; 
*/

function showPortada(){
	
	
	var id = $("#ctIbox").attr("href");
	
	
	var htmlIbox = $(id).html();
	
	iBox.show(htmlIbox , '', {width: '490', height: '500'});
								
	}

function cambiarMenu(id){

$("#divInteres").html('<img src="' + urlBase + 'frontEnd/images/load.gif">');

$.ajax({
        type: "POST",
        url:  urlBase + "index.php/formularioRegistro/getSubSeccionesInteres/" + id,
        success: function(datos){
          
		$("#divInteres").html(datos);
		  
      }
      });


}

function cuadroImagenes(idImagen){
	
	var seccion = $("#" + idImagen).attr("secc");
	var imagen = $("#" + idImagen).attr("numImg");
	
	var htmlIbox = '<iframe src="' + urlBase + '/galeria_imagenes/index/' + seccion + '/' + imagen + '" width="710" height="600" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="margin:0px;"  ></iframe><style type="text/css">#ibox_content {	width:712px !important;	height:600px !important;</style>';
	
	iBox.show(htmlIbox , '', {width: '712', height: '600'});
								
}

$("#regiones").change(function(){

alert('ok');
							   
});

$(document).ready(function(){

cambiarMenu(0);

});

$(function() { /* cuando se acaba de caragar la página */ 
	
	/* NAVEGACION CAJAS OTRAS NOTICIAS  PEQUEÑAS */
	
	$(".otrasNoticiasCaja").each(function(i){
	
		//flechita de arriba
		
		var thisScrollTop = $(this).children("#scrollControls").children("#scrollTop");
		
		$(thisScrollTop).click(function(){
		
		 var thisUl = $(this).parent().parent();
		
		 thisUl.children("ul").scrollTo('-=50', 500 );
		
		});
		
		//flechita de abajo
		
		
		var thisScrollBottom = $(this).children("#scrollControls").children("#scrollBottom");
		
		$(thisScrollBottom).click(function(){
		
		 var thisUl = $(this).parent().parent();
		
		 thisUl.children("ul").scrollTo('+=50', 500 );
		
		});
	
	});



	
	
		   
		   
	
	var currentNav; 
	
	$("#edicionesAnteriores").datepicker();	/* este es un calendario */
	
	$("#edicionesAnteriores").change(function(){ /* la accion de cuando se cambia de fecha*/					
		
		//pasar al controlador la fecha de la edicion de la vista
		goDateEdition($("#edicionesAnteriores").val());
		
	});
	
	$("#headerLogin").click(function(){ /* la cajita del log in que se muestra cuando se da click en log in*/									 
		$boxClass = $("#logInBox");
		if($("#logInBox").attr("class") == 'hidden'){
			$boxClass.removeClass('hidden');
			$boxClass.addClass('visible'); 
			$("#userName").focus();
		}else{
			$boxClass.removeClass('visible');
			$boxClass.addClass('hidden'); 
		}			
	});
	
	$('.close_headerLogin').click(function(){ 							 
		$boxClass = $("#logInBox");
		$boxClass.removeClass('visible');
		$boxClass.addClass('hidden'); /* boton para cerrar la caja del log in */				
	});
	
	
	
	$(".clickClear").click(function(){ /* limpia los valores cuando se da click en el item*/									   
		$(".clickClear").val(''); 			
	});
	
	/**********************
		MAIN NAVIGATION
	************************/
	
	$(".navLevel_0").mouseover(function(){ /* navigation Actions */
			currentNav = $(this).attr('id');
			$('#'+currentNav).css('border','none');
			$('#'+currentNav+"_link").css('border','none');
			$('#'+currentNav).addClass('mainMenuOn');	
			/*$(this).addClass('navActiveHover');*/
			idSon = $(this).attr('rel');
			$('.context').addClass('hidden');
			$('.context').removeClass('visible');
			$('#'+ idSon).addClass('visible');
			$('#'+ idSon).removeClass('hidden');
			//alert(menuItem);
	});
	$(".navLevel_0").mouseout(function(){
		$('#'+currentNav).removeClass('mainMenuOn'); 
		$('#'+currentNav). css('border-right','#fff 1px dotted');
		$('#'+currentNav+"_link").css('color','#666666');
		$('#'+ idSon).addClass('hidden');
		$('#'+ idSon).removeClass('visible');
	});
	$(".context").mouseover(function(){
		$('#'+currentNav).addClass('mainMenuOn'); //mantiene prendido el tab del menu al que pertenece el submenu
		$('#'+currentNav+"_link").css('color','#FFFF00');
	});
	$(".context").mouseout(function(){
			//$(this).removeClass('navActive');						
			$('.context').addClass('hidden');
			$('.context').removeClass('visible');
			$('#' + currentNav).removeClass('mainMenuOn');
			//alert(menuItem);
	});
	
	/***********************
		SCROLL
	**********************/	
	
	var sCroll = 0;
	var scrollMove = 300;
	var timeToMove = 1000;
	var currentContainer;
	var newMainHeight = $('#mainNews').height();
	var tHeight = newMainHeight;
	//$('#ultimaHoraContainer').height(tHeight);
	$('#ultimaHoraHome123').height($('#mainNews').height() - 60);
	//alert(tHeight);
	$("#scrollBottom") 
			.click(function(){
				//alert(sCroll + '  ' + newMainHeight);
				currentContainer = 'ultimaHoraHome123';
				//alert(currentContainer);
				//alert($('#' + currentContainer).height());
				setTimeout
                (
                        function()
                        {
                                $('#' + currentContainer).animate({ 
									scrollTop: sCroll
								  }, timeToMove );
								 //$('#' + currentContainer).scrollTo( '+=100px', 800 );
                        },
                        1
                );
				if(sCroll == scrollMove){
					sCroll = scrollMove;	
				}
				if(tHeight == 0){
					$('#' + currentContainer + ' li').each(function(index){
						tHeight += $(this).height();
					});
				}
				//alert(sCroll + ' , '+ tHeight);
				
/*				if(sCroll >= (tHeight + scrollMove + scrollMove)){
					sCroll = 0;
				}else{
					sCroll += scrollMove;	
				}*/
				sCroll += scrollMove;
				
			});
	$("#scrollTop") 
			.click(function(){
				currentContainer = 'ultimaHoraHome123';
				setTimeout
                (
                        function()
                        {
                                $('#' + currentContainer).animate({ 
									scrollTop: sCroll
								  }, timeToMove );
								 //$('#' + currentContainer).scrollTo( '+=100px', 800 );
                        },
                        1
                ); 
				sCroll -= scrollMove;
				if(sCroll <= 0){
					sCroll = 0;
				}
				
			});
			
	
	/*****************************
		ViDEO SCROLL
	*******************************/
	
	
	
	
	
	
	
	/*****************************
		ROUNDED CORNER ITEMS
	***************************/
	
	//$('#portadasContainer').corner("round br 20px");
	//$('#portadasContainer').css("background", "#000");
	//$('#portadasContainer').corner("round br 20px").parent().css('padding', '2px').corner("round br 20px")
	

	/*****************************
		CUADRO TABS HOME
	***************************/	
	$('#cuadroTab-1').tabs({ fxFade: true, fxSpeed: 'fast' });
	$('#cuadroTab-2').tabs({ fxFade: true, fxSpeed: 'fast' });
	$('#cuadroTab-3').tabs({ fxFade: true, fxSpeed: 'fast' });


	
});

/* END cuando se acaba de caragar la página */

//establece la fecha de la edicion del a vista
function goDateEdition(fecha){

$.ajax({
        type: "POST",
        url: urlBase + "home/goDateEdition/"+fecha,
        success: function(datos){
          
		  if(datos == "1"){
		  
		  window.location.href = urlBase;
		  
		  }
		  
      }
      });


}

function goRegional(){

var region = $("#regional").val();

$.ajax({
        type: "POST",
        url: urlBase + "home/goRegional/"+region,
        success: function(datos){
          
		  if(datos == "1"){
		  
		  window.location.href = urlBase;
		  
		  }
		  
      }
      });

}


function goRegionalByRegion(region, flag){


$.ajax({
        type: "POST",
        url: urlBase + "home/goRegional/"+region,
        success: function(datos){
          
		  if(datos == "1"){
		  	if(!flag){
		  		window.location.href = urlBase;
			}else{
				window.location.href = urlBase + 'secciones/show/Vida Social/907';
			}
		  
		  }
		  
      }
      });

}

function recargarSeccion(div, page){
//alert(page);
//jQuery("#"+ div).load(page);
value1 = 'manteco';

jQuery("#"+ div).load(page,{var1: value1},function(){
//alert('se supone que ya hice');
});

}




	/* Llamadas a Corousel{ */
	

/*	jQuery('.video-carousel').jcarousel({
				scroll:2,
				animation: "slow",
				vertical: true
			});*/

	
	
	jQuery('.media_gallery').media_gallery({
		thumbnail_element: 'span',
	  	target_container: '#gallery_display'
	});
	
	/****************** IMAGE CARROUSEL CALL ********************************/
	
	$(document).ready(function() {
			$('.image-carousel').jcarousel({
				scroll:1,
				animation: "slow",
				wrap:"last"
			});	
			
			/*avanza y retrosede imagenes mas grande */
			$siguienteCarr = $('#imgSigu');						
			$siguienteCarr.click(function() {
				if(numeroImgCarr<(imagenesCarr.length-1)){
					numeroImgCarr++;
					$('#viewPhoto').attr('src',imagenesCarr[numeroImgCarr]);
					$('#pieGalleryText').html(titulosCarr[numeroImgCarr]);
					//$("#viewPhotoIbox").attr("href", imgGrandeCarr[numeroImgCarr]);
					$("#viewPhotoIbox").attr("secc", currentCarr[numeroImgCarr]);
					$("#viewPhotoIbox").attr("numImg", [numeroImgCarr+1]);
				}
				$('#contImg').html(numeroImgCarr+1);
				
			});
			$anteriorCarr = $('#imgAnte');						
			$anteriorCarr.click(function() {
				if(numeroImgCarr>0){
					numeroImgCarr--;
					$('#viewPhoto').attr('src',imagenesCarr[numeroImgCarr]);
					$('#pieGalleryText').html(titulosCarr[numeroImgCarr]);
					//$("#viewPhotoIbox").attr("href", imgGrandeCarr[numeroImgCarr]);
					$("#viewPhotoIbox").attr("secc", currentCarr[numeroImgCarr]);
					$("#viewPhotoIbox").attr("numImg", [numeroImgCarr+1]);					
				}
				$('#contImg').html(numeroImgCarr+1);
				
			});			
			
		
			$('.image-carousel').children('li').each(function () {	
				$(this).click(function(event){
					
					$('#fotoGaleriaFotos').html('<img src="' + urlImages + 'loader.gif" />');
					//alert('manteco');
					var actualImage = $(this).children('a').children('img').attr('rel');
					//var imageSrc = urlBase+'thump/phpThumb.php?src='+ urlBase +'frontEnd/images/objetos/' + actualImage +"&w=100";
					var imageSrc = actualImage;
					
					var titulo = $(this).children('a').children('div').children('div').attr('title');
					var tituloArt = $(this).children('a').children('div').children('div').attr('articulo');
					var articuloLink = $(this).children('a').children('div').children('div').attr('idArticulo');
					
					numeroImgCarr = $(this).children('a').children('div').children('div').attr('numImg'); //para saber en imagen del carrusel esta
					//alert(imageSrc);
					
					var bigImageParms = 'width="255" ';
					
					
//					$(".tituloPhoto").text(titulo);

                    $("#viewPhoto").attr("src", imageSrc);
					
					//$("#viewPhotoIbox").attr("href", imageSrc);
					//$("#viewPhotoIbox").attr("href", imgGrandeCarr[numeroImgCarr]);
					$("#viewPhotoIbox").attr("secc", currentCarr[numeroImgCarr]);
					$("#viewPhotoIbox").attr("numImg", [numeroImgCarr+1]);
					
					$(".pieFotoArticulo").text(titulo);
					
					$("#tituloArt").text(tituloArt);
					
					$('#contImgNew').html((numeroImgCarr*1)+1);
					
					$("#tituloArt").attr("href",urlBase+'index.php/noticias/show/'+articuloLink);
					
					$('#fotoGaleriaFotos').html('<a href="'+imageSrc+'" rel="ibox"><img src="'+ imageSrc +'"/></a>');
					
					//alert($('#fotoGaleriaFotos').html());
					
					$('#fotoGaleriaFotos').children('a').click(function(event){
						iBox.showURL(imageSrc);
						return false;
					});
				});
			});
			
			
			$('.portadas-carousel').jcarousel({
				scroll:3,
				animation: "slow",
				wrap:"last"
			});	
			
			
			$('.portadas-carousel').children('li').each(function () {	
				$(this).click(function(event){
					
					$('#fotoGaleriaPortadas').html('<img src="http://images.lahora.com.ec/loader.gif" />');
					//alert('manteco');
					var actualImage = $(this).children('a').children('img').attr('rel');
					var imageSrc = urlBase+'thump/phpThumb.php?src='+urlBase+'frontEnd/images/objetos/'+actualImage;
					
						//alert($(this).children('a').children('img').attr('alt'));
						
					$("#msgPortada").text($(this).children('a').children('img').attr('alt'));
					
                     var rel = "#" + $(this).children('a').children('img').attr('alt');
					
					$('#fotoGaleriaPortadas').html('<a id="ctIbox" onclick="showPortada()" href="'+rel+'" rel="ibox"><img src="' + imageSrc + '&w=140&h=190 " /></a>');
					
					
					
				});
			});
		
		});
	
	
	/* }Fin Llamadas corusel*/


function sendMailToFriend(){

if($("#txtNombreFrom").val() == ""){

alert("Debe ingresar su nombre correctamente");

return;

}

if($("#txtNombreTo").val() == ""){

alert("Debe ingresar el nombre del destinatario correctamente");

return;

}

if($("#txtEmailFrom").val() == ""){

alert("Debe ingresar su mail correctamente");

return;

}

if($("#txtEmailTo").val() == ""){

alert("Debe ingresar el mail del destinatario correctamente");

return;

}


if($("#txtAsunto").val() == ""){

alert("Debe ingresar un asunto");

return;

}


// Interceptamos el evento submit
$.ajax({
        type: "POST",
        url: urlBase + "frontEnd/sendMailFriend.php",
		data: $('#formSendFriend').serialize(),
        success: function(datos){
			alert(datos);
			 window.location.href = urlBase + 'noticias/show/' + $("#idSeccion").val() ;
         } 
      });





} 

/************************** CUADROS HOME *******************************/

function mycarousel_initCallbackDeportivo(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
    	carousel.stopAuto();
	carousel.startAuto(5);														  
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};
function mycarousel_initCallbackSocial(carousel) {
	jQuery('.jcarousel-controlSocial a').bind('click', function() {
	carousel.stopAuto();
	carousel.startAuto(5);																
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};
/*****************************
	CARRUSEL DEPORTIVO
***************************/
function highlightDeportivo(carousel, obejctli,liindex,listate){ 
	 $('#imgDep_'+liindex).addClass("active-thumb");
};
function removehighlightDeportivo(carousel, obejctli,liindex,listate){ 
	 $('#imgDep_'+liindex).removeClass("active-thumb");
};

/*****************************
	CARRUSEL SOCIAL
***************************/
function highlightSocial(carousel, obejctli,liindex,listate){ 
	 $('#imgSoc_'+liindex).addClass("active-thumb-social");
};
function removehighlightSocial(carousel, obejctli,liindex,listate){ 
	 $('#imgSoc_'+liindex).removeClass("active-thumb-social");
};

jQuery(document).ready(function() {
    jQuery('.jcarousel-skin-slider').jcarousel({
        auto: 5,
		scroll:1,
        wrap: 'last',
		animation: 500,
        initCallback: mycarousel_initCallbackDeportivo,
		itemVisibleInCallback:  highlightDeportivo,
		itemVisibleOutCallback: removehighlightDeportivo
    });
	 jQuery('.jcarousel-skin-social').jcarousel({
        auto: 6,
		scroll:1,
        wrap: 'last',
		animation: 500,
        initCallback: mycarousel_initCallbackSocial,
		itemVisibleInCallback:  highlightSocial,
		itemVisibleOutCallback: removehighlightSocial
    });
});

/*******************************
	PANEL EDICIONES ANTERIORES
*******************************/
$('#panelEdicAnte').animate({
		 left: '110px'
		 }, 1000, function() {
		 // Animation complete.
}); 
$(document).ready(function() {
	$('#panelEdicAnte').mouseover(function() {
		$('#panelEdicAnte').stop().animate({
		 left: '110px'
		 }, 1000, function() {
		 // Animation complete.
		 }); 
	});
	
	$('#panelEdicAnte').mouseout(function() {
		$('#panelEdicAnte').stop().animate({
		 left: '-2px'
		 }, 1000, function() {
		 // Animation complete.
		 }); 
	});
	setTimeout(function(){   
		$('#panelEdicAnte').stop().animate({
			 left: '-2px'
			 }, 1000, function() {
			 // Animation complete.
		}); 
	}, 6000 ); 
});


/***********************************************************************/

/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
 
    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
 
    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};
 
// Ride the carousel...
jQuery(document).ready(function() {
    jQuery("#mycarouselNew").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});
 

/***************** scroll videos side bar *****************/
var videoControlTop = jQuery(".flechasVideos #scrollTop");
var videoControlBottom = jQuery(".flechasVideos #scrollBottom");


jQuery(videoControlTop).click(function() {

jQuery("#navVideosNew").scrollTo('-=82', 500 );

});

jQuery(videoControlBottom).click(function() {

jQuery("#navVideosNew").scrollTo('+=82', 500 );

});

/***************** articulo Portada Feature *****************/
$("#botPrevFeature").click(function(){
	if(contImgFeat>0){
		contImgFeat--;
		$('#imagenFeat').html('<img src="' + imagenesFeature[contImgFeat] +'" alt="' + piesFeature[contImgFeat] + '" style="float:none;" />');
		$('#pieFotoFeat').text(piesFeature[contImgFeat]);
		$('#countsFeat').text(contImgFeat+1);
	}
});

$("#botNextFeature").click(function(){
	if(contImgFeat<imagenesFeature.length-1){		
		contImgFeat++;
		$('#imagenFeat').html('<img src="' + imagenesFeature[contImgFeat] +'" alt="' + piesFeature[contImgFeat] + '" style="float:none;" />');
		$('#pieFotoFeat').text(piesFeature[contImgFeat]);
		$('#countsFeat').text(contImgFeat+1);
	}
});

$("#preFlecha").click(function(){
	if(contImgFeat>0){
		contImgFeat--;
		$('#imagenFeat').html('<img src="' + imagenesFeature[contImgFeat] +'" alt="' + piesFeature[contImgFeat] + '" style="float:none;" />');
		$('#pieFotoFeat').text(piesFeature[contImgFeat]);
		$('#countsFeat').text(contImgFeat+1);
	}
});

$("#nexFlecha").click(function(){
	if(contImgFeat<imagenesFeature.length-1){		
		contImgFeat++;
		$('#imagenFeat').html('<img src="' + imagenesFeature[contImgFeat] +'" alt="' + piesFeature[contImgFeat] + '" style="float:none;" />');
		$('#pieFotoFeat').text(piesFeature[contImgFeat]);
		$('#countsFeat').text(contImgFeat+1);
		
		$('#imagenFeat').children().css("display", "none");



		$('#imagenFeat').children().fadeIn('slow', function() {
		});
	}
});







