/* Twig Class */
var TWIG = {};

// Used to set anchor targets for external links and pop-ups
TWIG.setExternalLinks = (function() {
	function T() {
		var anchors = $('a'); // Get <a> tags
		anchors.each(function(idx){
			var a = $(this);
			if (a.attr('rel') == 'external') {
				a.attr('target','_blank'); // Set target
			}
			else if (a.attr('rel') == 'popup') {
				// Prevent multiple application
				if (a.attr('href').match(/^javascript:/)) {
						return void(0);
				};

				var popupParams = "'"+a.attr('href')+"','POPUP'"; // Build pop-up params list
				if ($.trim(a.attr('rev')) != '') { popupParams += ","+a.attr('rev'); };
				a.attr('href','javascript:void(0);'); // Clear href entry to prevent parent location changing
				a.removeAttr('target'); // Remove target if present
				a.unbind('click.setExternalLinks').bind('click.setExternalLinks', function(evt) { // Bind the onclick event
					eval('TWIG.openWindow('+popupParams+');'); // Pass eval'd params to openWindow fn
					return void(0);
				});
			};
		});
	}
	
	return T;
})();

// Open a pop-up window with set parameters
TWIG.openWindow = (function() {
	function T(URL,Name,W,H,L,T,Scrolls,Resize) {
		// Used to control params of pop-ups
		var defProps = 'copyhistory=no,directories=no,fullscreen=no,location=no,menubar=no,status=no,titlebar=yes,toolbar=no';
		var poppedProps = '';
	
		if (W != null) {
			if (Scrolls == true) { W += 16; } // Allow for chrome in IE
			poppedProps += ('width='+W+',');
		}
		if (H != null) { poppedProps += ('height='+H+','); }
		if (L != null) { poppedProps += ('left='+L+','); }
		if (T != null) { poppedProps += ('top='+T+','); }
		poppedProps += 'scrollbars=' + ((Scrolls != false) ? 'yes' : 'no') + ',' ; // Default 1
		poppedProps += 'resizable=' + ((Resize != false) ? 'yes' : 'no') + ',' ; // Default 1
		poppedProps += defProps;

//		alert(poppedProps);		
		poppedUp = window.open(URL,Name,poppedProps);
		if (poppedUp) { setTimeout("poppedUp.window.focus();",100); };
		return poppedUp;
	}
	return T;
})();




jQuery(document).ready(function() {
										  
	TWIG.setExternalLinks();

});
