var $j = jQuery.noConflict();

/*

	-- -- -- -- -- -- --
	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 = $j(parent).attr("class");

	// start a loop that cycles through each of the li elements inside the parent element
	$j(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 = ($j(this).attr("class"))
		var current = parent.substring(1) + " " + selectedPrefix  + ($j(this).attr("class"));

		// let's hide the CSS-defined background image, but only if this isn't the currently-selected item
		if (parentClass != current) {
			// turn on nav events for element this loop identifies
			attachNavEvents(parent, myClass, setActive, hoverSpeed, style);
			$j(this).children("a").css({backgroundImage:"none"});
		}

	});
}


function attachNavEvents(parent, myClass, setActive, hoverSpeed, style) {
var $sel = parent+" ."+myClass;
var parentname = parent.substr(1);
	$j($sel).mouseover(function() {
		// create pseudo-link
		$j(this).append('<div class="'+parentname +'-' + myClass + '"></div>');
		// either slide or fade, depending on the style value
		if (style == "slide") {
			// slide down the pseudo-link
			$j("div" + parent + "-" + myClass).css({display:"none"}).slideDown(hoverSpeed);
		} else {
			// fade in the pseudo-link
			$j("div" + parent + "-" + myClass).css({display:"none"}).fadeIn(hoverSpeed);
		}
	}).mouseout(function() {
		// either slide or fade, depending on the style value
		if (style == "slide") {
			// slide up & destroy pseudo-link
			$j("div" + parent + "-" + myClass).slideUp(hoverSpeed, function() {
				$j(this).remove();
			});
		} else {
			// fade out & destroy pseudo-link
			$j("div" + parent + "-" + myClass).fadeOut(hoverSpeed, function() {
				$j(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) {

	$j(parent + " ." + myClass).mousedown(function() {
			$j("div" + parent + "-" + myClass).attr("class", parentname + "-" + myClass + "-click");
		}).mouseup(function() {
			$j("div" + parent + "-" + myClass + "-click").attr("class", parentname + "-" + myClass);
		});
	}
}

$j(document).ready(function() {

generateSprites(".nav","current-",true,300,"fade");
generateSprites(".goldsponsors","current-",true,300,"fade");
generateSprites(".navlower","currentlower-",true,300,"fade");

$j("div.socialbuttonstwitter").html(function(index,oldhtml)
{
var twittext = "";
twittext += "<iframe allowtransparency=\"true\" frameborder=\"0\" scrolling=\"no\" tabindex=\"0\" class=\"twitter-share-button twitter-count-horizontal\" src=\"http://platform0.twitter.com/widgets/tweet_button.html?_=1298319244705&amp;count=horizontal&amp;lang=en&amp;text=Full%20Blue%20Racing&amp;url=";
twittext += escape(oldhtml);
twittext+="&amp;via=fullblueracing\" style=\"width: 110px; height: 20px; \" title=\"Twitter For Websites: Tweet Button\"></iframe><script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script>";


$j(this).html(twittext);
$j(this).css('visibility','visible');
});

$j("div.socialbuttonsfacebook").html(function(index,oldhtml)
{
var fbtext = "";
fbtext += "<iframe src=\"http://www.facebook.com/plugins/like.php?href=";
fbtext += escape(oldhtml);

fbtext+="&amp;locale=&amp;layout=button_count&amp;action=like&amp;width=92&amp;height=20&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:92px; height:20px;\" allowtransparency=\"true\"></iframe>";

$j(this).html(fbtext);
$j(this).css('visibility','visible');

});
});


