PHPurchase = {
    initialise: function() {
	this._root = document.createElement( 'div' );
	$( this._root ).addClass( 'PHBlocker' );
	$( this._root ).dblclick( function() {
	    PHPurchase.close();
	} );

	this._container = document.createElement( 'div' );
	$( this._container ).addClass( 'PHForm' );

	var form = document.createElement( 'form' );
	$( form ).html( [
	    '<div class="buttons">',
	    '<img src="/images/purchase_prints.gif" width="" height="" alt="Purchase Prints" class="menu" />',
	    '<a href="#">close</a>',
	    '</div>',
	    '<p>Peregrine Heathcote is selling a number of Limited Edition Prints personally signed by him.</p>',
		'<p>The prints are sold unframed however we can arrange framing, please contact us for separate pricing and delivery times. Unframed prints will be sent within the UK usually withing 5 working days. For delivery worldwide please contact us for additional delivery costs.</p>',
		'<p>We use PayPal  for purchases, which is a secure online payment service that enables you to pay in any currency. If you do not have a PayPal account you can still use the service using a valid credit or debit card. If you would prefer to pay by an alternative method please contact us.</p>',
		 '<p><a href="#">Continue to page</a></p>'
	].join( '' ) );

	$( form ).submit( this.submit );
	$( form ).click( function() {
	    var evt = arguments[0];
	    if ( evt.target && evt.target.tagName == 'A' ) {
		PHPurchase.close();
		return false;
	    }
	} );
	
	$( this._root ).appendTo( document.body );

	$( this._container ).append( form ).appendTo( document.body );

	$( this._root ).toggle();
	$( this._container ).toggle();

	/*$( '#menu a.contact' ).click( function() {
	    form.name.value = '';
	    form.email.value = '';
	    form.message.value = '';

	    PHPurchase.open();
	    return false;
	} );*/
    },
    close: function() {
	var me = this;

	$( this._container ).slideToggle( 'slow', function() {
	    $( me._root ).fadeTo( 1000, 0, function() {
		$( me._root ).css( { 'display' : 'none' } );
	    } );
	} );
    },
    open: function() {
	var me = this;

	$( this._root ).css( { 'display' : 'block' } ).fadeTo( 1000, 0.8, function() {
	    $( me._container ).slideToggle( 'slow' );
	} );
    },
    respond: function() {
    },
    submit: function() {
	var me = PHPurchase;
	me.close();

	var params = [
	    'name=' + escape( this.name.value ),
	    'email=' + escape( this.email.value ),
	    'message=' + escape( this.message.value ),
	    'callback=' + 'PHPurchase.respond'
	];

	var script_url = '/_inc/SendMail.php?' + params.join( '&' );
	var script_tag = document.createElement( 'script' );
	script_tag.type = 'text/javascript';
	script_tag.src = script_url;

	setTimeout( function() {
	    document.getElementsByTagName( 'head' )[0].appendChild( script_tag );
	}, 0 );

	return false;
    }
}

$( document ).ready( function() {
    PHPurchase.initialise();
} );
