var activeIndustries = new Array();
var activeObjectives = new Array();

var dpoolBaseUrl = '';

var imageGalleryOptions = {
	ease: 'easeInOutCubic',
	speed: 800,
	width: 380,
	height: 333,
	direction : 'horizontal' // vertical horizontal diagonal
}

$(document).ready(function(){
	dpoolBaseUrl = $('base').attr('href');
	$("#tx_dpcustomers_pi1-customer-imageGallery").jqGalScroll(imageGalleryOptions);
});

function showDetails(customerUid){
	$('#tx_dpcustomers_pi1-greylayer').show();
	$('#tx_dpcustomers_pi1-customer-details').html('');
	$('#tx_dpcustomers_pi1-loading').show();
	$('#tx_dpcustomers_pi1-customer-container').fadeIn('fast');
	
	var data = {
		dp_ajax_extkey: 'dp_customers',
		dp_ajax_code: 'show_details',
		customerUid: customerUid
	};

	$('#tx_dpcustomers_pi1-customer-details').load(
		dpoolBaseUrl + 'index.php?eID=dp_ajax',
		data,
		resultDetailsReady
	);	
}

function hideDetails() {
	$('#tx_dpcustomers_pi1-greylayer').hide();
	$('#tx_dpcustomers_pi1-customer-container').hide();
}

function resultDetailsReady () {
	$('#tx_dpcustomers_pi1-loading').hide();
	$('#tx_dpcustomers_pi1-customer-details').show();
	$("#tx_dpcustomers_pi1-customer-imageGallery").jqGalScroll(imageGalleryOptions);
}	

function showObjectives (objectiveUid, linkObject) {
	if($(linkObject).hasClass('act')) {
		$(linkObject).removeClass('act');
		activeObjectives = $.grep(activeObjectives, function (objective) { return objective != '.o-' + objectiveUid; });
		checkFilter();	
	} else {
		$(linkObject).addClass('act');
		activeObjectives.push('.o-' + objectiveUid);
		checkFilter();
	}
}

function showIndustries (industryUid, linkObject) {		
	if($(linkObject).hasClass('act')) {
		$(linkObject).removeClass('act');
		activeIndustries = $.grep(activeIndustries, function (industry) { return industry != '.i-' + industryUid; });
		checkFilter();	
	} else {
		$(linkObject).addClass('act');
		activeIndustries.push('.i-' + industryUid);
		checkFilter();
	}
}

function checkFilter() {
		
		if(activeObjectives.length > 0) { 
			var oPath = activeObjectives.join(','); 
			$('#objectives-reset').removeClass('act');
		} else { 
			var oPath = 'td';
			$('#objectives-reset').addClass('act');
		}
		if(activeIndustries.length > 0) { 
			var iPath = activeIndustries.join(','); 
			$('#industries-reset').removeClass('act');
		} else { 
			var iPath = 'td'; 
			$('#industries-reset').addClass('act');			
		}
		$('td').find('.tx_dpcustomers_pi1-customer-logo-grey').fadeIn('fast');
		$(oPath).filter(iPath).find('.tx_dpcustomers_pi1-customer-logo-grey').hide();

}

function resetObjectives() {
		
	$('#tx_dpcustomers_pi1-objectives .objectives-links').removeClass('act');
	activeObjectives = new Array();
	checkFilter();
	$('#objectives-reset').addClass('act');
}

function resetIndustries() {
	$('#tx_dpcustomers_pi1-industries .industries-links').removeClass('act');
	activeIndustries = new Array();
	checkFilter();
	$('#industries-reset').addClass('act');
}