//view controls functions
		
$j(document).ready(function () {
/*
	var menuHTML = '<div class="viewControls" id="controlsID">';
		menuHTML += 'Show in directory?<br />';
		menuHTML += '<label><input type="radio" name="viewOptionID" value="" checked="checked"> Default: Viewable by Faculty, Students, needs to be dynamic</label><br />';
		menuHTML += '<label><input type="radio" name="viewOptionID" value="show"> Show to everyone</label><br />';
		menuHTML += '<label><input type="radio" name="viewOptionID" value="hide"> Hide from everyone</label>';
		menuHTML += '</div>';
*/


	var controlsWait;
	
	// click to show the menu
	$j('.fieldControlsClick').click(function(){
		var menu = $j(this).parents('.fieldControls').find('.viewControls');
		menu.css({ 'top':$j(this).offset().top, 'left':$j(this).offset().left });
		menu.toggle("fast");
		return false;
	}).mouseenter(function(){
		$j(this).parents('.fieldControls').addClass('fieldGroupOver');
	}).mouseleave( function(){
		controlsWait = setTimeout( function(){ $j('.viewControls').hide() }, 250 );
		$j(this).parents('.fieldControls').removeClass('fieldGroupOver');
	})

	$j('.viewControls').mouseenter(
		function(){ clearTimeout(controlsWait) }
	).mouseleave(
		function(){ $j('.viewControls').hide() }
	);

	$j('.viewControls :radio').click( function() {
		val = $j(this).attr('value');
		$j(this).parents('.fieldControls').removeClass('show');
		$j(this).parents('.fieldControls').removeClass('hide');
		$j(this).parents('.fieldControls').addClass(val);
	});

	
	// $j('#previewClick').append('<div id="previewMenu"></div>');
	// 	for (var i=0; i < groupList.length; i++) {
	// 		$j('#previewMenu').append( '<div class="previewControl">'+ groupList[i] + '</div>' );	
	// 	};
			
	$j('#previewAsClick').mouseenter(
		function(){
			$j('#previewMenu').css({ 'left':$j(this).offset().left })
			$j('#previewMenu').show();
		}
	).mouseleave( function(){
		previewWait = setTimeout( function(){ $j('#previewMenu').hide() }, 250 )
	}).click( function(){return false;} );
	
	$j('#previewMenu').hide().mouseenter(
		function(){ clearTimeout(previewWait); }
		).mouseleave(
		function(){ $j('#previewMenu').hide(); }	
		);
	
	//leave preview mode
	$j('#editModeClick').hide().click(function(){
			$j('#profiletable').attr('class','');
			if($j('#Unpublish').attr('checked')){ $j('#hiddenMessage').remove(); }
			$j('.previewHide').show().removeClass('previewHide');
			$j('#previewMenu .on').removeClass('on');
			$j('#previewAsClick').text('Preview as...');
			$j('#profiletable input').removeAttr('disabled');
			$j('#profiletable select').removeAttr('disabled');
			$j('a').unbind('click',removeClick);
			$j('input').unbind('focus',removeClick);
			
			$j('.fieldControlsClick').click(function(){
				$j(this).parents('.fieldControls').find('.viewControls').toggle();
				return false;	
			});
			
			$j('#Unpublish').removeAttr('disabled');
			
			$j(this).hide();
			return false;
		});
	
	$j('#getShowHide').click(
		function(){
			var showHideVal = ''; 
			$j('.show').each( function(){ showHideVal += $j(this).attr('id') +'=show&' } );
			$j('.hide').each( function(){ showHideVal += $j(this).attr('id') +'=hide&' } );
			document.update.newShowHideSettings.value = showHideVal;
			return true;
		});
	
	
}); //end document ready

function removeClick(){ this.blur(); return false; }

function showPreview (link,grpName) {
	// preview mode functions
		if($j('#Unpublish').attr('checked')){ //hide entire profile is checked, hide everything and add a message
			$j('#profiletable').attr('class','');
			$j('#profiletable').attr('class','hideAll');
			$j('#Unpublish').attr('disabled','disabled');
			$j('.fieldControlsClick').unbind('click');
			if($j('#hiddenMessage').length == 0){$j('#previewControls').append('<div id="hiddenMessage">The entire profile is hidden.<br>No information will be displayed in the directory.</div>');}
		}else{
			// remove any previous classes that hid stuff
			$j('#profiletable').attr('class','');
			$j('.previewHide').show().removeClass('previewHide');
		
			// disable all of the form input fields
			// $j('#profiletable input').attr('disabled','disabled');  // going to add the no click instead to avoid ugly IE disabled mode
			$j('#profiletable select').attr('disabled','disabled');

			// add the class to the main container so we can add the css
			$j('#profiletable').attr('class','preview');						
			
			// apply the previewHide class to elements with specific group hide info
			//$j('.hide'+ $j(this).text()).addClass('previewHide');
			$j('.'+ grpName).addClass('previewHide');

			// turn on fields that are specifically shown by override
			$j('.show').show().removeClass('previewHide');
			
			// remove the hilight on the groups menu		
			$j('#previewMenu .on').removeClass('on');
			 //hilight groups menu item
			$j(link).addClass('on');
			
			// $j('#previewAsClick').text('Previewing as '+ grpName);
			
			// NO CLICKY IN PREVIEW MODE
			// need to disable these in a way in which I can reenable them later
			$j('a').bind('click',removeClick);
			$j('input').bind('focus',removeClick);
			
			$j('.fieldControlsClick').unbind('click');
			$j('#Unpublish').attr('disabled','disabled');
		}
			$j('#editModeClick').show();
			return false;
}

