$(function(){
	$("a[rel='lightbox']").lightBox();
	
	$('#menuNav ul li.submenu').hover(
		function(){ //mouse over
			$(this).find('ul').stop(true, true).slideDown();
			//$('#menuNav').animate({ 'height': '72px' });
		},
		function(){ //mouse out
			$(this).find('ul').stop(true, true).slideUp('fast');
			//$('#menuNav').animate({ 'height': '40px' }, 'fast');
		}
	);

});

function checkLogin(){
	var username = jQuery('#username').val();
	var pass = jQuery('#pass').val();
	jQuery('#verificando').show();
		
	jQuery.ajax({
		type: "POST",
		url: "classes/checkLogin.php",
		data: "username="+username+"&pass="+pass,
		success: function(msg){
			jQuery('#verificando').hide();
			if(msg=="error"){
				jQuery('#msg_error').show();
			} else {
				document.cookie="iDUsuario="+msg;
				window.location.reload();
			}
		}
	});
}

//Clima
var localidad_id = "ARMA0056";
var parametros = {};
parametros.op = 'clima';
parametros.localidad_id = localidad_id;

jQuery.post('/mcms/clima.php', parametros, function(resultado) {
	if (resultado.error)
		alert(resultado.mensaje);
	else {
		var clima = resultado.clima;
		jQuery('#lblEstado').html(clima.estado);
		jQuery('#lblTemperatura').html(clima.temperatura+"&deg;");
		jQuery('#imgEstado').html('<img src="/mcms/img/clima/'+clima.codigo+'.png">');
	}
}, 'json');

function updateClock(){
	var currentTime = new Date();
	var currentHours = currentTime.getHours();
	var currentMinutes = currentTime.getMinutes();
	var currentSeconds = currentTime.getSeconds();
	
	currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
	currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
	//currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
	//currentHours = (currentHours == 0) ? 12 : currentHours;
	
	var currentTimeString = currentHours + ":" + currentMinutes;
	jQuery("#clock").html(currentTimeString);
}

function setComentario(){
	jQuery('#enviando').show();
	jQuery('#btnenviar').hide();
	
	var datos = {};
	datos.titulo = jQuery('#titulo').val();
	datos.comentario = jQuery('#comentario').val();
	datos.idusuario = jQuery('#idusuario').val();
	datos.idnota =  jQuery('#idnota').val();
	
	jQuery.post('classes/setComentario.php', datos, function(resultado) {
		if (resultado.error)
			alert(resultado.mensaje);
		else {
			jQuery('#enviando').hide();
			jQuery('#nocoments').hide();
			jQuery('#btnenviar').show();
			
			jQuery('#ncdatos').append(resultado.attr['3']);
			jQuery('#nctitle').html(resultado.attr['1']);
			jQuery('#nctexto').html(resultado.attr['2']);
			jQuery.scrollTo('#cuadrocomentarios', 500, {onAfter:function(){ jQuery('#nuevocomentario').toggle('slow') }});
		}
	}, 'json');
}

function checkFormContacto(){
	var f = document.frmcontacto;
	var msg = document.getElementById("msg");
	if(f.nombre.value=='' || f.apellido.value=='' || f.email.value=='' || f.telefono.value=='' || f.mensaje.value==''){
		alert("Faltan campos por completar");
		return false;
	} else {
		return true;
	}
}

function addFF(){
	//Para internet explorer
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		var url="http://www.noticiasparatodos.com.ar/";
		var titulo="Noticias para Todos";
		window.external.AddFavorite(url,titulo);
	}
	
	//Para Netscape y Firefox
	else {
		if(navigator.appName == "Netscape") alert("Presione Crtl+D para agregar a este sitio en sus Bookmarks");
	}
}

function setHomePage(obj){
	if((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>3)){
		obj.style.behavior="url(#default#homepage)";
		obj.setHomePage("http://www.noticiasparatodos.com.ar/");
	} else {
		alert("Función sólo disponible en Internet Explorer");
	}
}

