/* MAIN.JS 
-Authors: Thomas Culbertson and Alex Ane
*/

//Function called on page load
$(document).ready(function main(){
	tabs();
	updateFeed();
	expandableList();
	documentTitle();
	pdf();
});

//Sets up JQuery tabs if needed
function tabs(){
	$('#tabs').tabs();
	
	//If tabs are present, override base content padding
	if($("#tabs").html() != null){ $("#columnTwo").css('padding', 0); }
	if($("#tabs").html() != null){ $("#columnTwo").css('padding-left', 0); }
	if($("#tabs").html() != null){ $("#corner").css('background-image', "url(/images/layout/navCorners.png)"); }
}

//Sets up third column update feed
function updateFeed(){
	$(".updateFeed").jCarouselLite({
    btnNext: ".feedDown",
    btnPrev: ".feedUp",
		//auto: 2000,
		//speed:1000,
		vertical: true,
		circular: true,
		visible:1
  });
}

//Adds click listener to collapseable lists if needed
function expandableList(){
	$(".collapsedList :header").before("<div class='expand'>+</div>"); //For collapsedList support
	$(".collapsedList .expand").click(alterSection); //For collapsedList support
}

//Changes the document title according to the current page
function documentTitle(){
	var pageTitle = $("#columnTwo h2").first().html();
	document.title = "FHIN | " + pageTitle;
}

//Places pdf icons in front of .pdf links in the main content section
function pdfMainContent(){
	$("#columnTwo a[href$='.pdf']").before("<img src='/images/content/pdficon_small.gif' align='bottom' /> ");
}

//Places pdf icons everywhere else
function pdf(){
	$("a[href$='.pdf']").before("<img src='/images/content/pdficon_small.gif' align='bottom' /> ");
}

//Toggle function for to hide or show collapseable list content
function alterSection(){
	var stateLoc = this; //Location of + or -
	var sectionState = stateLoc.innerHTML; //Value of + or -
	var textLoc = stateLoc.nextSibling.nextSibling.nextSibling; //Location of text to be hidden or displayed
	
	if (textLoc == undefined) //Fix for IE DOM
		var textLoc = stateLoc.nextSibling.nextSibling;
	
	if (sectionState == "+"){
		stateLoc.innerHTML = "-";
		textLoc.style.display = "block";
	}
	else if (sectionState == "-"){
		stateLoc.innerHTML = "+";
		textLoc.style.display = "none";
	}
}
