/**
  *	site.js
  *
  *	Main entry point for web application functionality.
  *
  *	@category	JavaScript
  *
  *	@package	HOG
  *	@subpackage	9721
  *	@version	1.00
  *
  *	@author		Adam David Moss
  *	@copyright	Copyright © 2011 - Adam David Moss - All Rights Reserved
  *
  *	@uses		jQuery.min.js
  *	@uses		jQuery.jqModal.js
 */
window.defaultStatus = "H.O.G.\xae Geordie Chapter";

$( document ).ready( function() {
	// Core DOM loaded (i.e. internal XHTML).
	$( 'a' )
		.mouseover( function() {
			window.status = this.title;

			return true;
		} )

		.mouseout( function() {
			window.status = window.defaultStatus;

			return true;
		} );

	$.jqm.params.modal = true;
	$.jqm.params.overlay = 85;
	$.jqm.params.overlayClass = 'dialog-overlay';
} );

function openDialog( href, includeRecaptcha ) {
	includeRecaptcha = ( typeof includeRecaptcha == "undefined" ? false : true );

	$( document ).on( 'keydown', function( e ) {
		if( e.which == 27) {  // escape, close box
			closeDialog();
		}
	} );

	var onLoad = null;

	if ( includeRecaptcha ) {
		onLoad = function( hash ) { $.getScript( '//www.google.com/recaptcha/api/js/recaptcha_ajax.js', function() { Recaptcha.create( '6LdAdQwAAAAAAG4y04E2qG571F1F35i97AnHSbUz', 'container-recaptcha', { theme: 'white' } ); } ); };
	}

	$( '#container-dialog' ).jqm( { ajax: href,
					ajaxText: '<div style="font-family: Segoe Print, Comic Sans MS, verdana, arial, geneva, helvetica, sans-serif; width: 100%;">Loading<br /><img src=".graphic/loading.gif" /><br />Please Wait</div>',
					onLoad: onLoad
				} )
				.jqmShow();

	return false;
}

function closeDialog() {
	$( document ).off( 'keydown' );

	$( '#container-dialog' ).jqmHide()
				.html('');

	return true;
}

function updateDialog( content ) {
	$( '#container-dialog' ).html( content );

	if ( content.indexOf( '<form' ) == -1 ) {
		$( '#container-dialog' ).fadeOut( 2000, 'linear', function() { closeDialog(); } );
	} else {
		$.getScript( '//www.google.com/recaptcha/api/js/recaptcha_ajax.js', function() { Recaptcha.create( '6LdAdQwAAAAAAG4y04E2qG571F1F35i97AnHSbUz', 'container-recaptcha', { theme: 'white' } ); } );
	}
}
