﻿sfHover = function() {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
	        this.className+=" over";
        }
        sfEls[i].onmouseout=function() {
	        this.className=this.className.replace(new RegExp(" over\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


// jQuery
function baseInit()
{
    $("#foot-content .padding ul li a").hover(
    function(e) {
        $(this).stop().animate({
            paddingLeft: "10px"
        }, 200);
    },
    function(e) {
        $(this).stop().animate({
            paddingLeft: "0px"
        }, 200);
    });                       
    
    // from zachstronaut.com
    // ps. i <3 zach
    // Tracks browser resize and viewport size for Analytics
    if (typeof pageTracker != 'undefined') {
        pageTracker._trackEvent(    'Browser Dimensions',
                                    'load',
                                    $(window).width()
                                        + 'x'
                                        + $(window).height(),
                                    $(window).width());
    
        $(window).resize(function () {
            pageTracker._trackEvent(    'Browser Dimensions',
                                        'resize',
                                        $(window).width()
                                            + 'x'
                                            + $(window).height(),
                                        $(window).width());
                                        
        });
    }

    enable_smooth_scroll();
}

// http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
// major changes by Paul Armstrong and Zachary Johnson
function enable_smooth_scroll() {
    function filterPath(string) {
        return string
                .replace(/^\//, '')
                .replace(/(index|default).[a-zA-Z]{3,4}$/, '')
                .replace(/\/$/, '');
    }

    var locationPath = filterPath(location.pathname);
    
    var scrollElement = 'html, body';
    $('html, body').each(function() {
        var initScrollTop = $(this).attr('scrollTop');
        $(this).attr('scrollTop', initScrollTop + 1);
        if ($(this).attr('scrollTop') == initScrollTop + 1) {
            scrollElement = this.nodeName.toLowerCase();
            $(this).attr('scrollTop', initScrollTop);
            return false;
        }
    });

    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if (locationPath == thisPath
                && (location.hostname == this.hostname || !this.hostname)
                && this.hash.replace(/#/, '')
            ) {
            if ($(this.hash).length) {
                $(this).click(function(event) {
                    var targetOffset = $(this.hash).offset().top;
                    var target = this.hash;
                    event.preventDefault();
                    $(scrollElement).animate({ scrollTop: targetOffset }, 500, function() {
                        location.hash = target;
                    });
                });
            }
        }
    });
}


$(baseInit);