$(document).ready(function(){
	$(document).pngFix();

	$('form.star-rating').each(function(i) {
		var fid = $(this).attr('id');
		$(this).children().not(':radio').hide();
		$(this).stars({
			callback: function(ui, type, value)
			{
				if ($('div.login-box').html().indexOf('account') !== -1) {
					$.post('ajax_rating.php', {id: fid, score: value});
				}
				else {
					window.location.href = 'login.php?return=' + encodeURIComponent(location.href);
				}
			}
		});
		$(this).show();
	});

	$('a.report').fancybox({
		'frameHeight': 250,
		'hideOnContentClick': false
	});

	$('a.media-link').fancybox({
		'frameHeight': 344,
		'frameWidth': 425,
		'hideOnContentClick': false
	});

	$('a.location-find').fancybox({
		'frameHeight': 430,
		'frameWidth': 500,
		'hideOnContentClick': false
	});
});

function characterCount(id) {
	var total = (140 - $('#comments').val().length);
	$('#counter').text(total);
	if (total < 1) {
		$('#comments').val($('#comments').val().substring(0, 140));
		$('#counter').text(0);
	}
}

function uploadFileManual() {
	if ($('#fileInput').val() == "") {
		alert('Please select a file!');
		return false;
	}
	else if ($('input:checked').length == 0) {
		alert('Please tick that you have read the terms and conditions!');
		return false;
	}
	else {
		$('#step1').hide();
		$('#step2').show();
		return true;
	}
}