var Featurespace = {
    init: function() {
        $('featurespace').addClass('noflash');
        this.navItems = $$('#features-nav a');
        this.features = $$('#features .feature');
        this.features.setStyle('display', 'none');
        
        this.navItems.each(function(item, idx) {
            item.addEvent('click', function(e) {
                e.preventDefault();
                Featurespace.goto(idx);
            });
        });
        
        this.goto(0);
    },
    goto: function(n) {
        if (this.currentNavItem) {
            this.currentNavItem.setStyle('display', 'block');
            var item = this.currentNavItem;
            setTimeout(function() {
                item.style.webkitTransform = 'translateX(0)';
            }, 100);
        }
        
        this.currentNavItem = this.navItems[n];
        this.currentNavItem.setStyle('display', 'none');
        this.currentNavItem.style.webkitTransform = 'translateX(-100%)'
        
        if (this.currentFeature) {
            this.currentFeature.setStyle('display', 'none');
            this.currentFeature.getElement(".product").style.webkitTransform = 'translateY(100%)';
        }
        
        this.currentFeature = this.features[n];
        this.currentFeature.setStyle('display', 'block');
        var product = this.currentFeature.getElement(".product");
        setTimeout(function() {
            if (product != null) {
                product.style.webkitTransform = 'translateY(0)';
            }
        }, 100);
    }
}

window.addEvent('domready', function() {
    if (swfobject.hasFlashPlayerVersion('9.0.24')) {
        // Flash Version
        swfobject.embedSWF('/_swf/featurespace.swf', 'featurespace', '100%', '499', '9.0.0', null, {data:'/en/xml/home/', autorotate:'0',feature:'0', ga: window.oldspiceGoogleAnalyticsKey}, {wmode:'opaque', allowScriptAccess:'always', allowFullScreen:'true'});
    } else {
        // JS Version
        Featurespace.init();
    }
});
