(function ($) {
	


   //Attach this new method to jQuery
    $.fn.extend({ 
         
        //This is where you write your plugin's name
        hideBlockFields: function() {
 
            //Iterate over the current set of matched elements
            return this.each(function() {
             	
                //code to be inserted here
				mySelect = $(this);
				//console.log(mySelect.parents('td').find('.field-name-field-block-body'));
				if($(this).val() == 'external') {
					$(this).parents('td').find('.field-name-field-block-body').hide();	
					$(this).parents('td').find('.field-name-field-block-links').fadeIn('slow');
					$(this).parents('td').find('.field-name-field-block-nodes').hide();	
		
				} else if ($(this).val() == 'internal') {
					$(this).parents('td').find('.field-name-field-block-body').hide();	
					$(this).parents('td').find('.field-name-field-block-links').hide();	
					$(this).parents('td').find('.field-name-field-block-nodes').fadeIn('slow');	
				
				} else if ($(this).val() == 'textarea') {
					$(this).parent().parents('td').find('.field-name-field-block-body').fadeIn('slow');	
					$(this).parents('td').find('.field-name-field-block-links').hide();	
					$(this).parents('td').find('.field-name-field-block-nodes').hide();	
				} else {
					$(this).parent().parents('td').find('.field-name-field-block-body').hide();
					$(this).parents('td').find('.field-name-field-block-links').hide();	
					$(this).parents('td').find('.field-name-field-block-nodes').hide();	
				}
		
				mySelect.bind('change', function(e) {
		   			block_type = $(this).val();
		   			if($(this).val() == 'external') {
		   				$(this).parents('td').find('.field-name-field-block-body').hide();	
		   				$(this).parents('td').find('.field-name-field-block-links').fadeIn('slow');
		   				$(this).parents('td').find('.field-name-field-block-nodes').hide();	
		
		   			} else if ($(this).val() == 'internal') {
		   				$(this).parents('td').find('.field-name-field-block-body').hide();	
		   				$(this).parents('td').find('.field-name-field-block-links').hide();	
		   				$(this).parents('td').find('.field-name-field-block-nodes').fadeIn('slow');	
		   			
		   			} else if ($(this).val() == 'textarea') {
		   				$(this).parent().parents('td').find('.field-name-field-block-body').fadeIn('slow');	
		   				$(this).parents('td').find('.field-name-field-block-links').hide();	
		   				$(this).parents('td').find('.field-name-field-block-nodes').hide();	
					} else {
						$(this).parent().parents('td').find('.field-name-field-block-body').fadeOut('slow');	
						$(this).parents('td').find('.field-name-field-block-links').hide();	
						$(this).parents('td').find('.field-name-field-block-nodes').hide();	
		   			}
		 			
				});
             
            });
        }
    });




	$(document).ready(function(){
		$('.field-name-field-block-type').find('select').hideBlockFields();
	});


/*
	function hideBlockFields() {
			console.log('hideBlockFields');
		$elements = $('.field-name-field-block-type').find('select');
	
		$elements.each(function(){
		});

	}
*/

})(jQuery);;

