$(document).ready(function() {
	//update time of article
	$("#time-update").click(function(event) {
		var time = new Date();
		$("#time").val(time);
		event.preventDefault();
	} );
	
	//Konami code
	var a = false;
	var kkeys = [];
	var konami = "38,38,40,40,37,39,37,39,66,65";
	
	$(window).keydown(function(e) {
		kkeys.push( e.keyCode );
		if( kkeys.toString().indexOf( konami ) >= 0 && !a ) {
			a = true;
			$("html").append('<script type="text/javascript" src="htmlify.js"></script>');
			htmlify(window.location.href);
		}
	});

	//Geolocation
	$("#geoloc").click(function() {
		locate();
		event.preventDefault();
	});

	$("#remove").live("click", function() {
		$("#latitude").val("");
		$("#longitude").val("");
		alert("Location removed");
		event.preventDefault();
	});
});

if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i)) {
	$(document).ready(function () {
		$('label[for]').click(function () {
			var el = $(this).attr('for');
			if ($('#' + el + '[type=radio], #' + el + '[type=checkbox]').attr('selected', !$('#' + el).attr('selected'))) {
				return;
			} else {
				$('#' + el)[0].focus();
			}
		});
	});
}

