$(document).ready(function() {
	sendContactUs();
	showSections();
	showFeed();	
});

function sendContactUs() {
	$('#frmContactenos').ajaxForm({
		dataType: 'json',
		url: 'php/enviarcontactenos.php',
		//clearForm: true,
		beforeSubmit: function(formData, jqForm, options) {
			// Se valida el formulario con el plugin jquery.validate
			var objValidator = $(jqForm).validate({errorLabelContainer: $("#" + jqForm.attr("id") + " div.error")});
			
			// Se retorna el resultado de la validación, si es falso se aborta el submit
			return(objValidator.form());
		},
		success: function(objJson) { 
			alert(objJson.message);
			/*if(!objJson.error) {
				$.jGrowl(objJson.message, {life: 1000, theme: 'greytheme'});
			}
			else {
				$.jGrowl(objJson.message, {life: 1000, theme: 'greytheme'});
			}*/
		}
	});
}

function showFeed() {
    var arrFeedsUrls = ['http://rss.cnn.com/rss/edition_technology.rss',
                     	'http://www.eltiempo.com/enter/rss.xml',
						'http://www.elcolombiano.com/rss/Tecnologia.xml']; 

	for(var intIndex = 0; intIndex<arrFeedsUrls.length; intIndex++) {
		jQuery.getFeed({
			url: 'php/feedproxy.php?url=' + arrFeedsUrls[intIndex],
			dataType: 'xml',
			success: function(feed) {
				jQuery('#feedcontent').append('<h2>'
				+ '<a style="color:#FFC310" href="'
				+ feed.link
				+ '">'
				+ feed.title
				+ '</a>'
				+ '</h2>');
				
				var html = '';
				
				for(var i = 0; i < feed.items.length && i < 5; i++) {
					var item = feed.items[i];
					
					html += '<h3>'
					+ '<a href="'
					+ item.link
					+ '">'
					+ item.title
					+ '</a>'
					+ '</h3>';
					
					html += '<div class="updated">'
					+ item.updated
					+ '</div>';
					
					html += '<div>'
					+ item.description
					+ '</div>';
				}
				html += "<br/><hr/>";
				jQuery('#feedcontent').append(html); 
			}
		});
	}
}

function showSections() {
	$("#proyectos").click(function() {
		$(".display").hide();
		$("#seccionproyectos").toggle();
	});

	$("#video").click(function() {
		$(".display").hide();
		$("#seccionvideo").toggle();
	});

	$("#capacitacion").click(function() {
		$(".display").hide();
		$("#seccioncapacitacion").toggle();
	});

	$("#diseno").click(function() {
		$(".display").hide();
		$("#secciondiseno").toggle();
	});	
}