﻿Object.extend(Modalbox, {
	_insertContent: function(content){
		$(this.MBcontent).hide().update("");
		if(typeof content == 'string') {
			setTimeout(function() { // Hack to disable content flickering in Firefox
				this.MBcontent.update(content);
			}.bind(this), 1);
		} else if (typeof content == 'object') { // HTML Object is given		    
			var _htmlObj = content.cloneNode(true); // If node already a part of DOM we'll clone it
			// If clonable element has ID attribute defined, modifying it to prevent duplicates
			if(content.id) _htmlObj.id = "MB_" + content.id;
			_htmlObj.style.fontSize = "12px";
			//alert("in insert content2 " + _htmlObj.id);
			/* Add prefix for IDs on all elements inside the DOM node */
			$(_htmlObj).select('*[id]').each(function(el){ el.id = "MB_" + el.id; });
			//this.MBcontent.appendChild(_htmlObj);
			this.MBcontent.appendChild(_htmlObj);
			
			this.MBcontent.down().show(); // Toggle visibility for hidden nodes
			if(Prototype.Browser.IE) // Toggling back visibility for hidden selects in IE
				$$("#MB_content select").invoke('setStyle', {'visibility': ''});
			// Disable controls inside source content to prevent duplication
		    // variant # 1 - disable all form elements inside source content
		    /*content.getElementsBySelector('*[id]').each(function(el){ 
		        if (el.disabled != null)
		            el.disabled = true;
		    });*/
			// variant # 2 - put the source of content outside of the form			
			document.body.insertBefore(content, document.body.childNodes[0]);			
		}
	}
});
Object.extend(Modalbox, {
    changeTitle: function(title){
	    $(this.MBcaption).update(title);
	}
});