$(document).ready(function() {
	
	var currentNode;
	/**
	  * Tab Specific Page Load 	
	  *	Added 01-22-10 - Eric Birnbaum
	  *	Requires scripts/jquery.jqURL.js to receive varables from querystring
	  *	@param	tid	-tab ID, Zero-based index indicating which tab to open on page load
	  *
	*/
	var tid = $.jqURL.get("tid");
	if (tid == null || tid == "") {
		tid = 0; // First tab if tid isn't provided
	}
	
	$("#tabs, #tabswah, #tabsunivRel").tabs({
		select: function(event, ui) {
			$('#content-slider').slider('option', 'value', 0);
		},
		show: function(event, ui) {
			currentNode = ui.panel;
			sliderActive(currentNode);	
			$('#content-scroll').scrollTop(1);
		},
		fx: { opacity: 'toggle' },
		selected: tid
	});
	
	$("#content-slider").slider({
		orientation: "vertical",
		min:-100,
		max:0,
		slide: handleSliderSlide
	});

//***	Events	***/

	/*  Create a print button to nicely print the selected tab content using jquery.PrintArea.js */
	$("div#print_button").click (function() {
		$(currentNode).printArea();
	});	
	
	$(".ui-tabs-panel a[href^='#']").click (function () {
		elementClick = $(this).attr("href");
		destination = $(elementClick).offset().top - $(currentNode).offset().top; //- $("#content-scroll").offset().top;			
		var slideValue = -destination  / $(currentNode).height() * 100;
		$("#content-scroll").attr({ scrollTop: destination});
		$('#content-slider').slider('option', 'value', slideValue);  
		return false;
	});
	
//***	Functions	***/

	function sliderActive(mc) {
		if ($(mc).height() < $('#content-scroll').height()) { $('#content-slider').slider('disable');}
		else { $('#content-slider').slider('enable');}
	}
	
	function handleSliderChange(e, ui) {
		var maxScroll = $("#content-scroll").attr("scrollHeight") - $("#content-scroll").height();
		$("#content-scroll").animate({ scrollTop: -ui.value * (maxScroll / 100)}, 1000);
	}
	
	function handleSliderSlide(e, ui) {	
		var maxScroll = $("#content-scroll").attr("scrollHeight") - $("#content-scroll").height();
		$("#content-scroll").attr({ scrollTop: -ui.value * (maxScroll / 100)});
	}

//***	Initialize	**/

	 if (typeof(eval(window)['skipBool']) == 'undefined') {	sliderActive('#tabs-1');} 
	 else { sliderActive('#content-scroll > span');}
});