$(document).ready(function() {
    $(document).pngFix();
    dUp.showDetails();
    dUp.backToTop();
    dUp.flir();
})

var dUp = {
    flir: function() {
        FLIR.init({path: fullurl+'facelift/'}, new FLIRStyle({mode:'wrap'}));
        $('h1').each(function() { FLIR.replace(this); });
        $('h2').each(function() { FLIR.replace(this); });
    },
    
    backToTop: function() {
        $('.backToTop').click(function() {
            $.scrollTo('body', 500);
            return false;
        })
    },
    
    showDetails: function() {
        $('.portElm').each(function() {
            var tElm = $(this);
            var tOverlay = tElm.find('.overlay:first');
            var tImg = tElm.find('.portImg:first');
            var tElmY = tElm.height();
            var tOverlayY = tOverlay.height();
            
            tImg.hide();
            tOverlay.hide();
            
            tElm.onImagesLoad({
                callback: function() {
                    tImg.fadeIn();
                    
                    tElm.bind('mouseenter', function() {
                        var YoffSet = this.offsetTop;
                        
                        if(tOverlayY < tElmY) {
                            $().mousemove(function(e) {
                                var tPadding = 25;
                                var tCenter = 10;
                                
                                if($.browser.safari) {
                                    tPadding = 60;
                                    tCenter = 20;
                                }
                                
                                var Y = e.pageY - YoffSet - (tOverlayY / 2 + tCenter);
                                
                                if(Y + tOverlayY + tPadding > tElmY) {
                                    tOverlay.css({bottom: 0})
                                } else if (Y <= 0) {
                                    tOverlay.css({top: 0, bottom: "auto"})
                                } else {
                                    tOverlay.css({top: Y, bottom: "auto"})
                                }
                            })
                        } else {
                            tOverlay.css({top: 0, bottom: 0, overflow: "auto"})
                        }
                        
                        tOverlay.fadeIn();
                    }).bind('mouseleave', function() {
                        tOverlay.fadeOut();
                    })
                }
            })
        })
    }
}