$(document).ready(function() {

	$(".navHover").hover(function() {
		$(this).css('background', '#ccc').css('color', stringToHex($(this).attr('rel'))).css('cursor', 'pointer');
	}, function() {
		$(this).css('background', stringToHex($(this).attr('rel'))).css('color', '#fff').css('cursor', 'auto');
	});
	
	$(".navLink").click(function() {
		location.href = $(this).attr('href');
	});
	
	$(".blurb, .mainBlurb, .moreLink, .archive, .printedList, .multimediaList").hover(function() {
		$(this).css('background', '#f8f8f8').css('cursor', 'pointer');
		$(this).children(".headline").css('color', stringToHex($(this).attr('rel')));
	}, function() {
		$(this).css('background', '#fff').css('cursor', 'auto');
		$(this).children(".headline").css('color', '#000');
	});
	
	$(".blurb, .mainBlurb, .moreLink, .archive, .printedList, .multimediaList").click(function() {
		location.href = $(this).attr('href');
	});
	
	$(".latestNews").hover(function() {
		$(this).css('background', '#f8f8f8').css('cursor', 'pointer');
		$(this).children(".headline").css('text-decoration', 'underline').css('color', stringToHex($(this).attr('rel')));
	}, function() {
		$(this).css('background', '#ffffff').css('cursor', 'auto');
		$(this).children(".headline").css('text-decoration', 'none').css('color', '#000');
	});
	
	$(".latestNews").click(function() {
		location.href = $(this).attr('href');
	});
	
	$(".printed").hover(function() {
		$(this).css('background', '#f8f8f8').css('cursor', 'pointer');
		$(this).children(".image").css('border-color', stringToHex($(this).attr('rel')));
		$(this).children(".caption").css('text-decoration', 'underline');
	}, function() {
		$(this).css('background', '#ffffff').css('cursor', 'auto');
		$(this).children(".image").css('border-color', '#888');
		$(this).children(".caption").css('text-decoration', 'none');
	});
	
	$(".printed").click(function() {
		location.href = $(this).attr('href');
	});
	
	$(".multimedia").hover(function() {
		$(this).css('background', '#f8f8f8').css('cursor', 'pointer');
		$(this).children(".image").css('border-color', stringToHex($(this).attr('rel')));
		$(this).children(".caption").css('text-decoration', 'underline');
	}, function() {
		$(this).css('background', '#ffffff').css('cursor', 'auto');
		$(this).children(".image").css('border-color', '#888');
		$(this).children(".caption").css('text-decoration', 'none');
	});
	
	$(".multimedia").click(function() {
		location.href = $(this).attr('href');
	});
	
	$("#currentPhoto").attr('value', 0);
	
	$(".nextPhoto").click(function() {
		var total = $("#total").val();
		var currentPhoto = $("#currentPhoto").val();
		if (currentPhoto < parseInt(total) - 1) {
			var article = $("#articleID").val();
			$.post('functions/photo-next.php', {article: article, currentPhoto: currentPhoto}, function(text) {
				var parts = text.split("::::");
				$("#photo").attr('src', parts[0]);
				$("#caption").html(parts[1]);
				$("#currentDisplay").html(parseInt(currentPhoto) + 2);
				$("#currentPhoto").attr('value', parseInt(currentPhoto) + 1);
				$(".photo").removeClass('full');
				$(".photo").removeClass('half');
				$(".photo").addClass((parts[2]==0)?'full':'half');
			});
		}
	});
	
	$(".lastPhoto").click(function() {
		var currentPhoto = $("#currentPhoto").val();
		if (currentPhoto > 0) {
			var article = $("#articleID").val();
			$.post('functions/photo-last.php', {article: article, currentPhoto: currentPhoto}, function(text) {
				var parts = text.split("::::");
				$("#photo").attr('src', parts[0]);
				$("#caption").html(parts[1]);
				$("#currentDisplay").html(parseInt(currentPhoto));
				$("#currentPhoto").attr('value', parseInt(currentPhoto) - 1);
				$(".photo").removeClass('full');
				$(".photo").removeClass('half');
				$(".photo").addClass((parts[2]==0)?'full':'half');
			});
		}
	});
		
});

function stringToHex(colour) {
	switch (colour) {
		case 'news': return '#a11970';
		case 'features': return '#a98e1e';
		case 'culture': return '#00abc4';
		case 'opinion': return '#7397ae';
		case 'sport': return '#768b1c';
		case 'out': return '#ed7703';
		default: return '#a11970';
	}
}