
/*

	School of Business
	Utah Valley State College
	http://www.uvsc.edu/business/
	
	front javascript (ver. 1.3)
	
	
	
	
	Initial Developer:		Matt Chatterton
							Technical Support
							School of Business
							x 6167
	
	
	
	Testing runs:				IE 6.029 WIN
								Firefox 1.504 WIN
								Opera 8.54 WIN
	
	
	
	CHANGE LOG
	--------------
	
	ver (1.0)	Initial file
	ver (1.1)	Corrected previous-onload-defined check (used typeof)
	ver (1.2)	Resized spotlight window (800 compatible)
	ver (1.3) Allows non-"contentBody" pages

*/




var LOADED_FRONT_JS;



if(typeof LOADED_FRONT_JS == "undefined") {


	// load stylesheet
	if (document.getElementsByTagName) {
		var l=document.createElement("link");
		l.setAttribute("rel", "stylesheet");
		l.setAttribute("type", "text/css");
		//l.setAttribute("href", "/woodbury/lib/css/front.css");
		l.setAttribute("href", "/woodbury/lib/css/front.css");
		//l.setAttribute("media", "screen");
		document.getElementsByTagName("head")[0].appendChild(l);
	}
	
	
	function setMainBottomItemSmall(item) {
		item.style.overflowY = 'hidden';
		item.style.overflow = 'hidden';
	}
	
	function setMainBottomItemFull(item) {
		item.style.overflowY = 'scroll';
		item.style.overflow = 'auto';
	}
	
	function open_text(item) {
		
		// proper scope to search
		var item_s = item.parentNode.parentNode;
		
		
		// locate proper item
		var item_f = null;
		var divs = item_s.getElementsByTagName('div');
		for(var x=0; x<divs.length; x++) {
			if(divs[x].className == 'mainBottom_item') {
				item_f = divs[x];
				break;
			}
		}
		
		if(item_f == null) return false;
		
		
		
		var popup = document.createElement('div');
		var popup_h = document.createElement('div');
		var popup_t = document.createElement('div');
		
		popup.appendChild(popup_h);
		popup.appendChild(popup_t);
		
		popup.className = "mainBottom_item_maximized";
		popup_h.className = "mainBottom_item_maximized_head";
		popup_t.className = "mainBottom_item_maximized_text";
		
		popup_h.innerHTML = "<div style=\"position:relative; padding-left:8px; padding-top:2px; float:left; color:white;\"><strong>School of Business Spotlight</strong></div><div style=\"\"><a href=\"javascript:\" onclick=\"close_text(this); return false;\"><img border=\"0\" src=\"style/main_section_max_close.gif\" width=\"21\" height=\"21\" alt=\"Close\"/></a></div><div style=\"clear:both\"></div>";
		popup_t.innerHTML = item_f.innerHTML;
		
		
		
		popup.style.position = "absolute";
		popup.style.top = "200px";
		popup.style.left = "20px";
		popup.style.width = "750px";
		popup_t.style.height = "350px";
		
		
		
		
		// CLICK & DRAG /////////////////////////////////////////////////////////////////////////////////
		
			var ie = document.all;
			var nn6 = document.getElementById&&!document.all;
			
			var x,y;
			var dobj;

			function movemouse(e)
			{
				dobj.style.left = nn6 ? (tx + e.clientX - x) + "px" : tx + event.clientX - x;
				dobj.style.top  = nn6 ? (ty + e.clientY - y) + "px" : ty + event.clientY - y;
				return false;
			}
			
			function selectmouse(e) 
			{
				var fobj       = nn6 ? e.target : event.srcElement;
				
				
				dobj = fobj.parentNode; 
				while(dobj.className != "mainBottom_item_maximized") {
					dobj = dobj.parentNode;
				}
				
				tx = parseInt(dobj.style.left+0);
				ty = parseInt(dobj.style.top+0);
				x = nn6 ? e.clientX : event.clientX;
				y = nn6 ? e.clientY : event.clientY;
				document.onmousemove = movemouse;
				return false;
			}
			
			popup_h.style.cursor = "move";
			popup_h.onmousedown = selectmouse;
			
			popup_h.onmouseup = function() {
				document.onmousemove = null;
				return false;
			}
			
		////////////////////////////////////////////////////////////////////////////////////////////////
		
		
		
		
		
		var page = document.getElementById("contentBody");
		if(!page) page = document.body;
		if(!page) return false;
		page.parentNode.appendChild(popup);
		
		
	}
	
	function close_text(item) {
	
		tc = item.parentNode; 
		while(tc.className != "mainBottom_item_maximized") {
			tc = tc.parentNode;
		}
		
		tc.style.display = "none";
		
		try {
			tc.parentNode.removeChild(tc);
		} catch(e_error) {}
		
		delete tc;
		//alert("matt TODO: need to delete the close_text item: " + item);		/// TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
	}








	// save the contents of onload function (if defined)
	var onload_before_front;
	if(typeof onload != "undefined") {
		onload_before_front = onload;
	}
	


	// attach our own code to onload
	onload = function () {
		
		
		var mainBottom=document.getElementById('mainBottom');
		
		if(!mainBottom) return false;
		
		
		var divs = mainBottom.getElementsByTagName('div');
		
		for(var x=0; x<divs.length; x++) {
			if(divs[x].className == 'mainBottom_item') {
				//divs[x].onmouseover = function(){setMainBottomItemFull(this);};
				//divs[x].onmouseout = function(){setMainBottomItemSmall(this);};
				
				setMainBottomItemSmall(divs[x]);
				
				var tmpCover = document.createElement('div');
				tmpCover.className = "mainBottom_foot";
				tmpCover.innerHTML = "<a href=\"javascript:\" onclick=\"javascript:open_text(this); return false;\">Read more...</a>";
				divs[x].parentNode.appendChild(tmpCover);
				
			}
		}
		
		
		// run any previous onload code
		if(typeof onload_before_front == "function") onload_before_front();
	}


}




// set marker to true so we don't run code again (if system attaches this js multiple times)
LOADED_FRONT_JS = true;




