﻿
$(document).ready(function() {
    /*
    $('.home-nav li a').each(function() {
    $(this).attr('title', $(this).css('background-position') );
    });
    */

    function bkgPos(e, anchor) {

        switch (true) {
            case (e == 'up'):
                var pos = '0 ';
                break;
            case (e == 'over'):
                var pos = '-168px ';
                break;
            case (e == 'down'):
                var pos = '-336px ';
                break;
            case (e == 'active'):
                var pos = '-504px ';
        }

        switch (true) {
            case $(anchor).hasClass('about'):
                pos = pos + '0';
                break;
            case $(anchor).hasClass('account'):
                pos = pos + '-81px';
                break;
            case $(anchor).hasClass('residential'):
                pos = pos + '-162px';
                break;
            case $(anchor).hasClass('business'):
                pos = pos + '-243px';
                break;
            case $(anchor).hasClass('green'):
                pos = pos + '-324px';
                break;
            default:
        }
        return pos;
    }

    function resetAnchors() {
        $('.home-nav li a').each(function() {
            $(this).css('background-position', bkgPos('up', this));
        });
    }

    $('.home-nav li a').hover(
        function() {
            if ($(this).hasClass('active')) return;
            $(this).css('background-position', bkgPos('over', this));
        },
        function() {
            if ($(this).hasClass('active')) return;
            $(this).css('background-position', bkgPos('up', this));
        }
    );


    $('.home-nav li a').mousedown(function($e) {
        $e.preventDefault();
        $(this).css('background-position', bkgPos('down', this));
    });

    $('.home-nav li a').mouseup(function($e) {
        $e.preventDefault();
        $('.home-nav li a').removeClass('active').each(function() {
            $(this).css('background-position', bkgPos('up', this));
        });
        $(this).addClass('active');
        $(this).css('background-position', bkgPos('active', this));
    });
});
