﻿// JavaScript Document
(function ($) {
    $.fn.squeakyNavMenu = function (options) {
        var 
			defaults = {
			    navDistances: 110,
			    navImage: '/images/nav.gif',
			    imageHeight: 15,
			    navElemWidth: [36, 104, 55, 52, 76, 80]
			},
			elemIndex = 0,
			settings = $.extend({}, defaults, options);
        /*Default State*/
        this.each(function (i) {
            currWidth = (settings.navElemWidth.constructor == Array ? settings.navElemWidth[i] : settings.navElemWidth);
            $(this).find('a').css({
                'background': 'url(' + settings.navImage + ') no-repeat -' + (i * settings.navDistances) + 'px 0',
                'width': currWidth + 'px'
            });
            /*On State Css*/
            if ($("body").attr('class') !== undefined) {
                var strClass = $("body").attr('class'),
					multiple = 0,
					arrClass = "",
					hoverState = false;
                if (strClass.indexOf(" ") != -1) {
                    multiple++;
                    arrClass = strClass.split(" ");
                }

                if (multiple > 0) {
                    for (c = 0; c < arrClass.length; c++) {
                        if (arrClass[c] != "") {
                            if ($(this).hasClass(arrClass[c])) {
                                hoverState = true;
                                $(this).find('a').css({
                                    backgroundPosition: '-' + (i * settings.navDistances) + 'px -' + settings.imageHeight + 'px',
                                    cursor: 'default'
                                });
                            }
                        }
                    }
                } else {
                    if (strClass != "") {
                        if ($(this).hasClass(strClass)) {
                            hoverState = true;
                            $(this).find('a').css({
                                backgroundPosition: '-' + (i * settings.navDistances) + 'px -' + settings.imageHeight + 'px',
                                cursor: 'default'
                            });
                        }
                    }
                }

            }

            /*Hover State*/
            if (!hoverState) {
                $(this).mouseover(function () {
                    $(this).find('a').css({ backgroundPosition: '-' + (i * settings.navDistances) + 'px -' + settings.imageHeight + 'px' });
                })
					.mouseout(function () {
					    $(this).find('a').css({ backgroundPosition: '-' + (i * settings.navDistances) + 'px 0px' });
					});
            }
        });
    }
})(jQuery);
