try {

	if (typeof(Prototype) == "undefined") throw "PopUnder requires Prototype.";
	
	var PopUnder = Class.create();
	
	PopUnder.prototype = {
		popunder: null,
		
		initialize: function(options){
			this.options = Object.extend({
				element: null,
				url: null,
				windowName: "",
				width: 50,
				heigth: 50,
				windowFeatures: {
					scrollbars: "no",
					resizable: "yes",
					status: "no",
					location: "no",
					toolbar: "no",
					menubar: "no"
				},
				useSizeToContent: true
			}, options || {});
			
			if (typeof(Prototype) == "undefined") 
				throw "PopUnder requires Prototype.";

			if(Object.isArray(this.options.element)){
				this.options.element = this.options.element.flatten();
				this.options.element.each(
					function(e){
						//dump("JobagentPopunder : Attaching onClick event to " + e);
						if ($(e) != null) $(e).observe("click", this.createPopUnder.bindAsEventListener(this));	
					},this
				);	
			}else if (Object.isElement($(this.options.element))){
				//dump("JobagentPopunder : Attaching onClick event to " + $(this.options.element));
				if ($(this.options.element) != null) $(this.options.element).observe("click", this.createPopUnder.bindAsEventListener(this));	
			}
			
		},
		
		createPopUnder: function(){
			if (getCookie("DONTSHOWJAPU") != 1 && this.popunder === null) {
				this.popunder = true; // window.open() takes time so this prevents user from opening multiple popunders
				var paramsTemplate = new Template("width=#{width},height=#{heigth},scrollbars=#{windowFeatures.scrollbars},resizable=#{windowFeatures.resizable}" +
				",status=#{windowFeatures.status},location=#{windowFeatures.location},toolbar=#{windowFeatures.toolbar},menubar=#{windowFeatures.menubar}");
				
				var params = paramsTemplate.evaluate(this.options);

				this.popunder = window.open(this.options.url, this.options.windowName, params);
				this.popunder.blur();
				this.popunder.opener.focus();
			}
		}
	};
	
}catch(e){
	dump("PopUnder: error: " + e.description);
}	

