var idToIgnore = false;
if (typeof(tracker) == 'undefined') {
    tracker = false;
}


var guidedTourDelegate = {

    changeToDimensions: function(newDimensions) {
        var container = this.view.view.view();
        if (container) {
            var currentDimensions = container.getDimensions();

            if (this.view.options.shouldAnimateContentChange) {
                new Effect.Parallel([
                    new Effect.Scale(container, ((newDimensions.width / currentDimensions.width) * 100), { scaleY:false, scaleContent:false, sync:true }),
                    new Effect.Scale(container, ((newDimensions.height / currentDimensions.height) * 100), { scaleX:false, scaleContent:false, sync:true })
                ], { duration:this.view.options.animationDuration });
            } else {
                container.style.width = newDimensions.width+'px';
                container.style.height = newDimensions.height+'px';
            }
        }
    },

    didAppendContent: function(view) {
        this.init(view);

        var incoming = view.currentSection;
        if (incoming) {
            this.changeToDimensions(incoming.content.getDimensions());
        }
    },

    init: function(view) {
        if (!this.view) this.view = view;
    },

    willShow: function(view, outgoing, incoming) {
        this.init(view);
    },

    didShow: function(view, outgoing, incoming) {
        this.init(view);
    }
}

Event.observe(window, 'load', function() {
    var splash = $('moviecontainer').down('.section');
    if (AC.Detector.isMobile()) {
        splash.addClassName('mobile');
    } else {
        splash.addClassName('standard');

        var sections = $$('.section')

        // set the height of the container to the height of the first content
        var height = splash.getHeight();
        $('moviecontainer').style.height = height+'px';

        // For IE we need to remove this node before swap view takes over
        // because swap view's innerHTML = '', breaks the splash
        splash.remove();

        if (!tracker) {
            tracker = new AC.ViewMaster.Tracker('click');
        }

        // set up the view master
        var view = new AC.ViewMaster.Viewer(sections, 'moviecontainer', 'size', { initialId:idToIgnore, animationDuration:.4, alwaysShowSection:true, shouldAnimateContentChange:true });
        view.setDelegate(guidedTourDelegate);
        view.didAppendContent(splash);

        // special tracking on the download links
        var downloadLinks = $$('.quicklinks .download');
        if (downloadLinks.length > 0) {
            downloadLinks[0].observe('mousedown', function(evt) {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.match('safari')) {
                    AC.Tracking.trackClick({
                        pageName: AC.Tracking.pageName()
                    }, this, 'd', evt.href);
                }
            });
        }
    }
});
