var morph = null;
var morphBack = null;
var slide = null;

window.addEvent ( 'domready', function () {
	
	var FadeInFadeOut = function ( pItem )
	{
		morph = new Fx.Morph ( pItem, {
			duration: 500,
			onComplete: function () {
				morphBack = new Fx.Morph ( pItem, {
					duration: 500
				}).start ({
					'color': ['#BBBBBB', '#888888']
				});
			}
		
		}).start ({
			'color': ['#888888', '#BBBBBB']
		});
  	};
  	
  	/* For fading in/out field descriptions when clicking an input field */
  	/*
  	$$('input').set ( 'opacity', 1 ).addEvents ( {
  		
  		focus: function () {
  			
  			$try ( function () {
  				if ( this.getParent ( 'tr' ) )
  				{
  					var tr = this.getParent ( 'tr' );
  					
  					if ( tr.getElement ( '.field-description' ) )
  					{
  						tr.getElement ( '.field-description' ).morph ( { 'color':'#5997D1', 'left': 0 } );
					}
				}
			});
			
		},
		
		blur: function () {
			
			if ( this.getParent ( 'tr' ) )
  				{
  					var tr = this.getParent ( 'tr' );
  					
  					if ( tr.getElement ( '.field-description' ) )
  					{
  						tr.getElement ( '.field-description' ).morph ( { 'color':'#FFFFFF', 'left': 900 } );
					}
				}
			}
	});
	*/
	
	/* For fading in/out description of scanners on left side */
	$$('.scanners-item').each ( function ( pItem, pIndex ) {
		
		pItem.addEvents ( {
			
			mouseenter: function () {
				var info = pItem.getElement ( 'em' );
				
				if ( $defined ( info ) )
				{
					FadeInFadeOut ( info );
				}
			}
			
		});
		
	});
	
	/* Causes content to slide out when a hyperlink is clicked */
	// $$('.click-slide.nav').each ( function ( pItem, pIndex ) {
	$$('.click-slide-nav').each ( function ( pItem, pIndex ) {
		
		if ( !pItem.get ( 'rel' ) )
		{
			
			pItem.addEvents ( {
				
				click: function ( pEvent ) {
					pEvent.stop ();
					
					if ( $chk ( morph ) )
					{
						morph.cancel ();
					}
					
					if ( $chk ( morphBack ) )
					{
						morphBack.cancel ();
					}
					
					slide = new Fx.Slide ( 'slide-in', { mode: 'horizontal' } );
					slide.toggle ();
					
					slide.addEvent ( 'complete', function () {
						window.location = pItem.get ( 'href' );
					});
					
				}
				
			});
		}
	});
	
	// New window links
  $$('.new-window').each ( function ( pItem, pIndex) {
	pItem.set ( 'target', '_blank' );
  });
  
  var lblParent;
  var sHTML;
  
  // Makes required fields have a red border color
  $$('input').each ( function ( item, index )
  {
      /* if ( item.type == 'text' || item.text == 'password' )
      {
      	*/
          if ( item.get ( 'class' ).contains ( 'required' ) )
          {
          	$try ( function () {
     		  
     		  if ( $defined ( item.getParent ( 'tr' ) ) ) {
	    	      lblParent = item.getParent ( 'tr' ).getElement ( 'td' ).getElement ( 'label' );
	    	      
	    	      if ( $chk ( lblParent ) )
	    	      {
		    	      sHTML = lblParent.get ( 'text' );
		    	      lblParent.set ( 'html', '<span style="color: red;">*</span> ' + lblParent.get ( 'text' ) );
	    	      }
    	      }
  	         });
   	      }
      // }
  });
	
});
