
cdm.api.Home=cdm.api.Home?cdm.api.Home:{};cdm.api.Home.getImageCarouselError=$("#cdm_language_error_herewasaproblemretrievingtheimages").val();cdm.api.Home.collectionNameString="CDMREPLACECOLLECTIONNAME";cdm.api.Home.collectionCount=0;cdm.api.Home.currentCollection=0;cdm.api.Home.collectionRange=0;cdm.api.Home.scrollDivHeight=500;cdm.api.Home.scrollContainerHeight=0;cdm.api.Home.lazyload="off";cdm.api.Home.initialCarouselsLoaded=false;cdm.api.Home.initialCarouselCounter=0;cdm.api.Home.collectionsToLoad=0;cdm.api.Home.scrollBusy=false;cdm.api.Home.carouselsNotLoaded=new Array();cdm.api.Home.carouselsNotLoadedCount=0;cdm.api.Home.collectionsNotLoaded=new Array();cdm.api.Home.delayedCarouselLoader=function(){cdm.util.ConsoleLogger("in the delayed carousel loader..."+cdm.api.Home.carouselsNotLoadedCount);if(cdm.api.Home.carouselsNotLoadedCount>0){for(c=0;c<cdm.api.Home.carouselsNotLoadedCount;c++){cdm.util.ConsoleLogger("should load delayed carousel for ... "+cdm.api.Home.collectionsNotLoaded[c]);$("#imageCarousel_"+cdm.api.Home.collectionsNotLoaded[c]).html(cdm.api.Home.carouselsNotLoaded[c]);$(".cdm-carousel-home-"+cdm.api.Home.collectionsNotLoaded[c]).jcarousel({scroll:1,visible:3,itemVisibleInCallback:cdm.util.jcarouselLazyClassCheck});}
cdm.api.Home.collectionsNotLoaded=[];cdm.api.Home.carouselsNotLoaded=[];cdm.api.Home.carouselsNotLoadedCount=0;}}
cdm.api.Home.getImageCarousel=function(collection){return $.ajax({type:"GET",url:"/utils/getimagecarousel/collection/"+collection,dataType:"html"}).done(function(msg){if(msg!="failure"&&msg!="nocarousel"){if($("#imageCarousel_"+collection).exists()){$("#imageCarousel_"+collection).html(msg);$(".cdm-carousel-home-"+collection).jcarousel({scroll:1,visible:3,itemVisibleInCallback:cdm.util.jcarouselLazyClassCheck});}else{cdm.util.ConsoleLogger("imageCarousel_"+collection+" DOES NOT EXIST!!!");cdm.api.Home.collectionsNotLoaded[cdm.api.Home.carouselsNotLoadedCount]=collection;cdm.api.Home.carouselsNotLoaded[cdm.api.Home.carouselsNotLoadedCount]=msg;cdm.api.Home.carouselsNotLoadedCount++;}}else if(msg=="failure"){$("#imageCarousel_"+collection).html("");cdm.util.ajaxErrorAlerts(cdm.api.Home.getImageCarouselError,"","","");}}).fail(function(a,b,c){$("#imageCarousel_"+collection).html();cdm.util.ajaxErrorAlerts(cdm.api.Home.getImageCarouselError,a,b,c);});}
cdm.api.Home.initialCollectionLoader=function(){$.when(cdm.api.Home.getImageCarousel(collectionCarousels[cdm.api.Home.initialCarouselCounter])).then(function(){if(cdm.api.Home.initialCarouselCounter<collectionTotal){cdm.api.Home.initialCarouselCounter++;if(cdm.api.Home.initialCarouselCounter<carouselCount){cdm.api.Home.initialCollectionLoader();}else{if(cdm.api.Home.lazyload=="off"){cdm.api.Home.homepageCollections();}}}});}
cdm.api.Home.init=function(){cdm.api.Home.initialCollectionLoader();}
$(document).ready(function(){if($("#cdm_language_error_failedtoretrieveimages").exists()){cdm.api.Home.getImageCarouselError=$("#cdm_language_error_failedtoretrieveimages").val();}
cdm.api.Home.lazyload=$("#cdm_homepage_lazyload").val();cdm.api.Home.currentCollection=collectionHomepageLoadLimit;cdm.api.Home.collectionRange=collectionHomepageLoadRange;if($("#cdm_lazy_home_linker").exists()){cdm.api.Home.bindMoreCollectionsLink();}
if(cdm.api.Home.lazyload=="on"){cdm.api.Home.collectionsToLoad=cdm.api.Home.collectionRange+collectionHomepageLoadLimit;cdm.api.Home.lazyBinder();if(collectionTotal>collectionHomepageLimit&&$("#homePageCollectionScrollContainer").exists()){cdm.api.Home.scrollContainerHeight=$("#homePageCollectionScrollContainer").height();cdm.api.Home.adjustScrollHeight(cdm.api.Home.scrollContainerHeight);}}else{cdm.api.Home.collectionsToLoad=collectionTotal;cdm.api.Home.currentCollection++;cdm.api.Home.collectionLoadCounter=1;}
cdm.api.Home.init();});cdm.api.Home.adjustScrollHeight=function(containerHeight){if(containerHeight<=cdm.api.Home.scrollDivHeight){cdm.api.Home.currentCollection=cdm.api.Home.currentCollection+1;collalias=cdmHomepageCollections[cdm.api.Home.currentCollection];collname=cdmHomepageCollectionNames[cdm.api.Home.currentCollection];$.when(cdm.api.Home.homepageInfo(collalias,collname)).then(function(){if(cdm.api.Home.currentCollection<collectionTotal){cdm.api.Home.scrollContainerHeight=$("#homePageCollectionScrollContainer").height();cdm.api.Home.adjustScrollHeight(cdm.api.Home.scrollContainerHeight);}})}}
cdm.api.Home.bindMoreCollectionsLink=function(){$("#cdm_lazy_home_linker").click(function(){cdm.api.Home.collectionsToLoad=cdm.api.Home.currentCollection+cdm.api.Home.collectionRange;cdm.api.Home.currentCollection++;cdm.api.Home.collectionLoadCounter=1;cdm.api.Home.homepageCollections();});}
cdm.api.Home.homepageCollections=function(){if(cdm.api.Home.currentCollection<=collectionTotal){if($("#cdm_lazy_home_linker").exists()){$("#cdm_lazy_home_linker").addClass("cdm_hide");}
cdm.api.Home.scrollBusy=true;collalias=cdmHomepageCollections[cdm.api.Home.currentCollection];collname=cdmHomepageCollectionNames[cdm.api.Home.currentCollection];$.when(cdm.api.Home.homepageInfo(collalias,collname),cdm.api.Home.getImageCarousel(collalias)).then(function(){if(cdm.api.Home.currentCollection<cdm.api.Home.collectionsToLoad){cdm.api.Home.collectionLoadCounter++;cdm.api.Home.currentCollection++;cdm.api.Home.homepageCollections();}else{cdm.api.Home.scrollBusy=false;if(cdm.api.Home.currentCollection<collectionTotal&&$("#cdm_lazy_home_linker").exists()){$("#cdm_lazy_home_linker").removeClass("cdm_hide");}
cdm.api.Home.delayedCarouselLoader();}});}}
cdm.api.Home.lazyBinder=function(){if($("#homePageCollectionLimit").exists()){$("#homePageCollectionLimit").scroll($.throttle(1500,cdm.api.Home.runHomepageScroller));}}
cdm.api.Home.runHomepageScroller=function(){if(!cdm.api.Home.scrollBusy){cdm.api.Home.homepageScroller();}}
cdm.api.Home.homepageScroller=function(){if(cdm.api.Home.currentCollection<collectionTotal){cdm.api.Home.collectionsToLoad=cdm.api.Home.currentCollection+cdm.api.Home.collectionRange;cdm.api.Home.currentCollection++;cdm.api.Home.collectionLoadCounter=1;cdm.api.Home.homepageCollections();}}
cdm.api.Home.homepageInfo=function(alias,thename){if(typeof(alias)!=='undefined'){return $.ajax({type:"GET",url:"/utils/getcollectionhomepagetext/collname/"+encodeURIComponent(thename)+"/collection/"+alias,dataType:"json"}).done(function(msg){if(msg.status=="success"){$("#idx_coll_"+msg.alias).html(msg.html).removeClass("cdm_hide");}else{cdm.util.ConsoleLogger("status was: "+msg.status);cdm.util.ConsoleLogger("html was: "+msg.html);}}).fail(function(msg){cdm.util.ConsoleLogger(cdm.gvars.cdmError+": "+msg);});}}