var Unobtrusive = function(){};
Unobtrusive.prototype = {
	
	initialize: function () {
		this.submitToLink();
		this.popup();
		this.external();
		this.closePopup();
	},
	
	submitToLink: function() {
		$j("input[@type=submit][@rel=subtolink]").each(function(i){
			
			var jLinkElement = $j('<a href="#">' + $j(this).val() + '</a>');
			$j(this).after(jLinkElement).remove();
			
			jLinkElement.click(function(){
				$j(this).parents("form")[0].submit();
				return false;
			});
			
		});
	},
	
	popup: function() {
		$j("a[@rel^=popup]").click(function(){
			var dims = this.getAttribute('rel').match(/.*\[([0-9]+)-([0-9]+)\].*/);
			window.open(this.getAttribute('href'),this.getAttribute('href'),'width=' + dims[1] + ',height=' + dims[2] + ',resizable,scrollbars');
			return false;
		});
	},
	
	external: function() {
		$j("a[@rel=external]").click(function(){
			window.open(this.getAttribute('href'));
			return false;
		});
	},
	
	closePopup: function(){
		$j("#bt-close").click(function() {
			window.close();
			return false;
		});
	}
}

$j(function(){
	var unobtrusiveScript = new Unobtrusive();
	unobtrusiveScript.initialize();
});