$(document).ready(function(){

	// work some functionality for anchors with 'class="popup"'
	$('a.popup').each(function (i){
		$(this).click(function(event) {
			event.preventDefault();

			if( $(this).attr('class') ) {
				var pop_width = 800;
				var pop_height = 600;

				var class_info = $(this).attr('class');
				var regexp = /(h-\d+|w-\d+)/gi;

				var info = class_info.match(regexp);
				if( info != null ) {
					info.forEach(function(x,idx){
						if( /w-\d+/.test(x) ){ pop_width = x.substr(2); }
						if( /h-\d+/.test(x) ){ pop_height = x.substr(2); }
					});
				}
			}

			$(this).attr('title','This link opens in a new window');

			pop_url = $(this).attr('href');
			pop_window = window.open( pop_url,
			                          "ets_pop",
			                          "location=1,resizable=1,scrollbars=1,status=1,width="+pop_width+",height="+pop_height
			                        );
		}); // end this.click
	}); // end: a.popup each
	
}); // end: document.ready

if( !Array.prototype.forEach ){
	Array.prototype.forEach = function(fun /*, thisp*/) {
		var len = this.length >>> 0;
		if (typeof fun != "function") { throw new TypeError(); }
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this) { fun.call(thisp, this[i], i, this); }
		}
	};
}

