
$(document).ready(function() {
	
	
	
	
	// 'Interactive Map Sidebar' EXPAND / COLLAPSE
	
	$(".expandable .expand_head").click(function () {
		if($(this).parent().hasClass("active")){
			closeExpandedSection();
		} else {
			openExpandableSection(this);
		}
		return false;
	})
	
	$(".expandable .nav-contents li").click(function () {
		setActiveNavItem(this);
	})
	
	
	if (document.getElementById("building-detail") || document.getElementById("architect-detail")){
		Galleria.loadTheme('js/galleria-theme/galleria.classic.min.js');
            $("#image-holder").galleria({
                width: 610,
                height: 519,
				imagePosition: "top center",
				showCounter: false,
                carousel: false,
                imageMargin: 1,
                autoplay: 6000,
                transitionSpeed: 300,
                thumbnails: "numbers"
            });
	          //on click off, 
		$(document).click(function (){
			if($(".expandable").hasClass("active")){
				$(".active .nav-contents").slideUp(120);
				$(".active a.expand_head").removeClass("open_tab");
				$(".active").removeClass("active");
			}
		})  
	}
	
	//Initialize pre-opened expandable tray
	if(window.pageloadCategory){
		if (pageloadCategory=="neighborhoods"){
			openExpandableSection( $(".expandable #neighborhood") );
			if(window.initialNeighborhood){
				var theActiveNavItem = $("#map-nav #neighborhood-list li#id" + initialNeighborhood);
				setActiveNavItem(theActiveNavItem);
			}
		}
		else if (pageloadCategory=="buildings"){
			openExpandableSection( $(".expandable #building") );
			if(window.initialBuilding){
				var theActiveNavItem = $("#map-nav #building-list li#id" + initialBuilding);
				setActiveNavItem( theActiveNavItem );
			}
		}
		else if (pageloadCategory=="architects"){
			openExpandableSection( $(".expandable #architect") );
			if(window.initialBuilding){
				var theActiveNavItem = $("#map-nav #architect-list li#id" + initialArchitect);
				setActiveNavItem( theActiveNavItem );
			}
		}
	}
	
	
	
	
	// Initialize Modal Popup Window Script
	$('.modal').modalpop({speed:100});

	
});


// Initialize Map Tour Info show/hide
function initializeTourDetailCloser(){
	$("#tour-details #tour-details-closer").click(function(){
		/* $(this).siblings("#tour-details-content").slideToggle("fast"); */
		$(this).parent().toggleClass("hidden");
		if ($(this).parent().hasClass("hidden")){
			$(this).siblings("#tour-details-content").slideUp("fast");
			$(this).children("#icon").addClass("show");
			$(this).children("span").html("show info");
		}
		else{
			$(this).siblings("#tour-details-content").slideDown("fast");
			$(this).children("#icon").removeClass("show");
			$(this).children("span").html("hide info");
		}
	});
}
	

function closeExpandedSection(){
	$(".active .nav-contents").slideUp(220);
	$(".active a.expand_head").removeClass("open_tab");
	$(".expandable.active").removeClass("active");
}
function openExpandableSection(theObject){
	$(".active .nav-contents").slideUp(220);
	$(".active a.expand_head").removeClass("open_tab");
	$(".expandable.active").removeClass("active");
	// -
	$(theObject).parent().addClass("active");
	$(".active .nav-contents").slideDown(220);
	$(".active h6.expand_head").addClass("open_tab");
	
	
}
function setActiveNavItem(theObject){
	$(".expandable .nav-contents li").each(function(){$(this).removeClass("active");});
	$(theObject).addClass("active");
}

function fireEvent(element,event) {
   if (document.createEvent) {
       // dispatch for firefox + others
       var evt = document.createEvent("HTMLEvents");
       evt.initEvent(event, true, true ); // event type,bubbling,cancelable
       return !element.dispatchEvent(evt);
   } else {
       // dispatch for IE
       var evt = document.createEventObject();
       return element.fireEvent('on'+event,evt)
   }
}

function showDetailTab(tabNumber){
	$("#info-text a.active").removeClass("active");
	$("#info-text .infotab").each(function() {
		/* alert(this.id); */
		$(this).hide();
	});
	
	$("#info-text #tab"+tabNumber).show();
	$("#info-text #link"+tabNumber).addClass("active");
}



