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()+8;
	//show the menu directly over the placeholder
	$("#divQuickLinks").css( { "left": (qlpos.left-8) + "px", "top":(qlpos.top + qlheight) + "px" } );
	$("#divQuickLinks").show();
}

function clearQuickLinksHideTimer()
{
	clearTimeout(qlTimeout);
}

function hideQuickLinksMenu (ev) {
	qlTimeout = setTimeout('$("#divQuickLinks").hide()', 1000);
}
/* End Quicklinks stuff */

var curTimeout = null;

function clearSubMenus() {
	$('div.submenu_container').hide();
	clearTimeout(curTimeout);
}

function SubMenuOnOver (link, holder, leftOff, topOff) {
	//clearTimeout(curTimeout);
	clearSubMenus();
	if ($("#"+holder).css('display') == 'none') 	{
		
		$("#"+holder).css( { "left": ($("#"+link).offset().left-leftOff) + "px", "top":($("#"+link).offset().top + $("#"+link).height()+topOff) + "px", "z-index": 99 } );
		$("#"+holder).slideDown();
	}
}

function SubMenuOnLeave(holder, delay) {
	$("#"+holder).css( { "z-index": 20 } );
	curTimeout = setTimeout('$("#'+holder+'").slideUp();clearSubMenus();', delay);
}

$(document).ready(function(){
	if ($('#lnkAbout') != null)
	{
		$('#lnkAbout').mouseover(function(){SubMenuOnOver('lnkAbout', 'divAbout', 8, 6)});
		$('#lnkAbout').mouseleave(function(){SubMenuOnLeave('divAbout', 300)});
		$('#divAbout').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divAbout').mouseleave(function(){SubMenuOnLeave('divAbout', 300)});
	}
	if ($('#lnkAdmissions') != null)
	{
		$('#lnkAdmissions').mouseover(function(){SubMenuOnOver('lnkAdmissions', 'divAdmissions', 4, 6)});
		$('#lnkAdmissions').mouseleave(function(){SubMenuOnLeave('divAdmissions', 300)});
		$('#divAdmissions').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divAdmissions').mouseleave(function(){SubMenuOnLeave('divAdmissions', 300)});
	}
	if ($('#lnkSchoolLife') != null)
	{
		$('#lnkSchoolLife').mouseover(function(){SubMenuOnOver('lnkSchoolLife', 'divSchoolLife', 4, 6)});
		$('#lnkSchoolLife').mouseleave(function(){SubMenuOnLeave('divSchoolLife', 300)});
		$('#divSchoolLife').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divSchoolLife').mouseleave(function(){SubMenuOnLeave('divSchoolLife', 300)});
	}
	if ($('#lnkStudentProjects') != null)
	{
		$('#lnkStudentProjects').mouseover(function(){SubMenuOnOver('lnkStudentProjects', 'divStudentProjects', 4, 6)});
		$('#lnkStudentProjects').mouseleave(function(){SubMenuOnLeave('divStudentProjects', 300)});
		$('#divStudentProjects').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divStudentProjects').mouseleave(function(){SubMenuOnLeave('divStudentProjects', 300)});
	}
	if ($('#lnkAlumni') != null)
	{
		$('#lnkAlumni').mouseover(function(){SubMenuOnOver('lnkAlumni', 'divAlumni', 4, 6)});
		$('#lnkAlumni').mouseleave(function(){SubMenuOnLeave('divAlumni', 300)});
		$('#divAlumni').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divAlumni').mouseleave(function(){SubMenuOnLeave('divAlumni', 300)});
	}
	if ($('#lnkSupportCSS') != null)
	{
		$('#lnkSupportCSS').mouseover(function(){SubMenuOnOver('lnkSupportCSS', 'divSupportCSS', 4, 6)});
		$('#lnkSupportCSS').mouseleave(function(){SubMenuOnLeave('divSupportCSS', 300)});
		$('#divSupportCSS').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divSupportCSS').mouseleave(function(){SubMenuOnLeave('divSupportCSS', 300)});
	}
	if ($('#lnkEmployment') != null)
	{
		$('#lnkEmployment').mouseover(function(){SubMenuOnOver('lnkEmployment', 'divEmployment', 4, 6)});
		$('#lnkEmployment').mouseleave(function(){SubMenuOnLeave('divEmployment', 300)});
		$('#divEmployment').mouseenter(function() {clearTimeout(curTimeout);})
		$('#divEmployment').mouseleave(function(){SubMenuOnLeave('divEmployment', 300)});
	}
	if ($('#lnkQuicklinks') != null)
	{
		$("#lnkQuicklinks").mouseover(function(){SubMenuOnOver('lnkQuicklinks', 'divQuicklinks', 96, 6)});
		$("#lnkQuicklinks").mouseleave(function(){SubMenuOnLeave('divQuicklinks', 300)});
		$("#divQuicklinks").mouseenter(function() {clearTimeout(curTimeout);})
		$("#divQuicklinks").mouseleave(function(){SubMenuOnLeave('divQuicklinks', 300)});
	}
});
