var webSiteRoot = window.location.protocol + "//" + window.location.host + "/";

function toggleStyle() {
	if ( $("#ZoomContainer") != null) 
	{
		if ($('#ZoomContainer').hasClass('small')) {
			$('#ZoomContainer').removeClass('small');
			$('#ZoomContainer').addClass('large');
		}
		else {
			$('#ZoomContainer').removeClass('large');
			$('#ZoomContainer').addClass('small');
		}
	}
}

function getDocHeight(doc)
{
	var docHt = 0, sh, oh;
	if (doc.height)
	{
		docHt = doc.height;
	}
	else if (doc.body)
	{
		if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
		if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
		if (sh && oh) docHt = Math.max(sh, oh);
	}
	return docHt;
}


function OpenMediaFile( mediaID )
{
	// determine available height and set popup to 80%
	var winHeight = getDocHeight(document) * .8;
	var winWidth = winHeight * 4 / 3;
	var win = window.open(webSiteRoot + 'ShowMedia.aspx?type=radwindow&MediaID=' + mediaID, 'radMediaWindow','height=' + winHeight + ',width=' + winWidth + ',fullscreen=no');
	/*
	var win = radopen(webSiteRoot + "ShowMedia.aspx?type=radwindow&MediaID=" + mediaID, "radMediaWindow")
	win.set_height(winHeight);
	win.set_width(winWidth);
	win.set_modal(true);
	win.center();
	*/
	/*
	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();
}

// also appears on line 18
/*
function OpenMediaFile( mediaID )
{
    var win = radopen(webSiteRoot + "ShowMedia.aspx?type=radwindow&MediaID=" + mediaID, "radMediaWindow");
    win.set_title("OpenMedia Title");
    win.set_status("OpenMedia Status");
}
*/

/* 
* 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;
		            }
		        }
		    }
		}
    }
}

/* newER */
var curTimeout = null;

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;
	});
}

function clearSubMenus() {
	$('.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(){
	$('.topmenu_img.not_selected').mouseover(function(){
		var src = $(this).attr("src").match(/[^\.]+/) + "_rollover.gif";
        $(this).attr("src", src);
	});
	$('.topmenu_img.not_selected').mouseout(function() {
        var src = $(this).attr("src").replace("_rollover", "");
        $(this).attr("src", src);
    });
    
    // This is to adjust scrollable area with the height of the menu
    var el = $("#SideMenuItem");
	var bodyEl = $("#SiteContent");
	var bodyTextEl = $("#ScrollableBodyCopy");
	if ( el != null && bodyEl != null && bodyTextEl != null ) {
	    //alert("el=" + el.height() + " body=" + bodyEl.height());
		if ( el.height() > bodyEl.height() ) {
			bodyTextEl.height(el.height() - bodyEl.height());
		}
	}    
});
