$(document).ready(function(){

	$('#whiteBox a.hrImage').lightBox({fixedNavigation:true});
	
	function parseForm(){
		$.post('/gateway/json', $("#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', true);
				} else {
					$('#'+key+',label[for='+key+'],label[for='+key+'] span').removeClass('disabled').removeAttr('disabled');
				}
			});
		}, 'json');
	}
	
	$('#resetButton').click(function(){
		$('#projectFilter input[checked]').removeAttr('checked');
		$('.toggleAll input').attr('checked', 'checked');
	});
		
	$('#projectFilter input:not(#search)').click(parseForm);
	$('#projectFilter #orderBy').change(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');
	});

	$('#mainImage').click(function(){
		$('#whiteBox a.hrImage:first').click();
	});
		
    $('#country').change(function(){
    	location.href='<?php echo $currentPage->getUrl(); ?>&country='+$(this).val()+'&branche='+$('#branche').val();
    });

    $('#branche').change(function(){
    	location.href='<?php echo $currentPage->getUrl(); ?>&country='+$('#country').val()+'&branche='+$(this).val();
    });
});
	