var url_docroot = '/';

/* ================================================================================
 *  Tomarq extras
 * ================================================================================ */

$.extend({
	lock: function(count, callback) {		
		var count = count;
		return function(e) {if (--count == 0) callback();};
	},
  generateId: function() {return arguments.callee.prefix + arguments.callee.count++;}
});

$.generateId.prefix = 'jq';
$.generateId.count = 0;

$.fn.extend({
  generateId: function() {
    return this.each(function() {
      if (this.id == '')
        this.id = $.generateId();
    });
  }
});

/* ================================================================================
 *  Initialisation
 * ================================================================================ */

var Tabs = function() {
	var selectors, contents;

	function init() {
		selectors = $('.tabs .tab-selectors div.tab-selector');
		contents = $('.tabs .tab-contents div.tab-content');
		
		/*
		var max_height = 0;
		contents.each(function(idx, elem)
		{
			if ($(elem).height() > max_height)
				max_height = $(elem).height();
		});
		contents.css('height', max_height);
		*/
		selectors.click(selectTab);
	}
	
	function selectTab(e)
	{
		id = $(e.currentTarget).attr('id');
		
		// remove current selection
		contents.removeClass('selected');
		selectors.removeClass('selected');
		
		// select new one.
		$('.tabs #' + id + 'contents').addClass('selected')
		$(e.currentTarget).addClass('selected');
	}
	
	return {
		init: init
	};
};

$(function() {
	Tabs().init();
});
