$(document).ready(function() {
	if ($('#select ul').length > 0) sfHover();
	if ($('ul#floors_tabs').length > 0) tabs();
	if ($('ul.event_navigation').length > 0) eventTabs();
	if ($('.pagination').length > 0) pagination();
	if ($('#region_tabs').length > 0) regionsTabs();
});

function sfHover() {
	/* IE 6 :hover Fix adapted for jquery, originally from A List Apart */
	$('#select li').each(function(i) {
		$(this).mouseover(function() { $(this).addClass('sfhover'); });
		$(this).mouseout(function() { $(this).removeClass('sfhover'); });
	});
}

function tabs() {
	$('#floors_tabs li a').each(function(i,e) {
		$(this).click(function(i,e) {
			// get my index
			var index = $("#floors_tabs li a").index(this);
			
			// find corresponding index of tables, turn all others off, turn corresponding on
			$('table.floors_list').attr('class','floors_list hide');
			$('table.floors_list').eq(index).attr('class','floors_list show');
			
			// turn all tabs off, turn me on
			$('#floors_tabs li a').attr('class','');
			$(this).attr('class','hit');
			
			return false;
		});
	});
}

function eventTabs() {
	$('ul.event_navigation li a').each(function(i,e) {
		$(this).click(function(i,e) {
			// get my index
			var index = $("ul.event_navigation li a").index(this);
			
			// find corresponding index of tables, turn all others off, turn corresponding on
			$('table.events_list').attr('class','events_list hide');
			$('table.events_list').eq(index).attr('class','events_list show');
			
			// turn all tabs off, turn me on
			$('ul.event_navigation li a').attr('class','');
			$(this).attr('class','hit');
			
			return false;
		});
	});
}

function regionsTabs() {
	$('ul#region_tabs li a').each(function(i,e) {
		$(this).click(function(i,e) {
			// get my index
			var index = $("ul#region_tabs li a").index(this);
			
			// find corresponding index of tables, turn all others off, turn corresponding on
			$('.tab_content').attr('class','tab_content hide');
			$('.tab_content').eq(index).attr('class','tab_content show');
			
			// turn all tabs off, turn me on
			$('ul#region_tabs li a').attr('class','');
			$(this).attr('class','hit');
			
			return false;
		});
	});
}

function pagination() {
	$('#pagination_top a').each(function(i,e) {
		$(this).click(function(i,e) {
			// get my index
			var index = $("#pagination_top a").index(this);
			
			// find corresponding index of tables, turn all others off, turn corresponding on
			$('.history_page').attr('class','history_page hide');
			$('.history_page').eq(index).attr('class','history_page show');
			
			// turn all tabs off, turn me on
			$('#pagination_top a').attr('class','');
			$('#pagination_bottom a').attr('class','');
			$('#pagination_bottom a').eq(index).attr('class','hit');
			$(this).attr('class','hit');
			
			return false;
		});
	});
	$('#pagination_bottom a').each(function(i,e) {
		$(this).click(function(i,e) {
			// get my index
			var index = $("#pagination_bottom a").index(this);
			
			// find corresponding index of tables, turn all others off, turn corresponding on
			$('.history_page').attr('class','history_page hide');
			$('.history_page').eq(index).attr('class','history_page show');
			
			// turn all tabs off, turn me on
			$('#pagination_bottom a').attr('class','');
			$('#pagination_top a').attr('class','');
			$('#pagination_top a').eq(index).attr('class','hit');
			$(this).attr('class','hit');
			
			return false;
		});
	});
}