// JavaScript Document

$(init);


function init(){
	
	$("#album-nav").hide();
	$("a.viewmap").toggle(function(){showAlbumNav(true); $(this).html("<img src='img/arrow_up.gif' />Hide Albums"); return false;}, function(){showAlbumNav(false); $(this).html("<img src='img/arrow_down.gif' />Show Albums"); return false;})
	copyAltToTitle();
	$(".maplegend a").each(setupLegend);
	$(".map a img").each(setupImg);
	
	
}

function setupImg(){
	

	$(this).hover(imgOver, imgOff);
	
	
}

function setupLegend(){

	$(this).hover(legendOver, legendOff);
	
}

function legendOver(){
	
	$(this).addClass("selected");
	var href = $(this).attr("href");
	$(".map a[href='" + href + "'] img").fadeTo(300, 1);
	
}

function legendOff(){
		$(this).removeClass("selected");	
		var href = $(this).attr("href");
		$(".map a[href='" + href + "'] img").fadeTo(0, 0.5);
	
}

function dimImages(){

	$(".map a img").fadeTo(0, 0.5);
	
}

function imgOver(e){
	
	$(this).fadeTo(300, 1);
	var href = $(this).parent().attr("href");
	$(".maplegend a[href='" + href + "']").addClass("selected");
	
}

function imgOff(e){
			
	$(this).fadeTo(100, 0.5);
	var href = $(this).parent().attr("href");
	//$(".maplegend a[href='" + href + "']").css({color: "#cccccc", fontWeight:"normal"});
	$(".maplegend a[href='" + href + "']").removeClass("selected");
}

function copyAltToTitle(){
	
	$(".map a img").attr("title", function(){return this.alt});
	
}

function showAlbumNav(b){
	
	if(b){
	$("#album-nav").show(300, dimImages);
	
	} else {
	$("#album-nav").hide(300);
	
	}
	
}
