// JavaScript Document
$(window).ready(function() {
	//drop down navigation
	$("#mainNav li ul").hide();
	$("#showTab").show();
	$("#mainNav").children().each(function() {
		$(this).hover(
			function(){
				$(this).attr('id', 'overt')
				$('#overt ul').slideDown('fast');
			},
			function() {
				$('#overt ul').hide();
				$(this).attr('id', '')
			}
		);
	});

	//tab navigation
	
	$(".propertyTab").hide();
	$("#ptab_overview").show();
	
	
	//function to determine if a tab is selected in the url
	checkTabAnchor();
	
	$(".tabsContainer ul li a").click(function() {
		var thisID = $(this).attr('id');
		var idSplit = thisID.split('_');

		tab_change(idSplit[1]);
	});
	
	$("#thumbnailContainer").children().each(function(){
		$(this).click(function() {
			$()
		});
	});
	
	if ($(".faq_questions").get(0)) {
		$(".faq_question div").hide();
		$(".faq_question a").click(function() {
			$(this).parent().children("div").slideToggle();
		});
	}
	if ($(".policy_questions").get(0)) {
		$(".policy_question div").hide();
		$(".policy_question a").click(function() {
			$(this).parent().children("div").slideToggle();
		});
	}
	
//	management function.. needs to be just like tabs the ids correspond like so.. class="manage_header" id="king_head"
//																				class="manage_copy" id="king_copy"
	$(".manage_copy").hide();
	$("#bailey_copy").show();
	$("#bailey_head").addClass('manage_selected');
	$(".manage_header h2 a").click(function() {
		var thisID = $(this).attr('id');
		var idSplit = thisID.split('_');
		manage_change(idSplit[0]);
	});
});

function tab_change(tabName) {
	$(".propertyTab").hide();
	$("#ptab_" + tabName).show();
	$('.selectedTab').removeClass('selectedTab');
	$("#plink_" + tabName).addClass('selectedTab'); //Add the selectTab class to the a with id: #plink_ourID
	
	if (tabName == "location") {
		initialize_map();
	}
}
function manage_change(tabName) {
	$(".manage_copy").hide();
	$("#" + tabName + "_copy").show();
	$('.manage_selected').removeClass('manage_selected');
	$("#" + tabName + "_head").addClass('manage_selected'); //Add the manage_selected class to the a with id: #ourID_copy
}

function checkAnchorLink(aObj) {
	var aSrc = $(aObj).attr('href');
	if (aSrc.match('#')) {
		var tabName = aSrc.split('#')[1];
		if (tabName != "") {
			if ($("#ptab_"+tabName).get(0)) {
				tab_change(tabName);
				return false;
			}
		}
	}
	return true;
}

function checkTabAnchor() {
	var curURL = document.location.toString();
	if (curURL.match('#')){ 
		var tabname = curURL.split('#')[1];
		var match = false;
		$(".tabsContainer ul li a").each(function() {
			var thisID = $(this).attr('id');
			var idSplit = thisID.split('_');
			
			if(tabname == idSplit[1]){
				tab_change(idSplit[1]);
				match = true;
			}
		});
		
		if (!match) {
			$('.propertyTab').hide();
			$('#ptab_overview').show();
			$('.selectedTab').removeClass('selectedTab');
			$('#plink_overview').addClass('selectedTab');
		}
	}
}


