$(document).ready(function()
{		
	/* Browsers */
	/*--------------------------------------*/
	$iphone = (navigator.userAgent.indexOf('iPhone') != -1);
	$itouch = (navigator.userAgent.indexOf('iPod') != -1);
	$msie = $.browser.msie;
	$safari = $.browser.safari;
	
	/* Form Tabs */
	/*--------------------------------------*/
	$("#greenroom-content_main .tabs").tabs(
	{
		show: 	function(event, ui)
				{
					$("#greenroom-content_main .tabs").show();
					
					if(ui.index == $(this).tabs('length')-1)
					{
						$('[name=next_tab]').hide();
					}
					else
					{
						$('[name=next_tab]').show().attr('rel', ui.index+1);
					}
					
					$('#'+ui.panel.id+' :input:first').focus();
				}
	});
	
	$('[name=next_tab]').click(function()
	{
		$("#greenroom-content_main .tabs").tabs('select', parseInt($(this).attr('rel')));
	});
	
	/* Module Select */
	/*--------------------------------------*/
	var $nav_module_current = $('#greenroom-nav_module_select').val();
	
	if(!$itouch && !$iphone)
	{
		$('#greenroom-nav_module_select').selectbox();
		
		$('#greenroom-nav_module_select_container li').click(function()
		{
			change_module($nav_module_current);			
		});
	}
	else
	{
		$("#greenroom-nav_module_select").show();
		
		$('#greenroom-nav_module_select').change(function()
		{
			change_module($nav_module_current);
		});
	}
	
	/* Anchors */
	/*--------------------------------------*/
	$('a[rel^='+$module+'][rel$='+$func+']').addClass('active');
	
	/* Login */
	/*--------------------------------------*/
	$('.login #username').focus();
	
	/* Functions */
	/*--------------------------------------*/
	$('#greenroom-nav_functions li').click(function()
	{
		$(this).siblings().children('a')
		.filter('.active')
		.addClass('disabled');

		$(this).children('a')
		.addClass('active');
	});
	
	$('.tabs a').keypress(function(e)
	{
		if(e.charCode == 32)
			$(this).click();
	});
	
	$('.submit a').keypress(function(e)
	{
		if(e.charCode == 32)
			window.location = $(this).attr('href');
	});
	
	/* Checkboxes */
	$('table.checkbox tr')
	.filter(':has(:checkbox:checked)')
	.addClass('selected')
	.end()
		.live('click', function(event)
		{
			$(this).toggleClass("selected");
			
			if (event.target.type !== "checkbox") 
			{
				checkbox = $(":checkbox", this);
				checkbox.attr("checked", checkbox.is(':not(:checked)'));
			}
		});
		
		
	/* Wysiwyg */
	$('.richtext').wysiwyg(
	{
		controls:
		{
			insertImage:  { visible: false },
		
			separator06:  { visible: false },
			
			h1mozilla: { visible: false },
			h2mozilla: { visible: false },
			h3mozilla: { visible: false },
			
			h1: { visible: false },
			h2: { visible: false },
			h3: { visible: false },
		
			separator08: { visible: false },
			
			increaseFontSize: { visible: false },
			decreaseFontSize: { visible: false }
			
		}
	});
	
	$('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});

});
	
/* Module Select */
/*--------------------------------------*/
function change_module($nav_module_current)
{
	var $nav_module_updated = $('#greenroom-nav_module_select').val();
	
	if($nav_module_updated != $nav_module_current)
	{
		window.location = $base_url+$nav_module_updated;
	}
}