// function to execute after data is returned and dom is ready
function populateHome() {
	
	jQuery(document).ready(function($) {      			
		
		// highlight main navigation tab
		jQuery('ul#nav li').removeClass('selected');
		jQuery('li#home').addClass('selected');
		
		// category nav
		jQuery('#categoriesTpl').tmpl(BP.data.stores.categoriesStore, {
			categoryLink: BP.fm.categoryLink
		}).appendTo('ul.list1');
		
		// featured products
		jQuery('#featuredProductsTpl').tmpl(BP.data.stores.productsStore, {
			productLink: BP.fm.productLink,
			productImg: BP.fm.productImg
		}).appendTo('ul.list3');
	   
     	
     	$('#news').innerfade({
						animationtype: 'slide',
						speed: 750,
						timeout: 2000,
						type: 'random',
						containerheight: '1em'
					});
					
					$('ul#zimgs').innerfade({
						speed: 1000,
						timeout: 5000,
						type: 'sequence',
						containerheight: '216px'
					});
					
					$('.fade').innerfade({
						speed: 1000,
						timeout: 6000,
						type: 'random_start',
						containerheight: '1.5em'
					});
					
					$('.adi').innerfade({
						speed: 'slow',
						timeout: 5000,
						type: 'random',
						containerheight: '150px'
					}); 
	});
}

// start loading data
BP.fetch.getCategories();
BP.fetch.getHomeProducts(populateHome);
