﻿    /* Funções */
    
    $(document).ready(function() {
        
        var menu = $('#menu');
        $('<div class="bottom"></div>').appendTo(menu);
        menu.find('li').not('li li').last().addClass('last');
        menu.find('li').not('li li').hover(
            function(event) {
                event.preventDefault();
                $(this).find('ul').stop(true, true).animate({width:'toggle'}, 'fast');
            },
            function(event) {
                event.preventDefault();
                $(this).find('ul').stop(true, true).animate({width:'toggle'}, 'fast');
            }
        );
        
        //$('#direita').find('li').not('li li').last().css('margin-bottom', 0);
            
    });
    
    var site = {
    
        slider : function($obj) {
                
            $(window).load(function(){
                
                vetImgs = new Array();                $obj.find('li').each(function(i) {
                    $(this).show();
                    vetImgs[i] = $(this).find('img').height();                    $(this).hide();                });
                vetImgs.sort(function(a,b){return a - b});                $obj.height(vetImgs[vetImgs.length - 1]);
            
                $obj.find('li').first().fadeIn();
                $(function sliderDefault(){
                    $obj.delay(5000).queue(function(){
                        $(this).children('ul').children('li').each(function(){
                            if ($(this).css('display') != 'none') {
                                $(this).fadeOut('slow', function() {
                                    //$(this).appendTo($(this).parent());
                                    $(this).next().fadeIn('slow', function(){
                                        $(this).prev().appendTo($(this).parent());
                                        $obj.dequeue();
                                        sliderDefault();
                                    });
                                });
                            }
                        });
                    });                 
                });
                
            });            
        },
        
        corner : function($obj, prefix) {
            $obj.css('position', 'relative');
            $('<div class="' + prefix + '-top"><div class="l"></div><p></p><div class="r"></div></div>').prependTo($obj);
            $('<div class="' + prefix + '-bottom"><div class="l"></div><p></p><div class="r"></div></div>').appendTo($obj);
            w1 = (($obj.find('.' + prefix + '-top').find('.l').width() + $obj.find('.' + prefix + '-top').find('.r').width()) / 2) * 2;
            w2 = (($obj.find('.' + prefix + '-bottom').find('.l').width() + $obj.find('.' + prefix + '-top').find('.r').width()) / 2) * 2;
            $obj.find('.' + prefix + '-top').width($obj.outerWidth());
            $obj.find('.' + prefix + '-bottom').width($obj.outerWidth());
            $obj.find('.' + prefix + '-top').find('p').width($obj.outerWidth() - w1);
            $obj.find('.' + prefix + '-bottom').find('p').width($obj.outerWidth() - w2);
        }
    }
    
    function goTo() {
        //if ($(window).scrollTop() > $(window).height()) {
        if ($(document).height() > $(window).height()) {
            if ($(window).scrollTop() > 300) {
                $('#go-top').fadeIn('fast');
            } else {
                $('#go-top').fadeOut('fast');
            }
        }
    }
    
    $(window).load(function() {
        $('<a href="#topo" id="go-top" title="Ir para o topo"></a>').prependTo('.interna');        
        goTo();
        $('a[href=#topo]').click(function(){
           $('html, body').animate({scrollTop: 0 }, 'slow');
           return false;
        });
    });
    
    $(window).scroll(function() {
        goTo();   
    });
    
    
    
    
    
    
