window.addEvent('domready', function() {
	
	// add rounded corners
	if ($('cnr_nav')) {
		
		var bottomCornersNav = new Element('div', { 'id': 'cnr_nav_bottom' });
		bottomCornersNav.injectAfter($('cnr_nav'));
	}

	if ($('cnr_ctt_main')) {
		
		var bottomCornersCnt = new Element('div', { 'id': 'cnr_main_bottom' });
		bottomCornersCnt.injectAfter($('cnr_ctt_main'));
	}
	
	// open links to downloadable files or other sites in a new window
	Array.prototype.f_contains = function(s) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == s) return true;
		}
		return false;
	}

	// known extensions for downloadable files
	var exts = ['png', 'jpg', 'jpeg', 'gif', 'pdf', 'doc', 'xls', 'ppt', 'zip', 'gz', 'mpg', 'mpeg', 'mov', 'mp4', 'avi', 'wmv', 'mp3', 'wav', 'swf', 'bmp', 'tif', 'tiff', 'svg'];

	var links = $ES('a');

	for (var i = 0; i < links.length; i++) {
		
		var link  = links[i];

		// find extension
		var split_slash = link.href.split('/');
		var split_ext   = split_slash[split_slash.length - 1].split('.');
		var ext         = split_ext[split_ext.length - 1];

		// check if extension indicates a downloadable file
		if (split_ext.length > 1) {
			if (exts.f_contains(ext)) {
				links[i].target = '_blank';
			}
		}
		
		// look for links to other sites
		if (link.href.substring(0, 7) == 'http://') {
			if (link.href.substring(7, 7 + window.location.hostname.length) != window.location.hostname) {
				links[i].target = '_blank';
			}
		}
	}
});

/*
  Moopop
  example: <a href="http://www.google.com" rel="popup[600,400]">popup google at 600x400</a>
*/
var moopop={width:0,height:0,captureByRel:function(attrVal,parent){this.capture($ES('a',parent||document).filterByAttribute('rel','*=',attrVal));},capture:function(el,width,height){if($defined(width)&&$defined(height)){this.width=width;this.height=height;}
switch($type(el)){case'element':this.add_pop_to(el);break;case'string':case'array':$$(el).each(function(el){this.add_pop_to(el);},this);break;}
this.width=null;this.height=null;},add_pop_to:function(el){el.addEvent('click',function(e){new Event(e).stop();this.popup(el);}.bind(this));var size=el.getAttribute('rel').match(/\[(\d+),\s*(\d+)\]/)||['',this.width,this.height];if(size[1])el.setAttribute('popupprops','width='+size[1]+', height='+size[2]);},popup:function(el){window.open(el.href,'',el.getAttribute('popupprops')||'');}};window.addEvent('domready',function(){moopop.captureByRel('popup');});
