/* OPEN WINDOW */

function openWindow(url, width, height){
	my_window= window.open (url,"mywindow","status=0,scrollbars=0,toolbar=0,menubar=0,resizeable=0,location=0,width="+width+",height="+height); 
}


function studentLinks(div, a, active_pos) {
	document.getElementById('Fun').style.display = "none";
	document.getElementById('Multimedia').style.display = "none";
	document.getElementById('Web').style.display = "none";

	document.getElementById('academic_and_research_link').style.backgroundPosition = "0px 0px";
	document.getElementById('just_for_fun_link').style.backgroundPosition = "-124px 0px";
	document.getElementById('multimedia_tools_link').style.backgroundPosition = "-248px 0px";
	document.getElementById('web_design_link').style.backgroundPosition = "-372px 0px";

// Reveal Active Map Element
	document.getElementById(div).style.display = "block";
	document.getElementById(a).style.backgroundPosition = active_pos;
}

function showLinks() {
	
	document.getElementById('just_for_fun_link').style.backgroundPosition = "-124px 0px";
	document.getElementById('multimedia_tools_link').style.backgroundPosition = "-248px 0px";
	document.getElementById('web_design_link').style.backgroundPosition = "-372px 0px";

	
	document.getElementById('academic_and_research_link').style.backgroundPosition = "0px -56px";
	document.getElementById('Fun').style.display = "block";
	document.getElementById('Multimedia').style.display = "block";
	document.getElementById('Web').style.display = "block";	
}

//	---------------------------------------------------------------------------
//	FUNCTION:	anchor()

//
//	Adds target="_blank" to links that go outside the site


function anchor() {
	// for DOM compliant browsers
	if (document.childNodes)
	{
		var fileTypes = new Array('pdf','doc','zip','xls');
		var a = document.getElementsByTagName("A");
		for (i=0;i<a.length;i++)
		{
			// open anything not in the current domain in a new window
			if ((a[i].hostname != window.location.hostname) && (a[i].href.indexOf('javascript') == -1)) {
				a[i].setAttribute('target', '_blank'); 
				debug.info('setAttribute(target,_blank) to id='+a[i]+')');
			}

			

			// search each anchor for a supported file extension
			for(x=0;x<fileTypes.length;x++) {
				ua = a[i].href.toUpperCase();
				ux = fileTypes[x].toUpperCase()
				if (ua.indexOf('.' + ux) != -1) {
					// if it matches, open in a new window and set the class equal to the file extension
					a[i].setAttribute('target', '_blank');
					a[i].className+=(a[i].className.length>0? " ": "") + fileTypes[x].toUpperCase();
					debug.info('set className='+fileTypes[x].toUpperCase()+' to id='+a[i]+')');
				}
			}
		}
	}
}

window.onload=anchor;


//	---------------------------------------------------------------------------
//	Script: string.cnet.js
//	These are mootools authored extensions designed to allow prototype.lite libraries run in this environment.
//	
//	Dependancies:
//	mootools - <Moo.js>, <String.js>, <Array.js>
//	
//	Author:
//	Aaron Newton, <aaron [dot] newton [at] cnet [dot] com>
//	
//	Class: String
//	This extends the <String> prototype.

