/*

	-- -- -- -- -- -- --
	css sprites 2
	nav behaviour

	http://www.alistapart.com/articles/sprites2
	-- -- -- -- -- -- --
	
*/

function generateSprites(parent, selectedPrefix, setActive, hoverSpeed, style) {
	// throw the parent object's class into a variable
	var parentClass = jqQDDN(parent).attr("class");

	// start a loop that cycles through each of the li elements inside the parent element
	jqQDDN(parent).children("li").each(function() {
		// create a few variables that we'll need during this function:
		// myClass = the class of the object we're currently inspecting
		// current = what the selected class should look like for the parent of the object we're currently inspecting
		var myClass = (jqQDDN(this).attr("class"))
		var current = parent.substring(1) + " current-" + (jqQDDN(this).attr("class"));

		// turn on nav events for element this loop identifies
		attachNavEvents(parent, myClass, setActive, hoverSpeed, style);
	
		// let's hide the CSS-defined background image, but only if this isn't the currently-selected item
		if (parentClass != current) {
			jqQDDN(this).children("a").css({backgroundImage:"none"});
		}

	});
}


function attachNavEvents(parent, myClass, setActive, hoverSpeed, style) {
    style = style.toUpperCase();
    jqQDDN(parent + " ." + myClass).mouseover(function() {
        // create pseudo-link
        jqQDDN(this).append('<div class="nav-' + myClass + '"></div>');
        // either slide or fade, depending on the style value
        if (style == "SLIDE") {
            // slide down the pseudo-link
            jqQDDN("div.nav-" + myClass).css({ display: "none" }).slideDown(hoverSpeed);
        } else if (style == "SLIDEUP") {
            // slide up the pseudo-link
            var h = jqQDDN("div.nav-" + myClass).height();
            jqQDDN("div.nav-" + myClass).css({ display: "", height: '0px', marginTop: h + 'px' }).
                animate({ height: h + 'px', marginTop: '0px' }, hoverSpeed);
        } else {
            // fade in the pseudo-link
            jqQDDN("div.nav-" + myClass).css({ display: "none" }).fadeIn(hoverSpeed);
        }
    }).mouseout(function() {
        // either slide or fade, depending on the style value
        if (style == "SLIDE") {
            // slide up to reverse the effect & destroy pseudo-link
            jqQDDN("div.nav-" + myClass).slideUp(hoverSpeed, function() {
                jqQDDN(this).remove();
            });
        } else if (style == "SLIDEUP") {
            // slide down to reverse the effect & destroy pseudo-link
            var h = jqQDDN("div.nav-" + myClass).height();
            jqQDDN("div.nav-" + myClass).css({ display: "", height: h + 'px', marginTop: '0px' }).
                animate({ height: '0px', marginTop: h + 'px' }, hoverSpeed, function() {
                    jqQDDN(this).remove();
                });
        } else {
            // fade out & destroy pseudo-link
            jqQDDN("div.nav-" + myClass).fadeOut(hoverSpeed, function() {
                jqQDDN(this).remove();
            });
        }
    });


	// we only want to check the mousedown/up events if the CSS exists for :active states
	// if so, let's apply our selective filtering to undo the events above
	if (setActive) {
		jqQDDN(parent + " ." + myClass).mousedown(function() {
			jqQDDN("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
		}).mouseup(function() {
			jqQDDN("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
		});
	}
}


