var contact = {
	
	_url: 'http://' + window.location.hostname + '/contact.php',
   	
   	_active: false,
   	
   	_dialog: 0,
    
    _overlay: 0,
    
    _css: {
    	
    	dialog: {
    		
    		offsetLeft: function() {
    			return (parseInt(document.documentElement.clientWidth / 2)) - (this.width / 2 + (this.padding / 2))
    		},
    		offsetTop: function() {
    			return (parseInt(document.documentElement.clientHeight / 2)) - (this.height / 2 + (this.padding / 2))
    		},
    		padding: 10,
	  			width: 440,
	  			height: 440
    	},
    	
    	offsetScrollLeft: function() {
    		return document.documentElement.scrollLeft
    	},
    	
    	offsetScrollTop: function() {
    		return document.documentElement.scrollTop
    	}
    },
    
    _createDialog: function() {
    	
    	if (this._dialog) return;
    	
    	var _frame = document.createElement('iframe')
    	
    	with (_frame) {
    		
    		setAttribute('id', 'contact-frame')
    		setAttribute('src', this._url)
    		setAttribute('frameBorder', 0)
    		setAttribute('width', '100%')
    		setAttribute('height', '100%')
    		style.background = 'none'
    		style.border = 'none'
    	}
    	
    	// Create dialog
	  	this._dialog = document.createElement('div')
	  	this._dialog.setAttribute('id', 'contact-dialog')
	  	this._dialog.appendChild(_frame)
  		
  		// Set dialog CSS
		with (this._dialog.style) {
		
			backgroundColor = '#e3dcc2'
 			display = 'none'
	    	height = this._css.dialog.height + 'px'
	    	left = this._css.dialog.offsetLeft() + this._css.offsetScrollLeft() + 'px'
	    	padding = this._css.dialog.padding + 'px'
	    	position = 'absolute'
	    	top = this._css.dialog.offsetTop() + this._css.offsetScrollTop() + 'px'
	    	width = this._css.dialog.width + 'px'
	    }
	    
	    window.onresize = function() {
	    	contact.update()
	    }
	    
	    window.onscroll = function() {
	    	contact.update()
	    }
	    
	    // Add element to document
	    document.body.appendChild(this._dialog)
    },
    
    _createOverlay: function() {
    	
    	if (this._overlay) return;
    	
    	// Create overlay
	  		this._overlay = document.createElement('div')
	  		this._overlay.setAttribute('id', 'contact-overlay')
	  		this._overlay.onclick = function() { contact.close() }
	  		
		// Set overlay CSS
		with (this._overlay.style) {
			
			background = 'url(overlay.gif) repeat'
	    	display = 'none'
	    	height = document.body.offsetHeight + 'px'
	    	left = '0px'
	    	position = 'absolute'
	    	top = '0px'
	    	width = document.body.offsetWidth + 'px'
	    }
	    
	    // Add element to document
	    document.body.appendChild(this._overlay)
  	},
	
    update: function() {
    	this._dialog.style.left = this._css.dialog.offsetLeft() + this._css.offsetScrollLeft() + 'px'
	  		this._dialog.style.top = this._css.dialog.offsetTop() + this._css.offsetScrollTop() + 'px'
    },
    
    open: function() {
    	
    	if (this._active) return;
    	
    	this._createOverlay()
    	this._createDialog()
    	
    	this._overlay.style.display = 'block'
    	this._dialog.style.display = 'block'
    	
    	this._active = true
    },
    
	close: function() {
		
		this._overlay.style.display = 'none'
    	this._dialog.style.display = 'none'
    	
    	this._active = false
    }
}

