var iframe = new Element('iframe', {'width':'400','height':'600','src':'form_mail/index.php', 'frameborder':'0'});	
var close_html = "<a href = '#' onclick = 'overlay.hide()'><img src = 'images/close_btn_small.gif' id='close_btn' border='none'></a>";
var firstRun = true;
var dialog = new Element('div');


function openContact(){
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	
		var ieVersion = new Number(RegExp.$1); // capture x.x portion and store as a number
 		if (ieVersion <= 6){
 			//document.write("You're using IE6.x or earlier")
			contactPopUp();
		} else {
 			showContactOverlay();
		}
	} else {
 		showContactOverlay();
	}
}

function contactPopUp(){
	window.open('form_mail/index.php','contact','width=400,height=600,location=no,toolbar=no,status=no,scrollbars=no,resize=no');
}

function showContactOverlay(){
	
	if(firstRun) { 
		overlay = new DialogOverlay(dialog);
		dialog.insert(iframe);
		dialog.insert({'bottom': close_html});
		firstRun = false;
	}
		
	overlay.show()
}
		
function DialogOverlay(content) {
	
	// Manage arguments and assign defaults, 
	if (typeof container == 'undefined' ) container = document.body;
	if (null == (this.container = $(container))) throw("container is not valid");

	// Assign instance variables
	this.content = content;
	this.overlay = new Element('div', { 'class': 'overlay' }).hide();
	this.dialog = new Element('div', { 'class': 'dialog' }).hide();
	
	// Hide the overlay when clicked. Ignore clicks on the dialog.
	Event.observe(this.overlay, 'click', this.hide.bindAsEventListener(this));
	Event.observe(this.dialog, 'click',  function(event) { Event.stop(event) });
	
	// Insert the elements into the DOM
	this.dialog.insert(this.content);
	this.container.insert(this.overlay);
	this.container.insert(this.dialog);

	// Content may have been hidden if it is embedded in the page
	content.show();
	this.dialog.hide();
}

DialogOverlay.prototype.show = function() {
	new Effect.Appear(this.overlay, { duration: 0.25,  to: 0.8 });
	//new Effect.Appear(this.dialog, { duration: 0.25,  to: 1 });
	this.dialog.show();
	return this;
};

DialogOverlay.prototype.hide = function(event) {
	this.dialog.hide();
	this.overlay.fade({ duration: 0.25 });
	return this;
};