var rcactive = false;
var menuactive = false;

function showRueCommunityForm() {
	$("form.ruecommunity-options").show();
	hideMap();
}

function hideRueCommunityForm() {
	if(!rcactive) {
		$("form.ruecommunity-options").hide();
		showMap();
	}
}

function showMap() {
	if(!menuactive) {
	    $('div#map').css('visibility','visible');
	}
}

function hideMap() {
	$('div#map').css('visibility','hidden');
}

$(document).ready(function(){ 

	if($.browser.msie && parseInt($.browser.version) == 6) {
		$(document).pngFix();
	}
	
	$("ul.navigation-primary").superfish(); 
	
	$("ul.navigation-primary a").mouseover(
	  function () {
	    menuactive = true;
		hideMap();
	  }
	);
	
	$("ul.navigation-primary a").mouseout(
	  function () {
	    menuactive = false;
		setTimeout(showMap,100);
	  }
	);
	
	$("a.join").mouseover(
	  function () {
		rcactive = true;
		$("form.ruecommunity-options").slideDown('fast');
		hideMap();
	  }
	);
	
	$("a.join").mouseout(
	  function () {
		rcactive = false;
		showMap();
		setTimeout(hideRueCommunityForm,500);
	  }
	);
	
	$("form.ruecommunity-options").hover(
	  function () {
		rcactive = true;
		showRueCommunityForm();
	  },
	  function () {
		rcactive = false;
		setTimeout(hideRueCommunityForm,500);
	  }
	);
	

	$("a.rollover img").hover(
		function(){
		    var imgs = $(this).parents("table#trend_list").find("img");
		    imgs.each(function(i){
		        $(this).attr('src',$(this).attr('src').replace("-on","-off"));
		    });
			$(this).attr('src',$(this).attr('src').replace("-off","-on"));
			$(this).parent("a").next("p").css("display","block");
		},
		function(){
		    var imgs = $(this).parents("table#trend_list").find("img");
		    imgs.each(function(i){
		        $(this).attr('src',$(this).attr('src').replace("-on","-off"));
				$(this).attr('src',$(this).attr('src').replace("-off","-on"));
		    });
			$(this).parent("a").next("p").css("display","none");
		}
	);

});