//to keep the page from being loaded in another site's frame
if(window != top) top.location.href = location.href;

if(typeof Prototype != "undefined"){
	Element.addMethods({
		imgPreLoad: function(){ //image preloader
			var tmp;
			var cacheImg = $A(arguments);
			cacheImg = cacheImg.map(function(img){
				tmp = new Image();
				return tmp.writeAttribute("src",img);
			});
		}, 
		
		equalHeights: function(parent){
			Element.cleanWhitespace(parent).setStyle({ height: 'auto' });
			parent.setStyle({ height: parent.getHeight()+'px' });
			return parent;
		}
	});
	
	Form.Element.Methods.processing = function(element){
		element = $(element);
		//skip buttons and HIDDEN inputs
		if(['submit','reset','hidden'].member(element.readAttribute('type'))) return;
		//Set controls for focus, blur, and change events
		var value = (element.hasAttribute('value'))?element.readAttribute('value'):"";
		function toggle(evt){
			this.writeAttribute('value',(this.hasAttribute('value'))?false:value);
			Event.stop(evt);
		}
		Event.observe(element,'focus',toggle);
		Event.observe(element,'blur',toggle);
		Event.observe(element,'change',function(){
			Event.stopObserving(element,'blur',toggle);
		});
	};
	Element.addMethods();
	
	Object.extend(Number.prototype, {
		rand: function(min){
			if(typeof min == "undefined") min = 0;
			return (Math.random()*this).round()+min;
		}
	});
	
	Element.imgPreLoad('images/windows/banner.jpg','images/windows/banner2.jpg','images/windows/nav_arrow.png','images/windows/bground.png','images/windows/bground1.png');
	//fix for IE handling of background images
	if(Prototype.Browser.IE){
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
		
		Event.observe(window,'load',function(){
			$$('dl.faculty_bios dd').invoke('insert',{ top: "\u2014" });
			//this fixes a number of IE bugs in displaying images
			//that might be floated
			$$('body img').invoke('makePositioned');
			//fix for quotes around quoted material for Internet Explorer
			$$('body q', '.quoted').each(function(q){
				Element.cleanWhitespace(q).setStyle({ fontStyle: 'normal' });
				Element.insert(q,{ top: q.hasClassName('single')?'\u2018':'\u201c' });
				Element.insert(q, { bottom: q.hasClassName('single')?'\u2019':'\u201d' });
			});
		});
	}
	
	if(window != top) top.location.href = location.href;
	
	['load','resize'].each(function(evt){
		Event.observe(window,evt,function(ev){
			Element.equalHeights($('main_area'));
			Event.stop(ev);
		});
	});
	
	document.observe('dom:loaded',function(){
		//set _blank target on those links with a rel of "external"
		$$('body a[rel="external"]').invoke('writeAttribute','target','_blank');
		
		//set fix for input text fields
		$$('body input[type=text]','body textarea').invoke('processing');
	});
	
	Event.observe(window,'load',function(){
		$$('img[alt="rotating banner"]').each(function(img){
			img.ancestors().first().cleanWhitespace().setStyle({
				height: img.getHeight()+'px !important'
			});
		}).each(function(img){
			var src = img.readAttribute("src");
			new PeriodicalExecuter(function(){
				Effect.toggle(img,'appear',{ delay: 1, afterFinish: 
					function(){
						if(!img.visible()) img.writeAttribute("src",src+"?"+new Date().getTime());
					}
				});
			},2);
		});
	});
	
} else {
	//for older browsers like Netscape 4...
	function MM_reloadPage(init){
		if (init==true) with (navigator){
			if ((appName=="Netscape")&&(parseInt(appVersion)==4)){
				document.MM_pgW=innerWidth;
				document.MM_pgH=innerHeight;
				onresize=MM_reloadPage;
			}
		} else if(innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH){
			location.reload();
		}
	}
	MM_reloadPage(true);
	
	window.onerror = function (){ return true; }
}