function init_ui( )
{
	// Buttons
	$('button').button();
	$('input:submit').button();
	$('input:button').button();
	
	// Input boxes
	$('input:text, input:password').addClass('inputctl');
	$('input:text, input:password').focus(function() {
		$(this).addClass('highlight');
	});
	$('input:text, input:password').blur(function() {
		$(this).removeClass('highlight');
	});
	$('input.uppercase').keyup(function() {
		$(this).val($(this).val().toUpperCase());
	}); // input with class uppercase forces text to uppercase
	
	// Datepickers
	$('.datepicker').datepicker();
	$('.datepicker2x2').datepicker({ numberOfMonths: [2,2] });
	
	// Zebra stripe table_list tables
	$('.table_list tr:nth-child(even)').addClass('alt');
	$('.table_list tr').mouseover(function() {
		$(this).addClass('hover');
	}).mouseout(function() {
		$(this).removeClass('hover');
	});
	
	// Page navigation
	$('div#page-first').click(function () {
		if($('div#page-first').hasClass('slideDown'))
		{
			$('div#page-inside').animate({ 'height': 'toggle', 'opacity': 'toggle' });
			$('div#page-actions').removeClass('slideDown');
			$('div#page-first').removeClass('slideDown');
		}
		else
		{
			$('div#page-inside').width($('div#page-actions').width());
			$('div#page-inside').animate({ 'height': 'toggle', 'opacity': 'toggle' });
			$('div#page-actions').addClass('slideDown');
			$('div#page-first').addClass('slideDown');
		}
	 });
	 
	 //for each description div...  
	$('div.description').each(function(){  
		//...set the opacity to 0...  
		$(this).css('opacity', 0);  
		//..set width same as the image...  
		$(this).css('width', $(this).siblings('img').width());  
		//...get the parent (the wrapper) and set it's width same as the image width... '  
		$(this).parent().css('width', $(this).siblings('img').width());  
		//...set the display to block  
		$(this).css('display', 'block');  
	});  
   
	// $('div.slide-wrapper').hover(function(){  
		// //when mouse hover over the wrapper div  
		// //get it's children elements with class description '  
		// //and show it using fadeTo  
		// $(this).children('.slide-description').stop().fadeTo(500, 0.7);  
		// slideIsHovering = true;
	// },function(){  
		// //when mouse out of the wrapper div  
		// //use fadeTo to hide the div  
		// $(this).children('.slide-description').stop().fadeTo(500, 0);  
		// slideIsHovering = false;
	// }); 
	
	$('#link1right').hoverIntent(function(){
		$('#link1right-grey').fadeIn('slow',function(){
			$('#link1right-grey').mouseout(function(){
				$('#link1right-grey').fadeOut('slow');
			});
		});
	},function(){
	});
	$('#link1left').hoverIntent(function(){
		$('#link1left-grey').fadeIn('slow',function(){
			$('#link1left-grey').mouseout(function(){
				$('#link1left-grey').fadeOut('slow');
			});
		});
	},function(){
	});
	$('#link2right').hoverIntent(function(){
		$('#link2right-grey').fadeIn('slow',function(){
			$('#link2right-grey').mouseout(function(){
				$('#link2right-grey').fadeOut('slow');
			});
		});
	},function(){
	});
	$('#link2left').hoverIntent(function(){
		$('#link2left-grey').fadeIn('slow',function(){
			$('#link2left-grey').mouseout(function(){
				$('#link2left-grey').fadeOut('slow');
			});
		});
	},function(){
	});
	
	
	// photo albums
	$('a.album1').lightBox({fixedNavigation:true});
	$('a.album2').lightBox({fixedNavigation:true});
	$('a.album3').lightBox({fixedNavigation:true});
	$('a.album4').lightBox({fixedNavigation:true});
		
	// mega menus
	jkmegamenu.render( );	
}

function popup(id, title, url)
{
	id = '#' + id;
	$(id).load(url).dialog({
		autoOpen: false,
		title: title,
		width: 500,
		height: 420
	});
	$(id).dialog('open');
	$(".ui-dialog-content").css("height", "");
}

function popup_sized(id, title, url, width, height)
{
	id = '#' + id;
	$(id).load(url).dialog({
		autoOpen: false,
		title: title,
		width: width,
		height: height
	});
	$(id).dialog('open');
	//$(id).height(height);
	$(".ui-dialog-content").css("height", "");
}

function popup_close(id)
{
	id = '#' + id;
	$(id).dialog('close');
}

function popup_message(message)
{
	$('#popup_message').html('<p>' + message + '</p>');
	$('#popup_message').dialog({
		autoOpen: false,
		title: 'SMITH Northview Hospital',
		modal: true,
		buttons: [{
				text: "OK",
				click: function() {
				$(this).dialog('close'); }
			}
		]
	});
	$('#popup_message').dialog('open');
	$(".ui-dialog-content").css("height", "");
}

function popup_confirm(message, btn_confirm_text, btn_confirm_func, btn_confirm_args_array)
{
	$('#popup_confirm').html('<p>' + message + '</p>');
	$('#popup_confirm').dialog({
		autoOpen: false,
		title: 'Please Confirm',
		modal: true,
		buttons: [{
				text: btn_confirm_text,
				click: function() {
				xajax_update_module(btn_confirm_func, btn_confirm_args_array);
				$(this).dialog('close'); }
			},
			{
				text: "Cancel",
				click: function() {
				$(this).dialog('close'); }
			}
		]
	});
	$('#popup_confirm').dialog('open');
	$(".ui-dialog-content").css("height", "");
}

// generic - handles up and down key events for search dropdowns
function on_search_keydown(event)
{
	if(event.keyCode == 40) // down
	{
		selected_elem = $('a.auto_suggestion_result.selected').first();
		if($(selected_elem).length == 0)
		{
			// select the first returned result
			$('a.auto_suggestion_result').first().addClass('selected');
		}
		else
		{
			// get next element
			next_elem = $(selected_elem).parent().next().children('a.auto_suggestion_result').first();
			if($(next_elem).length)
				$(next_elem).addClass('selected');
			$(selected_elem).removeClass('selected');
		}
	}
	else if(event.keyCode == 38) // up
	{
		selected_elem = $('a.auto_suggestion_result.selected').first();
		if($(selected_elem).length == 0)
		{
			// select the last returned result
			$('a.auto_suggestion_result').last().addClass('selected');
		}
		else
		{
			// get prev element
			prev_elem = $(selected_elem).parent().prev().children('a.auto_suggestion_result').first();
			if($(prev_elem).length)
				$(prev_elem).addClass('selected');
			$(selected_elem).removeClass('selected');
		}
	}
}

function display_on(id)
{
	$("#" + id).show();
}

function display_off(id)
{
	$("#" + id).hide();
}

function clear_display(id)
{
	$("#" + id).val("");
}

function clear_radio_buttons(name)
{
	$("input[name='" + name + "']").each(function () {
		$(this).checked = false;
	});
}
