// safely establish namespaces...
if (typeof ActiveCommerce == 'undefined')
	ActiveCommerce = {};

if (typeof ActiveCommerce.Config == 'undefined')
	ActiveCommerce.Config = {};

if (typeof ActiveCommerce.Config.Home == 'undefined')
	ActiveCommerce.Config.Home = {};

ActiveCommerce.Home = {
	config : {
		sliderId : 'slider',
        analyticsTrackEvent : '_trackEvent',
        analyticsCategory : 'ActiveCommerce-HomePage',
        analyticsActionSliderClick : 'Slider-Click',
        analyticsActionFeaturedProductClick : 'FeaturedProduct-Click',
        analyticsActionPromoClick : 'Promo-Click'
	},
	
	init : function() {
		with (ActiveCommerce.Home) {
			jQuery('#' + ActiveCommerce.Home.config.sliderId).nivoSlider({			
				effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
				animSpeed:500, // Slide transition speed
				pauseTime:5000, // How long each slide will show
				directionNav:true, // Next & Prev navigation
				directionNavHide:true, // Only show on hover
				controlNav:true, // 1,2,3... navigation
				controlNavThumbs:false, // Use thumbnails for Control Nav
				keyboardNav:false, // Use left & right arrows
				manualAdvance:false, // Force manual transitions
				captionOpacity:1 // Universal caption opacity
			});
		}
	},

    initAnalytics : function () {
        if (typeof(_gaq) != 'undefined') {
            var config = ActiveCommerce.Home.config;
            jQuery('#' + config.sliderId + ' a.nivo-imageLink').click(function() {
                var image = jQuery(this).children('img').first();
                var index = jQuery(this).index('.nivo-imageLink') + 1;  //index() is 0-based
                _gaq.push([config.analyticsTrackEvent, config.analyticsCategory, config.analyticsActionSliderClick, image.attr('src'), index]);
                return true;
            });
            jQuery('#featured-products a').click(function() {
                var product = jQuery(this).attr('href');
                var index = jQuery(this).parent().index('.thumb') + 1;
                _gaq.push([config.analyticsTrackEvent, config.analyticsCategory, config.analyticsActionFeaturedProductClick, product, index]);
            });
            jQuery('#spiffs a').click(function() {
                var promo = jQuery(this).attr('href');
                var index = jQuery(this).parent().index() + 1;
                _gaq.push([config.analyticsTrackEvent, config.analyticsCategory, config.analyticsActionPromoClick, promo, index]);
            });
        }
    }
}

jQuery(ActiveCommerce.Home.init);
jQuery(ActiveCommerce.Home.initAnalytics);
