 /*
 *
 * tabbed schedule table functionaity
 *
 */

var tab = false;


function showTab(a, t, n) {

	$(n).attr("class", "inactive");
	
	if(a.indexOf("fri") != -1) {
		tab = "1";
	} else if (a.indexOf("sat") != -1) {
		tab = "2";
	} else if (a.indexOf("sun") != -1) {
		tab = "3";
	} else if (a.indexOf("film") != -1) {
		tab = "4";
	} else if (a.indexOf("ongoing") != -1) {
		tab = "5";
	}
	
	if(tab != false) {
		// show the desired tab
		$("#schedule-day-"+tab).css("display","block");
		// highlight desired tab	
		$(n[tab-1]).attr("class", "active");
	} else {
		// else show first table if no anchor is not set
		$(t[0]).css("display","block");
		// highlight first schedule tab	
		$(n[0]).attr("class", "active");
	}
	
	
}

jQuery(document).ready(function() {	
	
	var sched_t = $(".schedule-table");

	if(sched_t) {
			
		$(".schedule-table tr:nth-child(odd)").addClass("odd");
		
		// hide tables
		$(sched_t).css("display","none");
		
		// find tab nav
		var n = $("#schedule-day-nav li");
		
		// get url
		var l = window.location.href;
		// find anchor
		var sched_anchor = parseUri(l).anchor;
		
		
		showTab(sched_anchor, sched_t, n)
		
		
		// set click on tabs
		$("#schedule-day-nav li a").click( function() {
			
			sched_day = $(this).parent().attr("id").split("-")[2];
			$(sched_t).css("display","none");
			$("#schedule-day-"+sched_day).css("display","block");
			$("#schedule-day-nav li").attr("class", "inactive");
			$(this).parent().attr("class", "active");
			
			return false;
			
		});
		
		// set click on links within the table
		$(".schedule-table a").click( function() {
		
			// hide tables
			$(sched_t).css("display","none");
			
			// get url
			l = $(this).attr("href");
			// find anchor
			sched_anchor = parseUri(l).anchor;
			
			window.location.href = l;
			
			
			showTab(sched_anchor, sched_t, n)
			
			// double check it anchors down to the correct position
			if (sched_anchor) {
				window.scrollTo(0,findPos($("#"+sched_anchor).get()[0])[1]);
			}
			
			return false;
			
		});

		// double check it anchors down to the correct position
		if (sched_anchor) {
			window.scrollTo(0,findPos($("#"+sched_anchor).get()[0])[1]);
		}
		
		
	}
	
});