
//Default first load

window.addEventListener("load",firstPageLoad,false);

function firstPageLoad(e){
	var defaultPhotoID = getQueryVariable("defaultid");
	var ac_select = getQueryVariable("ac_select");
	var schoolid = getQueryVariable("sid");
	
	if(defaultPhotoID && ac_select && schoolid) 
		requestCurriculum(ac_select,schoolid,defaultPhotoID);
}

//Ajax functions
function requestCurriculum(formsel,sid,default_id){
	var params = "";
	
	params += formsel	? 'ac_select='+formsel.value : '';
	params += sid 	? '&sid=' + sid : '';
	params += default_id ? '&defaultid=' + default_id : '';
	
	if(onCourse){
		closeCourse(onCourse);
		onCourse = NaN;
	}
	
	//target container, parameters to the page
	ajax_req_course_box_list('curriculum_content',params);
	
	//target container, parameters to the page
	ajax_req_fac_staff_sidebar('curriculum_facstaff',params);
	
	//target container, gallery id, photo width, parameters to the page
	ajax_req_department_photos('curriculum_dphotos', 0, 254, params);
	
	//target container, parameters to the page
	ajax_req_dep_info('curriculum_dept_info',params);

}
function ajax_req_department_photos(target, galid, width, params){
	images = $('galimages' + galid);
	
	for(i = images.childNodes.length; i > 0; i--){
		images.removeChild(images.childNodes[0]);
	}
	
	var ajaxDPhotos = new Ajax.Updater(
		{
			success: 'galimages' + galid
		},
		"/academics/inc/request_dphotos.asp",
		{
			method: 'get',
			parameters: params,
			asynchronous: true,
			onFailure: function() {
				$(target).innerHTML = "There was an error processing your request."
			},
			onComplete: function(){
				//debug("photo success");

				eval("myGallery"+galid+".resetGallery("+galid+")");
				eval("myGallery"+galid+".setWidth("+width+")");
					
				ReSizeIFRAME();
				setTimeout(ReSizeIFRAME, 500);
			}
		}
	);
}
function ajax_req_course_box_list(target, params){
	$(target).innerHTML = "<div style='text-align: center;'><img src='/images/spinner.gif' /></div>";

	var ajaxCurriculum = new Ajax.Updater(
		{
			success: target
		},
		"/academics/inc/request_courses.asp",
		{	
			method: 'get', 
			parameters:	params,
			asynchronous: true,
			onFailure:	function() {
				$(target).innerHTML = "There was an error processing your request."
			},
			onComplete: function(){
				//debug("courses success");	
				ReSizeIFRAME();
				setTimeout(ReSizeIFRAME, 500);
				greetingHeight = Element.getHeight('curriculum_dept_greeting');
				if(greetingHeight > 285){
					//Element.setHeight('curriculum_dept_greeting',285);
					//$('curriculum_dept_greeting').style.overflow = "auto";
				}
				
			}
		}
	);
}
function ajax_req_dep_info(target, params){
	$(target).innerHTML = "<div style='text-align: center;'><img src='/images/spinner.gif' /></div>";

	var ajaxCurriculum = new Ajax.Updater(
		{
			success: target
		},
		"/academics/inc/request_deptinfo.asp",
		{	
			method: 'get', 
			parameters:	params,
			asynchronous: true,
			onFailure:	function() {
				$(target).innerHTML = "There was an error processing your request."
			},
			onComplete: function(){
				//debug("courses success");	
				ReSizeIFRAME();
				setTimeout(ReSizeIFRAME, 500);
				//greetingHeight = Element.getHeight('curriculum_dept_greeting');
				//if(greetingHeight > 285){
				//	Element.setHeight('curriculum_dept_greeting',285);
				//	$('curriculum_dept_greeting').style.overflow = "auto";
				//}
				
			}
		}
	);
}
function ajax_req_fac_staff_sidebar(target, params){
	$(target).innerHTML = "<div style='text-align: center;'><img src='/images/spinner.gif' /></div>";

	var ajaxCurriculum = new Ajax.Updater(
		{
			success: target
		},
		"/academics/inc/request_fac_staff.asp",
		{	
			method: 'get', 
			parameters:	params,
			asynchronous: true,
			onFailure:	function() {
				$(target).innerHTML = "There was an error processing your request."
			},
			onComplete: function(){
				//debug("courses success");	
				ReSizeIFRAME();
				setTimeout(ReSizeIFRAME, 500);
			}
		}
	);
}
//End Ajax functions

var onCourse = NaN;
function rollONcourse(cNum){
		//fe_css('swap','titleBack_'+cNum,'titleBack_over','titleBack_off') 
		//fe_css('swap','titleText_'+cNum,'titleText_over','titleText_off') 
		//fe_css('swap','arrow_'+cNum,'courseArrow_over','courseArrow_off') 
}
function rollOFFcourse(cNum){
	if(onCourse != cNum){
		//fe_css('swap','titleBack_'+cNum,'titleBack_off','titleBack_over') 
		//fe_css('swap','titleText_'+cNum,'titleText_off','titleText_over') 
		//fe_css('swap','arrow_'+cNum,'courseArrow_off','courseArrow_over')
	}
}
function openCourse(cNum){
	if(onCourse == cNum){
		closeCourse(cNum); 
		onCourse = NaN;
	}else{	
		if (onCourse) closeCourse(onCourse); 
		//fe_css is in headscripts see Goodshepard if you need it
		fe_css('swap','titleBack_'+cNum,'titleBack_on','titleBack_off') 
		fe_css('swap','titleText_'+cNum,'titleText_on','titleText_off') 
		fe_css('swap','arrow_'+cNum,'courseArrow_on','courseArrow_off') 
		fe_css('remove','course_'+cNum,'hide')
		onCourse = cNum;  
	}
	//ReSizeIFRAME()
}
function closeCourse(cNum){
	fe_css('swap','titleBack_'+cNum,'titleBack_off','titleBack_on') 
	fe_css('swap','titleText_'+cNum,'titleText_off','titleText_on') 
	fe_css('swap','arrow_'+cNum,'courseArrow_off','courseArrow_on')
	fe_css('add','course_'+cNum,'hide')
	//ReSizeIFRAME()
}
var btnopenid = NaN;
function btnover(btnid)	{//MouseOver here
	}
function btnout(btnid)	{
	if (btnopenid != btnid)
		{//Mouseout here
		}
	}
function btnopen(btnid) {
	if (btnopenid) btnclose(btnopenid);
	if(btnopenid == btnid) {
		 //Close if one is open
		 btnclose(btnid);
		 btnopenid = NaN;
	}
	else{
		$("bio_off_" + btnid).style.display = "none";
		$("bio_" + btnid).style.display = "";

		btnopenid = btnid;

		ReSizeIFRAME();
	}
}

function btnclose(btnid) {
	$("bio_off_" + btnid).style.display = "";
	$("bio_" + btnid).style.display = "none";
	ReSizeIFRAME();
}
