/**
 * Classe respons�vel pelos servi�os.
 */
iMicrocis.Service.Interface = Class.create(iMicrocis.Interface, 
{
    /**
     * Executa ao instanciar a classe.
     */
    initialize: function() {},
    
    /**
     * Carrega a interface.
     * 
     * @param String area A classe da �rea a ser carregada.
     */
    load: function(area)
    {
        switch (area)
        {
            case 'technical-assistance':
                new Effect.Appear($(area).getElementsByClassName('container')[0], {duration: 0.5, from: 0, to: 1, queue: {position: 'end', scope: 'interface-01'}});
                
                break;
            case 'internet-and-design':
                new Effect.Appear($(area).getElementsByClassName('container')[0], {duration: 0.5, from: 0, to: 1, queue: {position: 'end', scope: 'interface-01'}});
                
                break;
            case 'print':
                new Effect.Appear($(area).getElementsByClassName('container')[0], {duration: 0.5, from: 0, to: 1, queue: {position: 'end', scope: 'interface-01'}});
                
                Event.observe($$('body#print a.botao-portfolio')[0], 'click', function(e) {
                    e.stop();
                    
                    new Ajax.Request('/service/print/portfolio.php', {
                        onSuccess: function(Transport) {
                            var Interface = new iMicrocis.Interface;
                            
                            // Insere o conteúdo do portfólio mais o blackout.
                            $$('body#print')[0].insert(Transport.responseText);
                            
                            pageSize = Interface.getPageSize();
                            
                            // Define a largura e a altura do blackout.
                            $$('body#print div.blackout-portfolio')[0].setStyle({
                                width: pageSize[0]+'px',
                                height: pageSize[1]+'px'
                            });
                            
                            // Exibe o blackout.
                            new Effect.Appear($$('body#print div.blackout-portfolio')[0], {
                                duration: 0.3,
                                from: 0,
                                to: 0.7,
                                queue: {
                                    position: 'end',
                                    scope: 'print/portfolio'
                                }
                            });
                            
                            // Exibe o portfólio.
                            new Effect.Appear($$('body#print div.portfolio')[0], {
                                duration: 0.3,
                                from: 0,
                                to: 1,
                                delay: 0.2,
                                queue: {
                                    position: 'end',
                                    scope: 'print/portfolio'
                                }
                            });
                            
                            scrollCount = 0
                            
                            idScrollUpInterval = null;
                            idScrollDownInterval = null;
                            
                            scrollActions = {
                                up: function() {
                                    $$('body#print div.portfolio div.content')[0].scrollTop = scrollCount-2;
                                
                                    if (scrollCount > 0)
                                        scrollCount = scrollCount - 2; 
                                },
                                
                                down: function() {
                                    $$('body#print div.portfolio div.content')[0].scrollTop = scrollCount+2;
                                    
                                    if ((scrollCount+455) < $$('body#print div.portfolio div.content')[0].scrollHeight)
                                        scrollCount = scrollCount + 2;
                                }
                            }
                            
                            Event.observe($$('body#print div.portfolio a.fechar')[0], 'click', function(e) {
                                e.stop();
                                
                                // Exibe o portfólio.
                                new Effect.Fade($$('body#print div.portfolio')[0], {
                                    duration: 0.3,
                                    from: 1,
                                    to: 0,
                                    queue: {
                                        position: 'end',
                                        scope: 'print/portfolio'
                                    }
                                });
                                
                                new Effect.Fade($$('body#print div.blackout-portfolio')[0], {
                                    duration: 0.3,
                                    from: 0.7,
                                    to: 0,
                                    queue: {
                                        position: 'end',
                                        scope: 'print/portfolio'
                                    },
                                    afterFinish: function() {
                                        $$('body#print div.blackout-portfolio')[0].remove();
                                        $$('body#print div.portfolio')[0].remove();
                                    }
                                });
                            });
                            
                            Event.observe($$('body#print div.portfolio div.arrow-top')[0], 'mousedown', function() {
                                idScrollUpInterval = setInterval('scrollActions.up()', 10);
                            });
                            
                            Event.observe($$('body#print div.portfolio div.arrow-top')[0], 'mouseup', function() {
                                clearInterval(idScrollUpInterval);
                            });
                            
                            Event.observe($$('body#print div.portfolio div.arrow-top')[0], 'mouseout', function() {
                                clearInterval(idScrollUpInterval);
                            });
                            
                            Event.observe($$('body#print div.portfolio div.arrow-bottom')[0], 'mousedown', function() {
                                idScrollDownInterval = setInterval('scrollActions.down()', 10);
                            });
                            
                            Event.observe($$('body#print div.portfolio div.arrow-bottom')[0], 'mouseup', function() {
                                clearInterval(idScrollDownInterval);
                            });
                            
                            Event.observe($$('body#print div.portfolio div.arrow-bottom')[0], 'mouseout', function() {
                                clearInterval(idScrollDownInterval);
                            });
                        }
                    })
                });
                
                break;
            case 'sell-and-lease':
                new Effect.Appear($(area).getElementsByClassName('container')[0], {duration: 0.5, from: 0, to: 1, queue: {position: 'end', scope: 'interface-01'}});
                
                break;
            case 'system':
                new Effect.Appear($(area).getElementsByClassName('container')[0], {duration: 0.5, from: 0, to: 1, queue: {position: 'end', scope: 'interface-01'}});
                
                $(area).getElementsByClassName('content')[0].getElementsByClassName('left')[0].getElementsByClassName('system')[0].getElementsByClassName('link').each(
                    function(element, index) {
                        Event.observe(element, 'click', function(e) {
                            _Microcis = new iMicrocis;
                            _Microcis.extend('with-service --with-service-system');
                            
                            _Microcis.Service.System.load(element.ancestors()[0].classNames());
                            
                            new Effect.toggle(element.ancestors()[0].ancestors()[0], 'appear', {duration: 0.2})
                        });
                    }
                );
                
                $(area).getElementsByClassName('content')[0].getElementsByClassName('right')[0].getElementsByClassName('back-to-home').each(
                    function(element, index) {
                        Event.observe(element.descendants()[0], 'click', function(e) {
                            _Microcis = new iMicrocis;
                            _Microcis.extend('with-service --with-service-system');
                            
                            _Microcis.Service.System.load('home');
                        });
                    }
                );
                
                break;
        }
    }
});