(function(){

  angular
    .module('izApp')
    .directive('kontakte', kontakteDirective);
 
kontakteDirective.$inject=["ContactsService"];  
function kontakteDirective(ContactsService){
	return {
	    restrict: 'E',
	  	template: '<div ng-include="templateUrl"></div>',
	  	scope: {
		  kontaktData: "@",
		  templateName: '@',
		  mailSubject: "@"
		},
	  	controller: kontakteController
	};
}
  
 kontakteController.$inject=["$scope","UtilService"];
 function kontakteController($scope,UtilService){
		   
		  	if($scope.templateName && $scope.kontaktData){
			  $scope.kontakte = JSON.parse($scope.kontaktData);
			  $scope.kontakteChunks = UtilService.chunkArray($scope.kontakte,2+$scope.kontakte.length%2);
			  $scope.templateUrl = '/backend/resources/api/templates/name/' + $scope.templateName + '/render';  
			}
		  
		    $scope.calcColWidth = function(noOfElementsInRow,width){
				if (noOfElementsInRow==3){
					return 4;
				}
			    
			    if(noOfElementsInRow==2){
					return 6;
				}
			  
			    if(noOfElementsInRow==1){
					return 12;
				}
			  
			    return 4; // default : 3 elements per row
			}; 
  }
  
}());
