/**
 * SprintX site enhancement
 *
 * @author Alan Horrocks <ahorrocks@doc-net.com>
 * @author Jim Tunstall <jtunstall@doc-net.com>
 * @copyright Copyright &copy; 2009, Doctor Net Limited
 * @package SprintX Website
 */

// Global namespace
var SprintX = {};

// Module stack
SprintX.modules = (function () {
   // Queued modules
	var arr_modules = [];

	// Public methods
	return {
	   // Add module
		add: function (obj_module_initialise) {
			arr_modules[arr_modules.length] = obj_module_initialise;
		},

		// Run modules
		run: function () {
			for (var int_index in arr_modules) {
            arr_modules[int_index]();
         }
		}
	};
}());

/* SprintX WMP */
SprintX.wmp = (function () {
   var int_current_wmn,

   initialise = function () {},
   _highligh_active_wmn = function () {
      $('#wmn_' + int_current_wmn).addClass('wmn_active');
   };

   SprintX.modules.add(initialise);

   var obj_public = {
	   select_wmn: function(int_wmn_id) {
	      int_current_wmn = int_wmn_id;
	      _highligh_active_wmn();
		}
   }

	return obj_public;
})();

/* SprintX Styled Modal Pop-Up */
SprintX.modal_window = (function () {
   var obj_jquery_tools,
   str_overlay_div = '#sprintx_overlay',
   str_content_id = '',
   hide = function () {
      $(str_overlay_div).hide();
   },
   obj_expose = {
      color: '#999',
      loadSpeed: 'fast',
      closeSpeed: 'fast',
      onBeforeClose: hide
   },
   initialise = function() {
      obj_jquery_tools = $(str_overlay_div).expose(obj_expose);
      $('a.modal_window').click(render);
      $(str_overlay_div + ' .close span').click(close);
      $(str_overlay_div + ' .close img').click(close);
   },
   render = function () {
      if (str_content_id.length == 0) {
         str_content_id = $(this).attr('id') + '_content';
      }
      $(str_overlay_div + ' .header .inner').empty();
      $(str_overlay_div + ' .body .inner').empty();
      if ($('#' + str_content_id).size() > 0) {
         obj_container_clone = $('#' + str_content_id).clone();
         // Need to update all DOM id's to be unique (we simply suffix with '_real' for now)
         $('*', obj_container_clone).each(function () {
            if ($(this).attr('id').length > 0) {
               $(this).attr('id', $(this).attr('id') + '_real');
            }
         })
         obj_container_clone.prependTo(str_overlay_div + ' .body .inner');
         $(str_overlay_div + ' .body .inner').children().each(function() {
            $(this).show();
         });
      }
      var int_top = $(window).scrollTop() + (($(window).height() - $(str_overlay_div).outerHeight()) / 2);
      var int_left = $(window).scrollLeft() + (($(window).width() - $(str_overlay_div).outerWidth()) / 2);
      $(str_overlay_div).css('top', int_top).css('left', int_left);
      obj_jquery_tools.expose().load();
      $(str_overlay_div).show();
      str_content_id = '';
      return false;
   },
   close = function () {
      obj_jquery_tools.expose().close();
   };

   SprintX.modules.add(initialise);

   var obj_public = {
	   show: function(str_new_content_id) {
	      str_content_id = str_new_content_id;
	      render();
		},
		hide: function() {
		   close();
		}
   }

	return obj_public;
}());

// JQuery DOM ready
$(document).ready(function() {
   // Run modules
   SprintX.modules.run();
});
