$(document).ready(function(){
	function parseForm(gets) {
		// IE7 sends aboslute urls, so always split on the ?
		var getParams = ((typeof(gets) == 'undefined')? '': gets.split('?')[1]);
		$.post('/gateway/json?'+ getParams, $("#projectFilter").serialize(), function(data){
			$('#resultsValue').html(data.count);
			$('#projectRows').html(data.html);
			$.each(data.numbers, function(key, value){
				$('#'+ key +'Value').html('('+ value +')');
				if (value < 1) {
					$('#'+ key +',label[for='+ key +'],label[for='+ key +'] span').addClass('disabled');
					$('#'+ key).attr('disabled', 'disabled');
				} else {
					$('#'+ key +',label[for='+ key +'],label[for='+ key +'] span').removeClass('disabled').removeAttr('disabled');
				}
			});
			$('#navigation').html(data.navigation);
			$('#navigation a').click(function(){
				parseForm($(this).attr('href'));
				return false;
			});
		}, 'json');
	}
	$('#whiteBox a.hrImage').lightBox({fixedNavigation:true});
	$('#resetButton').click(function(){
		$('#projectFilter input[checked]').removeAttr('checked');
		$('.toggleAll input').attr('checked', 'checked');
	});
		
	$('#projectFilter input:not(#search)').click(function(){ parseForm(''); });
	$('#projectFilter #orderBy').change(function(){ parseForm(''); });
	
	$('#projectFilter').submit(function(){
		parseForm('');
		return false;		
	});
	parseForm('');
});

$(window).load(function(){
	$('#logo, #footer').ifixpng();
	$('#referenceLogos').cycle({random: 1, pause: 1, speed: 0, timeout: 1000 });

	$('.thumbImage').click(function() {
		$('#mainImage').attr('src','/download/?id='+ $(this).attr('id').substr(5)+'&width=329&height=216&zc=1');
		$('#mainImage').attr('alt', $(this).attr('alt'));
	});

	$('#mainImage').click(function(){
		$('#whiteBox a.hrImage:first').click();
	});
});