// Custom Tabs
var number_of_tabs = 3; //Sets the number of tabs
//Allow only one AJAX request per tab per page load:
var ajax_complete = new Array();
for(x = 1; x <= number_of_tabs; x++){
	ajax_complete[x] = false;
}

//school print URL
var print_school;

function open_tab(tab_number, ajax_url, callback_function){	var tabID = '#tab' + tab_number;
	var tabID_content = '#tab' + tab_number + '_content';
	
	hide_tabs(); //remove all tab content	
	$(tabID_content).css('display', 'block'); //show selected tab content
	$(tabID).addClass('selected'); //add selected class to the selected tab
	$('ul#tabnav li').css('display', 'inline'); //important - keeps the tab list as inline elements!
	
	//check for/run an AJAX request - only loads one request per tab per page load!
	if(ajax_url > '' && ajax_complete[tab_number] == false){
		$(tabID_content).load(ajax_url);
		ajax_complete[tab_number] = true;
	}
	//check for/run a callback function
	if(callback_function > ''){
		callback_function();
	}
}

function hide_tabs(){
	//Hide all tabs
	var x;
	for(x = 1; x <= number_of_tabs; x++){
		var tabID = '#tab' + x;
		var tabID_content = '#tab' + x + '_content';
		$(tabID).removeClass('selected');
		$(tabID_content).css('display', 'none');
	}
}

function feeder(){
	//Replaces news.htm $(document).ready function!
	// Display loading animated GIF while AJAX call is being made
	$("#feed_me").empty().html('<div align="center"><img src="/pbImages/ajax-loader.gif" /><br />Please wait...</div>');	
	$("#feed_me2").empty().html('<div align="center"><img src="/pbImages/ajax-loader.gif" /><br />Please wait...</div>');
	
			
	// Get RSS Feed
	$("#feed_meHome").load("/wrd/readrss/Default.aspx", { rss: "http://news.palmbeach.k12.fl.us/pao/category/top-news/feed", entries: "1", words: "30"  });
	$("#feed_me").load("/wrd/readrss/Default.aspx", { rss: "http://news.palmbeach.k12.fl.us/pao/category/headlines/feed", entries: "5", words: "30"  });
	$("#feed_me2").load("/readrss/Default.aspx", { rss: "http://news.palmbeach.k12.fl.us/superintendent/feed", entries: "4", characters: "0"  });
	$("#vodcast").load("/vodcast.html");
}

//The following code handles the departments on the 'departments' tab
var selected;
	
$(document).ready(function()
{            
			$(".a2dlink").click(function () { 
				$(".hide").hide();
				$("#A2D").show();
				});
			
			$(".e2hlink").click(function () { 
				$(".hide").hide();
				$("#E2H").show();
				});
			
			$(".i2llink").click(function () { 
				$(".hide").hide();
				$("#I2L").show();
				});
			
			$(".m2plink").click(function () { 
				$(".hide").hide();
				$("#M2P").show();
				});
			
			$(".q2tlink").click(function () { 
				$(".hide").hide();
				$("#Q2T").show();			
				});
			
			$(".u2zlink").click(function () { 
				$(".hide").hide();
				$("#U2Z").show();
				});
			
			//added to show a2d links on page load:
			$("#A2D").show();
			
});
function make_bold(varthis){
	$(".a2dlink").css("font-weight", "normal");
	$(".e2hlink").css("font-weight", "normal");
	$(".i2llink").css("font-weight", "normal");
	$(".m2plink").css("font-weight", "normal");
	$(".q2tlink").css("font-weight", "normal");
	$(".u2zlink").css("font-weight", "normal");
	$(varthis).css("font-weight", "bold");
}
		
//School Overlay and Open Tab Code
var schools_path = '/schools/'; //path for school pages
var extension = '.htm' //extension for pages
var margin_set = false;
var opacity_val = 0.8;

$(document).ready(function (){
	/*	IMPORTANT! This script checks for a query string.
		If there is a school value, the joverlay plugin is used to display school information.
		If there is no value, the news tab is opened and news is loaded.
	*/
	var school;
	school = window.location.search.substring(1);
	if(school > '' && school != null){
		//check to see if the schools tab page is requested
		//school number is present in URL
		
		
		
		//check to see if the schools tab page is requested
		if(school == 'school=yes'){
			//open the home page with the schools tab displayed.
			open_tab(2, '', load_directory_page());
			return;
		}else if(school == 'dept=yes'){
			//open the home page with the departments tab displayed.
			open_tab(3, '');
			return;
		}else{			
			//Check the Query string value and append the extension		
			school = school.replace('school=', '');
		
			school = school + extension; //adds the extension to the schoolnumber
			school = schools_path + school; //adds the relative path to the folder containing the school pages
			print_school = school;
			school = school + get_timestamp(); //adds timestamp (for anti-cacheing purposes
	
			//Expand the div
			open_tab(2, '', load_directory_page()); //show the school information tab
		
			//Call the the JOverlay element - the CSS enables scrolling on lower resolution monitors
			$('#School_Info').jOverlay({center: false, url: school, opacity: opacity_val, bgClickToClose: false, css :{position: 'absolute', 'margin-left': '-314px', left: '50%', 'margin-top': '75px'}});
			$('#print_button').css({"display" : "block"});
		}
			//hide the select tags for IE6
			hideSelect();
	}else{
		//There is no school in the query string. Go ahead and open to the news and events tab
		open_tab(1, '', feeder());
	}
})

function ajax_school_info(){
	//Load the school information
	var school = $('#Select_Schools').val();
	//window.location = '?school=' + school;
	
	school = school + extension; //adds the extension to the schoolnumber
	school = schools_path + school; //adds the relative path to the folder containing the school pages
	print_school = school;
	school = school + get_timestamp(); //adds timestamp (for anti-cacheing purposes
	
	//Expand the div
	open_tab(2, '', load_directory_page()); //show the school information tab
		
	//Call the the JOverlay element - the CSS enables scrolling on lower resolution monitors
	$('#School_Info').jOverlay({center: false, url: school, opacity: opacity_val, bgClickToClose: false, css :{position: 'absolute', 'margin-left': '-314px', left: '50%', 'margin-top': '75px'}});
	$('#print_button').css({"display" : "block"});
	//hide the select tags for IE6
	hideSelect();
}

function load_directory_page(){
	//load the directory page into the schools tab
	var directory_page = '/schools/schools.asp' + get_timestamp();
	$('#School_Information_Directory').load(directory_page);
}

function get_timestamp(){
	//timestamp added to prevent page cacheing
	var date = new Date();
	var hours = date.getHours();
	var minutes = date.getMinutes();
	var seconds = date.getSeconds();
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	var timestamp = year.toString() + month.toString() + day.toString() + hours.toString() + minutes.toString() + seconds.toString();
	timestamp = '?request=' + timestamp;
	return timestamp;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	//added from the original school directory page!
  	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  	if (restore) selObj.selectedIndex=0;
}

function hideSelect(){
	if(typeof isIE != "undefined"){
		//show the iframe shim (IE6 hack to fix select box zindex issue)
		$("#shim").show();
	}
}

function showSelect(){
	if(typeof isIE != "undefined"){
		//hide the iframe shim
		$("#shim").hide();
	}
}

function closeSchoolInfo(){
	$.closeOverlay();
	showSelect();
}

function printMe(){
	var printWindow;
	url = "/schools/schoolPrint.asp?school="
	url = url + print_school;
	printWindow = window.open(url, "PrintWindow","height=500,width=625,status=yes,toolbar=no,menubar=no,location=no");	
	//printWindow.close();
}

