jQuery.noConflict();

var oldZindex = '';
var inSubNav = false;
var currentBgImage = '';
var oldBgImage = '';
var hoveredDiv = false;
var toCheckDiv = false;
var hoveredSubDiv = false;
var toHideDiv = false;	
var toSetZindex = false;
var toSetBgImage = false;
var states = new Array();

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

	$("#sofo-riders_ a").each(function() {
		originalstate = new Array();
		originalstate.push($(this).attr("id"), $(this).css("z-index"), $(this).css("background-image"));
		states.push(originalstate);
	});

	$("#sofo-riders_ a").hover(function() {
			// small reset
			$(".ddsubnav").hide();			
			for (var i = 0; i < states.length; i++) {
				$("#" + states[i][0]).css("z-index", states[i][1]).css("background-image", states[i][2]);
			} 
						
			oldZindex = $(this).css("z-index");
			$(this).css("z-index", 28);
			oldBgImage = $(this).css("background-image");
			if (oldZindex == 25)
				$(this).css("background-image", $(this).css("background-image").replace("_2", "_1"));
			else
				$(this).css("background-image", $(this).css("background-image").replace("_0", "_1"));	
			currentBgImage = $(this).css("background-image");
			
			hoveredDiv = $(this).attr("id").replace("ddtopnav_", "");
			hoveredSubDiv = $("#subnavi_" + hoveredDiv);
			hoveredSubDiv.show(); 
			
			hoveredSubDiv.hover(function() {
				inSubNav = true;
				$("#ddtopnav_" + hoveredDiv).css("z-index", 28);
				$("#ddtopnav_" + hoveredDiv).css("background-image",  currentBgImage);
			}, function() {
				hoveredSubDiv.hide();
				inSubNav = false;
				$("#ddtopnav_" + hoveredDiv).css("z-index", oldZindex);
				$("#ddtopnav_" + hoveredDiv).css("background-image", oldBgImage);
			});
			
		}, function() {
			toCheckDiv = hoveredDiv;
			toHideDiv = hoveredSubDiv;
			toSetZindex = oldZindex;
			toSetBgImage = oldBgImage;
			window.setTimeout(function() {
								if (!inSubNav) { 
									toHideDiv.hide();
									$("#ddtopnav_" + toCheckDiv).css("z-index", toSetZindex);
									$("#ddtopnav_" + toCheckDiv).css("background-image", toSetBgImage);
								}								
							 }, 10);	
		});
		


});

