$(document).ready(function() { 
	firstclick = true;
	$("div.box a").click(function() {
		$("div#welcome").hide();
		$("div#contact").hide();
		$("div#contact").css("width","368px");
		$("#contact").css("height","741px");
		$("div#hidemap").empty();
		if (firstclick == true) {
			$("div.random").remove();
			$('#content').masonry({
			singleMode: false,
			resizeable: true,
			columnWidth: 250,
			itemSelector: '.outer',
			saveOptions: true
			});
		};
		if (firstclick == false) {
		$("div.open").remove();
		$("div.box").removeClass("nodisplay"); 
		};
		//   $("div.outer").fadeOut(10);
		var boxid = $(this).attr("id");
		var urlLoad = $(this).attr("href"); 
		$("div#welcome").hide();
		$("div#contact").hide();
		$("div#contact").css("width","368px");
		$("#contact").css("height","741px");
		$("div#hidemap").empty();
		$("div#b" + boxid).addClass("nodisplay");
		$("#b" + boxid).after("<div class='open'></div>");
		$("div.open").append("<iframe id='boxframe' class='noborder' scrolling='no' marginwidth='0' marginheight='0' frameborder='0' border='0' allowtransparency='true'></iframe>");							
		$("iframe#boxframe").src(urlLoad);
		$('#content').masonry({
			singleMode: false,
			resizeable: true,
			columnWidth: 250,
			itemSelector: '.outer',
			saveOptions: true
			});
		//    $("div.outer").fadeIn(10);
		$.scrollTo('.open', 400);
		firstclick = false;
		return false;
		}); 
	
$("a.welcome").click(
	function () {
	$("#welcome").show();
	$("div#contact").hide();
	return false;
}); 
$("a.contact").click(
	function () {
	$("#contact").show();
	$("div#welcome").hide();
	return false;
}); 
$("a#showmap").toggle(
      function () {
        durl = $(this).attr("href");
        $("#hidemap").append("<iframe id='dirframe' class='mapframe' scrolling='no' marginwidth='0' marginheight='0' frameborder='0' border='0' allowtransparency='true' src='" + durl + "'></iframe>");							
        $("#contact").animate( {width:"868px"}, 200 )
	.animate( {height:"1061px"}, 200 );
	$("#hidemap").show();
	$("#dirframe").show();
	$.scrollTo('#hidemap', 400);	
	return false;
      },
      function () {
	$("div#hidemap").empty();
	$("div#contact").css("width","368px");
	$("#contact").css("height","741px");
      }
    );

$("#wrapper").click(
	function () {
	$("div#welcome").hide();
	$("div#contact").hide();
	$("div#hidemap").empty();
	$("div#contact").css("width","368px");
	$("#contact").css("height","741px");
});

$("#header").click(
	function () {
	$("div#welcome").hide();
	$("div#contact").hide();
	$("div#hidemap").empty();
	$("div#contact").css("width","368px");
	$("#contact").css("height","741px");
});

$(".open").click(
	function () {
	$("div#welcome").hide();
	$("div#contact").hide();
	$("div#hidemap").empty();
	$("div#contact").css("width","368px");
	$("#contact").css("height","741px");
});

});


