var webSiteRoot = window.location.protocol + "//" + window.location.host + "/";

function OpenMediaFile( mediaID )
{
	openWindow(webSiteRoot + 'ShowMedia.aspx?type=radwindow&MediaID=' + mediaID, 'mediaWindow', 'width=800,height=600,status=0,location=0,menubar=0');
    //var win = radopen(webSiteRoot + "ShowMedia.aspx?type=radwindow&MediaID=" + mediaID, "radMediaWindow")
    //win.set_title("OpenMedia Title");
    //win.set_status("OpenMedia Status");
}

function ShowFaculty(facultyId) {
  var win = radopen(webSiteRoot + "pages/FacultyBio.aspx?FacultyId=" + facultyId, "radFacultyWindow");
  win.setSize(500, 540);
  win.center();
}

/* Return a handle to the current rad window. Can be used inside an open radwindow */
function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;//Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    return oWindow;
} 

function ShowSiteMap() {
    var win = radopen(webSiteRoot + "pages/SiteMap.aspx", "radMediaWindow");
    win.setSize(400, 600);
    win.center();
}

function ShowCriticalNews() {
    var win = radopen(webSiteRoot + "pages/CriticalNews.aspx", "rwCriticalNews");
    win.setSize(400, 300);
    win.center();
}

/* 
* Scan all the news section blocks. If they are larger than 100 then resize down to 100 
* if they are a good size then leave them alone but delete the contents of the next div
* which contains the readme block
*/
function ResizeNewsSections() {
    ResizeDivSections('newsBox', 'newsBoxCopy', 105);
    }
    
/*
 * Scan the div specified by the wrapperDiv
 * Find all div's inside which have the class name divClassName
 * Resize the div down to divHeight. If already that hight then clear out the readMore div for that block
 */
function ResizeDivSections( wrapperDiv, divClassName, divHeight )
{    
	var div = document.getElementById(wrapperDiv);
	var divList = div.getElementsByTagName('div');
	for( var i=0; i<divList.length; ++i ) {
		var el = divList[i];
		if ( el.className == divClassName ) {
		    if (el.clientHeight > divHeight) {
		        el.style.height = divHeight + "px";
		    }
		    else {
		        // clear out the read more
		        for (var j = i + 1; j < divList.length; ++j) {
		            if (divList[j].className == 'readMore') {
		                divList[j].innerHTML = "";
		                break;
		            }
		        }
		    }
		}
    }
}

var toggleFlag = false;

 function toggleFont(){
	if (toggleFlag) {
		var currentFontSize = $('.main_body_container_body_main').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum/1.2;
		$('.main_body_container_body_main').css('font-size', newFontSize);
	    
		currentFontSize = $('.main_copy').css('font-size');
		currentFontSizeNum = parseFloat(currentFontSize, 10);
		newFontSize = currentFontSizeNum/1.2;
		$('.main_copy').css('font-size', newFontSize);
	}
	else {
		var currentFontSize = $('.main_body_container_body_main').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('.main_body_container_body_main').css('font-size', newFontSize);
	    
		currentFontSize = $('.main_copy').css('font-size');
		currentFontSizeNum = parseFloat(currentFontSize, 10);
		newFontSize = currentFontSizeNum*1.2;
		$('.main_copy').css('font-size', newFontSize);
    }
    
    toggleFlag = !toggleFlag; 
 }

function setupTab(tabHeader_i, tabContainer_i, tabBodyClass_i){
	$('#'+tabContainer_i+' div.'+tabBodyClass_i).hide(); // Hide all divs
	$('#'+tabContainer_i+' div.'+tabBodyClass_i+':first').show(); // Show the first div
	$('#'+tabHeader_i+' ul li:first').addClass('active'); // Set the class of the first link to active
	$('#'+tabHeader_i+' ul li a').click(function(){ //When any link is clicked
		$('#'+tabHeader_i+' ul li').removeClass('active'); // Remove active class from all links
		$(this).parent().addClass('active'); //Set clicked link class to active
		var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		$('#'+tabContainer_i+' div.'+tabBodyClass_i).hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
}

/* Quicklinks javascript */
var qlTimeout = null;
function showQuickLinksMenu (ev) {
	clearQuickLinksHideTimer();
	//get the position of the placeholder element
	var qlpos = $("#qlLink").offset();  
	var qlheight = $("#qlLink").height()-108;
	//show the menu directly over the placeholder
	$("#divQuickLinks").css( { "left": (qlpos.left-21) + "px", "top":(qlpos.top + qlheight) + "px" } );
	$("#divQuickLinks").show();
}

function clearQuickLinksHideTimer()
{
	clearTimeout(qlTimeout);
}

function hideQuickLinksMenu (ev) {
	qlTimeout = setTimeout('$("#divQuickLinks").hide()', 1000);
}
/* End Quicklinks stuff */

$(document).ready(function(){
	// Add quicklinks functions
	if ($('#qlLink') != null)
	{
		$("#qlLink").mouseover(showQuickLinksMenu);
		$("#qlLink").mouseleave(hideQuickLinksMenu);
		$("#divQuickLinks").mouseenter(clearQuickLinksHideTimer).mouseleave(hideQuickLinksMenu);
	}
});
