/* ExI */
var ExI = new Class({
    Implements: Options,
    options: {
        url: 'http://blossam.co.jp',
        duration: 400,
        color: '#999'
    },
    initialize: function(options) {
        this.setOptions(options);
        
        $$('a').each(function(a) {
            a.set('tween', {
                duration: this.options.duration,
                transition: 'expo:out',
                link: 'cancel'
            });
            a.store('defaultColor', a.getStyle('color'));
            a.addEvents({
                mouseenter: function() {
                    a.tween('color', this.options.color);
                }.bind(this),
                
                mouseleave: function() {
                    a.tween('color', a.retrieve('defaultColor'));
                }.bind(this)
            });
        }.bind(this));
        
        
        $('global-nav').getElements('ul[class!=children] > li').each(function(li, liIndex) {
            var a = li.getElement('a');
            var text = a.get('text');
            
            li.setStyles({
                width: a.getSize().x,
                height: a.getSize().y
            });
            a.set('html', a.get('text') + '<br />' + a.get('text'));
            a.set('morph', {
                duration: this.options.duration,
                transition: 'expo:out',
                link: 'chain'
            });
            a.addEvents({
                mouseenter: function() {
                    a.morph({
                        'margin-top': - li.getSize().y
                    });
                }.bind(this),
                mouseleave: function() {
                    a.morph({
                        'margin-top': 0
                    });
                }.bind(this)
            });
            /*
            if (text == 'Online Shop' || text == 'Shopping Guide') {
                a.addClass('attach-tip');
                a.set('title', 'Coming Soon');
                a.addEvent('click', function(event) { event.stop() });
            }
            */
        }.bind(this));
        
        if ($('fixed-global-nav')) {
            $('fixed-global-nav').getElements('ul[class!=children] > li').each(function(li, liIndex) {
                var a = li.getElement('a');
                var text = a.get('text');
                
                /*
                if (text == 'Online Shop' || text == 'Shopping Guide') {
                    a.addClass('attach-tip');
                    a.set('title', 'Coming Soon');
                    a.addEvent('click', function(event) { event.stop() });
                }
                */
            }.bind(this));
        }
        
    }
});
/* GNV */
var GNV = new Class({
    Implements: Options,
    resizeTimer: null,
    scrollTimer: null,
    options: {
        wrapperIdName: 'wrapper',
        baseIdName: 'global-nav',
        fixedIdName: 'fixed-global-nav',
        duration: 200,
        transition: 'sine:in:out',
        opacity: 0.9
    },
    initialize: function(options) {
        this.setOptions(options);
        
        if (Browser.Engine.trident && Browser.Engine.version < 5) {
            $(this.options.fixedIdName).setStyle('display', 'none');
            return;
        }
        
        var fixedElement = $(this.options.fixedIdName);
        if ($defined(fixedElement) == false) {
            return;
        }
        
        fixedElement.store('defaultDisplay', fixedElement.getStyle('display'));
        fixedElement.addEvents({
            mouseenter: function() {
                fixedElement.get('tween', {
                    property: 'opacity',
                    duration: this.options.duration,
                    transition: this.options.transition,
                    link: 'chain'
                }).start(1);
            }.bind(this),
            
            mouseleave: function() {
                fixedElement.get('tween', {
                    property: 'opacity',
                    duration: this.options.duration,
                    transition: this.options.transition,
                    link: 'chain'
                }).start(this.options.opacity);
            }.bind(this)
        });
        fixedElement.setStyles({
            position: 'fixed',
            display: 'none',
            top: 0,
            opacity: this.options.opacity,
            'z-index': 99999999
        });
        
        this.toggle.run([], this);
        
        window.addEvents({
            scroll: function() {
                $clear(this.scrollTimer);
                this.scrollTimer = (function() {
                    this.toggle.run([], this);
                }.bind(this)).delay(200);
            }.bind(this),
            
            resize: function() {
                $clear(this.resizeTimer);
                this.resizeTimer = (function() {
                    this.toggle.run([], this);
                }.bind(this)).delay(200);
            }.bind(this)
        });
    },
    
    toggle: function() {
        var baseBottom = $(this.options.baseIdName).getCoordinates().bottom;
        var fixedElement = $(this.options.fixedIdName);
        fixedElement.setStyle('width', $(this.options.wrapperIdName).getComputedSize().totalWidth);
        
        if (window.getScroll().y > baseBottom) {
            if (fixedElement.getStyle('display') == 'none') {
                fixedElement.setStyle('display', fixedElement.retrieve('defaultDisplay'));
            }
            fixedElement.get('tween', {
                property: 'opacity',
                duration: this.options.duration,
                transition: this.options.transition,
                link: 'chain'
            }).start(this.options.opacity);
        } else {
            fixedElement.get('tween', {
                property: 'opacity',
                duration: this.options.duration,
                transition: this.options.transition,
                link: 'chain',
                onComplete: function() {
                    fixedElement.setStyle('display', 'none');
                }
            }).start(0);
        }
    }
});
