// JavaScript Document
$(document).ready(function(){
	$(".active").each(function(i){ 			//take out the already active, to avoid taking the active class on and off again.
		var currSrc = $(this).attr("src");
		var newSrc = currSrc.replace("-off", "-on");
		$(this).removeClass("menu-item");
		$(this).attr("src", newSrc);
	});
	
	$(".menu-item").hover(function(){ 	//hovering
		var currSrc = $(this).attr("src");
		var newSrc = currSrc.replace("-off", "-on");
		$(this).attr("src", newSrc);
	},function(){ 											// going back out
		var currSrc = $(this).attr("src");
		var newSrc = currSrc.replace("-on", "-off");
		$(this).attr("src", newSrc);
  });
	
	$(".cat-date, .fright").click(function(){
		var Rel = "."+$(this).attr("rel");
		var Curr = $(Rel).css("display");
		if(Curr == "block"){
			$(Rel).slideUp();
		} else $(Rel).slideDown();
		return false;
	});
	$(".diag").hide();
	$(".diagram a").click(function(){
		$(".diag").fadeOut();
		var section = $(this).attr("class");
		var title = $(this).attr("title");
		if(section.length > 0){
			$.get("/diagram/"+section+"/"+title+"/", function(data){
				setTimeout(function(){ $(".diagramText").html('<div style="padding-left:10px;">'+data+'</div>');}, 400);
				$(".diag").fadeIn();
			});
		}
		return false;
	});
	
	$(".clip").scrollable({
		vertical:false,
		size: 1,
		speed: 3000
	}).circular().autoscroll({autoplay: true, interval: 6000});
	
	$(".contact-map a").click(function(){
		$(".contact-map a img").each(function(i,el){
			var src = $(this).attr("src");
			if(src.length > 0){
				var newSrc = src.replace('-on', '-off');
				$(this).attr("src", newSrc);
			}
		});
		
		var thisRel = $(this).attr("rel");
		var imgSrc = $("."+thisRel).attr("src");
		var newSrc = imgSrc.replace('-off', '-on');
		$("."+thisRel).attr("src", newSrc);
		$(".slideDown").slideUp();
		var place = $(this).attr("rel");
		var data = '<iframe src="/getAddress.php?place='+place+'" width="100%" height="580" border="0" frameborder="0"></iframe>';
		$(".slideDown").html(data);
		$(".slideDown").slideDown("slow");
		$(document).scrollTo($('.slideDown'), 800);
		return false;
	});
	
});