String.implement({
	stripTags: function() {
		return this.replace(/<\/?[^>]+>/gi, '');
	},
	stripScripts: function() {
		return this.replace(/<script[^>]*?>.*?<\/script>/img, '');
	},
	evalScripts: function() {
		var scripts = this.match(/<script[^>]*?>.*?<\/script>/g);
		if(scripts) scripts.each(function(script){
			eval(script.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
		});
	},
	replaceAll: function(searchValue, replaceValue, regExOptions) {
		return this.replace(new RegExp(searchValue, $pick(regExOptions,'gi')), replaceValue);
	},
	urlEncode: function() {
		if (this.indexOf('%') > -1) return this;
		else return escape(this);
	},
	parseQuery: function() {
		var vars = this.split(/[&;]/);
		var rs = {};
		if (vars.length) vars.each(function(val) {
			var keys = val.split('=');
			if (keys.length && keys.length == 2) rs[encodeURIComponent(keys[0])] = encodeURIComponent(keys[1]);
		});
		return rs;
	},
	tidy: function() {
		var txt = this.toString();
		$each({
			"[\xa0\u2002\u2003\u2009]": " ",
			"\xb7": "*",
			"[\u2018\u2019]": "'",
			"[\u201c\u201d]": '"',
			"\u2026": "...",
			"\u2013": "-",
			"\u2014": "--"
		}, function(value, key){
			txt = txt.replace(new RegExp(key, 'g'), value);
		});
		return txt;
	}
});








//	---------------------------------------------------------------------------
//	CLASS:		FormTip(selector,options)
//	AUTHOR:		Ryan J. Salva
//	REVISED:	December 2008

var FormTip = new Class({
	Implements: Options,
	options: {
		className: 'FormTip',
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(selector,options){
		this.setOptions(options);
		this.els = $$(selector);
		this.els.each(function(el,index){
			el.addEvent('focus',this.show.bindWithEvent(this));
			el.addEvent('blur',this.hide.bindWithEvent(this));
		}.bind(this));
	},
	show: function(e) {
		var e = new Event(e);
		var el = e.target;
		if ($type(el) != 'element') return false;
		var title = el.getAttribute('title');
		if (!$defined(title)) return false;
		var pos = el.getPosition(el.getOffsetParent());
		var width = el.getWidth();
		this.tip = new Element('div',{'class':this.options.className,'styles':{
			opacity: 0,
			position: 'absolute',
			left: pos.x + width,
			top: pos.y
		}}).setText(title);
		this.tip.inject(el.getParent(),'inside');
		this.tip.tween('opacity',1); 
	},
	hide: function() {
		this.tip.remove();
	}
});


/*	---------------------------------------------------------------------------
	CLASS:		Layout(el[,columns])
	AUTHOR:		Ryan J. Salva, http://www.capitolmedia.com
	LICENSE:	MIT License, <http://en.wikipedia.org/wiki/MIT_License>	
	REVISED:	January 2008
	EXAMPLE:	<div id="Wrapper"><div id="Left">Foo</div><div id="Right">Bar</div></div>
				var x = new Layout('Wrapper',['Left','Right']);
	ABOUT:		Utility function designed to fix any layout using aboslute positioning for each column
				Adjusts the page to make wrapper as tall as the highest column (left, right, etc.)
				Most Capitol Media websites use the column ids: Left, Right, Middle and Canvas	
*/

var Layout = new Class({
	initialize: function(el,columns){
		this.columns = columns;
		this.el = $(el);
		if (!$defined(this.el)) return false;
		
		// this.el.setStyle('overflow','hidden');
		this.columns.each(function(col,index) {
			this.columns[index] = $(col);
		}.bind(this));
		this.columns = this.columns.clean();
		this.periodical = this.update.bind(this).periodical(200);
	},
	update: function() {
		var y = 0;
		this.columns.each(function(col,index) {
			var h = col.getCoordinates().height;
			if(h > y) y = h;
		});
		this.el.get('tween',{property:'height',duration:100}).start(y);
	}
});

//	---------------------------------------------------------------------------
//	FUNCTION:	fixPNG()
//	AUTHOR:		???
//
//	Enables transparecy for PNG files in IE
//	NOTE: Makes most colors a little darker than the GIF counterpart
//	
//	REQUIRED ASSETS:
//	files/site/x.gif (1x1 transparent GIF)
//
//	IMPLEMENTATION:
//	include this file in the header with utility.js and stylesheet

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		img.style.visibility = "visible";
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "site/x.gif";
		}
	}
}
function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "http://school.edmonds.wednet.edu/madrona/madronatech/site/x.gif";
}


//	---------------------------------------------------------------------------
//	CLASS:		Menu()
//	AUTHOR:		Ryan J. Salva
//	REVISED:	December 2007
//
//	Creates a drop-down menu for navigation. Also Corrects Windows IE support 
//	for LI:hover and adds an <IFRAME> behind drop-down menus to keep the 
//	menu above <SELECT> elements.
//
//	REQUIREMENTS:
//	Styles found in default.css
//	
//	TESTED IN:
//	Windows: IE 6, Firefox 1, Opera 8
//	Mac: IE 5.2, Firefox 1, Safari 1

var Menu = new Class({
	Implements: Options,
	options: {
		iframe: false,
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(el,options){
		this.el = $(el);
		if (!$defined(this.el)) return false;
		this.setOptions(options);
		
		this.el.getElements('li').each(function(li,index) {
			li.addEvent('mouseenter',function() {
				this.addClass('hover');
			});
			li.addEvent('mouseleave',function() {
				this.removeClass('hover');
			});
		});
		if (this.options.iframe) this.addIframe();
	},
	addIframe: function() {
		this.el.getElements('ul').each(function(ul,index) {
			var coord = ul.getCoordinates();
			var iframe = new Element('iframe',{'src':'about:blank','styles':{
				overflow:'hidden',
				border:0,
				width: coord.width,
				height: coord.height,
				left: 0,
				top: 0,
				zIndex: -10,
				opacity: 0
			}});
			iframe.injectTop(ul);
			ul.setStyle('z-index',99);
		});
	}
});



