angular.module("fluro").directive("preloadImage",function(){return{restrict:"A",link:function(scope,element,attrs){var aspect=angular.isDefined(attrs.aspect)?scope.$parent.$eval(attrs.aspect):0;aspect||(aspect=0),scope.aspect=aspect,aspect?element.wrap('<div class="preload-image-outer aspect-ratio" style="padding-bottom:'+scope.aspect+'%"></div>'):element.wrap('<div class="preload-image-outer"></div>');var preloader=angular.element('<span class="image-preloader"><i class="fa fa-spinner fa-spin"/></span>');element.on("load",function(){element.removeClass("preload-hide"),element.addClass("preload-show"),preloader.remove()}),scope.$watch("ngSrc",function(){element.addClass("preload-hide"),element.parent().append(preloader)})}}}),angular.module("fluro").directive("menu",function(){return{restrict:"E",replace:!0,template:'<ul class="basic-menu basic-menu-{{trigger}}"><li ng-if="trigger != \'click\'" ng-repeat="menuItem in model" ng-class="{\'dropdown\':menuItem.items.length, \'open\':isExpanded(menuItem)}"><a ng-class="{\'hidden-xs\':menuItem.items.length}" class={{menuItem.class}} ui-sref={{getSref(menuItem)}} ui-sref-opts=menuItem.stateRefOptions ng-if="menuItem.type == \'state\'" ui-sref-active=active><span compile-html=menuItem.title></span> <span ng-if=menuItem.items.length class=caret></span> </a><a ng-class="{\'hidden-xs\':menuItem.items.length}" class={{menuItem.class}} ng-attr-target="{{(menuItem.target.length) ? menuItem.target : undefined}}" ng-href={{menuItem.url}} ng-if="menuItem.type != \'state\'"><span compile-html=menuItem.title></span> <span ng-if=menuItem.items.length class=caret></span> </a><a ng-click=isolateToggle(menuItem) class="visible-xs-block {{menuItem.class}}" ng-if=menuItem.items.length><span compile-html=menuItem.title></span><span class=caret></span></a><ul class=dropdown-menu ng-if=menuItem.items.length><li ng-repeat="subMenuItem in menuItem.items" ng-switch=subMenuItem.type><a ui-sref={{getSref(subMenuItem)}} ui-sref-opts=subMenuItem.stateRefOptions class={{menuItem.class}} ng-switch-when=state ui-sref-active=active><span compile-html=subMenuItem.title></span></a> <a ng-attr-target="{{(subMenuItem.target.length) ? subMenuItem.target : undefined}}" class={{menuItem.class}} ng-href={{subMenuItem.url}} ng-switch-default><span compile-html=subMenuItem.title></span></a></li></ul></li><li ng-if="trigger == \'click\'" ng-repeat="menuItem in model" ng-class="{\'dropdown\':menuItem.items.length, \'open\':isExpanded(menuItem)}"><a ui-sref={{getSref(menuItem)}} ui-sref-opts=menuItem.stateRefOptions ng-if="menuItem.type == \'state\' && !menuItem.items.length" class={{menuItem.class}} ui-sref-active=active><span compile-html=menuItem.title></span> <span ng-if=menuItem.items.length class=caret></span> </a><a ng-attr-target="{{(menuItem.target.length) ? menuItem.target : undefined}}" ng-href={{menuItem.url}} class={{menuItem.class}} ng-if="menuItem.type != \'state\' && !menuItem.items.length"><span compile-html=menuItem.title></span> <span ng-if=menuItem.items.length class=caret></span> </a><a ng-click=isolateToggle(menuItem) ng-if=menuItem.items.length class={{menuItem.class}}><span compile-html=menuItem.title></span> <span class=caret></span></a><ul class=dropdown-menu ng-if=menuItem.items.length><li ng-repeat="subMenuItem in menuItem.items" ng-switch=subMenuItem.type><a ui-sref={{getSref(subMenuItem)}} ui-sref-opts=subMenuItem.stateRefOptions ng-switch-when=state class={{menuItem.class}} ui-sref-active=active><span compile-html=subMenuItem.title></span> </a><a ng-attr-target="{{(subMenuItem.target.length) ? subMenuItem.target : undefined}}" class={{menuItem.class}} ng-href={{subMenuItem.url}} ng-switch-default><span compile-html=subMenuItem.title></span></a></li></ul></li></ul>',scope:{model:"=ngModel",trigger:"=?"},link:function(scope,element,attrs){scope.justified=!!angular.isDefined(attrs.justified)&&scope.$parent.$eval(attrs.justified)},controller:function($scope,$rootScope){$scope.trigger||($scope.trigger="hover"),$scope.expanded=[],$scope.getSref=function(menuItem){return menuItem.stateParams?menuItem.state+"("+JSON.stringify(menuItem.stateParams)+")":menuItem.state},$scope.isExpanded=function(menuItem){return _.contains($scope.expanded,menuItem)},$scope.expand=function(menuItem){if(!_.contains($scope.expanded,menuItem))return $scope.expanded.push(menuItem)},$scope.isolateToggle=function(menuItem){_.contains($scope.expanded,menuItem)?$scope.collapse(menuItem):$scope.expanded=[menuItem]},$scope.toggleExpanded=function(menuItem){$scope.isExpanded(menuItem)?$scope.collapse(menuItem):$scope.expand(menuItem)},$rootScope.$on("$stateChangeSuccess",function(){$scope.collapseAll()}),$scope.collapseAll=function(){$scope.expanded.length=0},$scope.collapse=function(menuItem){_.contains($scope.expanded,menuItem)&&_.pull($scope.expanded,menuItem)}}}}),angular.module("fluro").directive("hamburger",function(){return{restrict:"E",replace:!0,template:"<div class=hamburger><span></span> <span></span> <span></span> <span></span></div>",link:function($scope,$elem,$attr){}}}),angular.module("fluro").directive("googleMap",function($window,$timeout){return{restrict:"E",replace:!0,template:"<div class=map-outer><div class=map-inner></div></div>",scope:{model:"=ngModel",selectCallback:"=ngSelectCallback",styleOptions:"=ngStyleOptions"},link:function($scope,$element,$attrs){function fitMap(){var bounds=new google.maps.LatLngBounds;_.each(markers,function(marker){var lat=marker.position.lat(),lng=marker.position.lng(),myLatLng=new google.maps.LatLng(lat,lng);bounds.extend(myLatLng)}),map.fitBounds(bounds)}var mapOptions,map,marker,geocoder,markers=[];styleOptions=[],$scope.styleOptions&&(styleOptions=$scope.styleOptions);var createMarker=function(location){if(location.latitude&&location.longitude){var position=new google.maps.LatLng(location.latitude,location.longitude);map.setCenter(position),marker=new google.maps.Marker({map:map,position:position,title:location.title}),google.maps.event.addListener(marker,"click",function(){$timeout(function(){$scope.selectCallback&&$scope.selectCallback(location)})}),markers.push(marker)}};$scope.$watch("model",function(model){model&&_.each(model,function(model){createMarker(model)}),fitMap()}),function(){console.log("Map starting"),mapOptions={zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP,disableDefaultUI:!1,maxZoom:15,scrollwheel:!1,draggable:!0,styles:styleOptions},map=new google.maps.Map($element.find(".map-inner").get(0),mapOptions),geocoder=new google.maps.Geocoder,angular.element($window).bind("resize",fitMap)}()}}}),angular.module("fluro").controller("RelatedProductController",function($scope,FluroContentRetrieval){$scope.$watch("slug.data.relatedProduct",function(related){var relatedIds=_.map(related,function(product){if(product._id)return product._id});if(relatedIds.length){var queryDetails={_id:{$in:relatedIds}};FluroContentRetrieval.query(queryDetails).then(function(data){$scope.products=data})}})}),angular.module("fluro").controller("RelatedProjectController",function($scope,FluroContentRetrieval){$scope.$watch("slug._id",function(id){var queryDetails={"data.relatedProduct":id};FluroContentRetrieval.query(queryDetails).then(function(data){$scope.projects=data})})}),angular.module("fluro").controller("ProjectListController",function($scope){$scope.$watch("collections",function(){if($scope.collections&&$scope.collections.length){var division=Math.floor($scope.collections[0].items.length/3);division<3&&(division=3);var items=$scope.collections[0].items;$scope.columns=_.chunk(items,division)}},!0),$scope.getAspect=function(image){return 100*(image.width>image.height?image.height/image.width:image.width/image.height)}}),angular.module("fluro").controller("ChunkController",function($scope,$filter){$scope.$watch("settings.search",function(terms){var filtered=$filter("filter")($scope.category.data.products,terms);$scope.chunked=_.chunk(filtered,4)})}),angular.module("fluro").controller("ChunkController2",function($scope,$filter){var makeChunk=function(list,terms){var filtered=$filter("filter")(list,terms);return _.chunk(filtered,4)},list="";$scope.$watch("settings.subcat",function(newValue,oldValue){list=null===newValue?$scope.category.data.products:$scope.category.data.subCategory[newValue].list,$scope.chunked=makeChunk(list,$scope.settings.search)}),$scope.$watch("settings.search",function(terms){$scope.chunked=makeChunk(list,terms)})}),angular.module("fluro").controller("CfsProductsController",function($scope,$stateParams){$scope.settings={},$scope.settings.active=void 0!==$stateParams.c?$stateParams.c:null,$scope.settings.subcat=null,$scope.toggle=function(catid,subcatIndex){$scope.settings.active=catid,$scope.settings.subcat=null,void 0!==subcatIndex&&($scope.settings.subcat=subcatIndex)},$scope.showAll=function(){$scope.settings.active=null,$scope.settings.subcat=null},$scope.isCategoryActive=function(catid){return $scope.settings.active===catid},$scope.isShowAll=function(){return null===$scope.settings.active&&null===$scope.settings.subcat}}),angular.module("fluro").controller("ColumnSplitController",function($scope){$scope.$watch("items[0]",function(item){if(item){var pieces=item.body.split("|");$scope.pieces=pieces}})}),angular.module("fluro").controller("AppController",function($rootScope){$rootScope.$on("$stateChangeStart",function(){$rootScope.mobileMenuExpanded=!1})}),angular.module("fluro").controller("HomeController",function($scope,$state){$scope.go=function(index){switch(index){case 0:$state.go("xchange");break;case 1:$state.go("scab");break;case 2:$state.go("lboard")}}}),angular.module("fluro").controller("ContactFormController",function($scope,$stateParams){$stateParams.pid&&$stateParams.pid.length&&$scope.$watch("formConfig.state",function(val){"ready"==val&&_.set($scope.formConfig,"model.product",$stateParams.pid)})});