/* $Id: SiteScripts.js 1367 2009-05-06 15:23:13Z buddy $ */
    
function startup() {
    document.imageBaseUrl = webSiteRoot+'MasterPages/';
    //preloadImages('images/aboutpcd_navrollover_10.gif','images/academics_navrollover_11.gif','images/arts_navrollover_12.gif','images/athletics_navrollover_13.gif','images/admissions_navrollover_14.gif','images/community_navrollover_15.gif','images/alumni_navrollover_16.gif','images/supportpcd_navrollover_17.gif');

	var el = document.getElementById("SideMenu");
	var bodyEl = document.getElementById("SiteContent");
	var bodyTextEl = document.getElementById("ScrollableBodyCopy");//Named in child templates that want a scrollable region
	if ( el != null && bodyEl != null && bodyTextEl != null ) {
	    //alert("el=" + el.clientHeight + " body=" + bodyEl.clientHeight);
		if ( el.clientHeight > bodyEl.clientHeight ) {
			bodyTextEl.style.height = (el.clientHeight - bodyEl.clientHeight) + 'px';
		}
	}
}


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 preloadImages() { //adapted from v3.0 to rebase urls - BJP 
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=document.imageBaseUrl+a[i];}}
    }

    function swapImgRestore() { //adapted from v3.0 to rebase urls - BJP
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
  }

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=document.imageBaseUrl+a[i+2];}
}
   */

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;
		            }
		        }
		    }
		}
    }
}
