$(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
	}
	//var tabvalue = 1 //url.substring(url.lastIndexOf('/') + 1);
	//tid =tabvalue;

	//var url = window.location.pathname; //'www.google.com/dir1/dir2/2';
	//var id = parseInt(url.split('/')[url.split('/').length - 1]);
	//tid=id
	
	var url = window.location.pathname; //'www.google.com/dir1/dir2/2';
	var tabvalue = url.substring(url.lastIndexOf('/') + 1);
	//var test = tabvalue.replace('-','+');
	//alert(test);
	//alert(tabvalue);
	
	if((tabvalue.toUpperCase() == "EARLY-CAREER-DEVELOPMENT-PROGRAMS") || (tabvalue.toUpperCase() == "PROGRAMMES-DE-D%C3%A9VELOPPEMENT-DE-CARRI%C3%A8RE") || (tabvalue.toUpperCase() == "PROGRAMMES-DE-DÉVELOPPEMENT-DE-CARRIÈRE"))
	{
	    tid =3
	}
	else if ((tabvalue.toUpperCase() == "INNOVATORS-SCHOLARSHIP-PROGRAM") || (tabvalue.toUpperCase() == "PROGRAMME-DE-BOURSES-D%E2%80%99%C3%A9TUDES") || (tabvalue.toUpperCase() == "PROGRAMME-DE-BOURSES-D’ÉTUDES"))
	{
	     tid =2
	}
	else if ((tabvalue.toUpperCase() == "UNDERGRAD-AND-GRAD-OPPORTUNITIES") || (tabvalue.toUpperCase() == "OPPORTUNIT%C3%A9S-POUR-LES-%C3%A9TUDIANTS-ET-JEUNES-DIPL%C3%B4M%C3%A9S") || (tabvalue.toUpperCase() == "OPPORTUNITÉS-POUR-LES-ÉTUDIANTS-ET-JEUNES-DIPLÔMÉS"))
	{
	     tid =1
	}
	else if(tabvalue.toUpperCase() == "REWARDS-AND-RECOGNITION")
	{
	     tid =1
	}
	else if(tabvalue.toUpperCase() == "LEARNING-AND-DEVELOPMENT")
	{
	     tid =2
	}
	else if(tabvalue.toUpperCase() == "THE-FIVE-INITIATIVES")
	{
	     tid =1
	}
    	else if(tabvalue.toUpperCase() == "THE-HONEYWELL-BEHAVIORS")
	{
	     tid =2
	}
	else if(tabvalue.toUpperCase() == "SIX-SIGMA")
	{
	     tid =3
	}
	else if(tabvalue.toUpperCase() == "INITIATIVE-FOR-SCIENCE-ENGINEERING")
	{
	     tid =4
	} 
	else if(tabvalue.toUpperCase() == "DIVERSITY-AT-HONEYWELL")
	{
	     tid =5
	} 
	else if(tabvalue.toUpperCase() == "CORPORATE-RESPONSIBILITY")
	{
	     tid =6
	}
	else
	{
	     tid =0
	}

	$("#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');}
});
