
function insertFontAwesome(){
	var colored;
	if(jQuery('#dx_fa_color_checker').is(':checked')) {
		colored = 'color='+jQuery('#dx_fa_preview span').css('color');
	}else{
		colored='';
	}
	colored = colored.replace(/\s/g, '');
	var insert = jQuery('#dx_fa_preview span').attr('class').replace('fa ','');
	var editor = jQuery('#editor_name').val();
	window.parent.jInsertEditorText('{'+insert+' '+colored+'}',editor);
	window.parent.SqueezeBox.close();
	return false;
}


function fa4(){

	var fa_style = jQuery('.fa_style a');
	var fa_preview = jQuery('#dx_fa_preview span');
	var btn_dx_fa_button = jQuery('.btn_dx_fa_button');


	if(fa_version == 5){
		var listado_sel = jQuery('.dib a i');
	}else{
		var listado_sel = jQuery('.fa-hover a');
	}


	listado_sel.click(function(){
		var fa_class = jQuery(this).attr("class");

		//TEXTO
		var fa_text = fa_class.replace('fa', '');
		jQuery(".fa-text").text(fa_class);

		//quito todo
		fa_preview.removeClass();
		
		//icon
		fa_preview.addClass(fa_class);
		fa_preview.addClass(jQuery("select#dx_fa_sizes").val());
		fa_preview.addClass(jQuery("select#dx_fa_rotated_fs").val());

		if(jQuery('input#dx_fa_fixedw').is(':checked')) {  
            fa_preview.addClass('fa-fw');
        } else {  
            fa_preview.removeClass('fa-fw');
        }

        if(jQuery('input#dx_fa_border').is(':checked')) {  
            fa_preview.addClass('fa-border');
        } else {  
            fa_preview.removeClass('fa-border');
        }

        jQuery("#dx_fa_pull_fs input[type='radio']:checked").val();

        if(jQuery('input#dx_fa_spin').is(':checked')) {  
            fa_preview.addClass('fa-spin');
        } else {  
            fa_preview.removeClass('fa-spin');
        }
	});

	btn_dx_fa_button.click(function(){
		insertFontAwesome();
	});


	fa_style.click(function(){

		var style_class = jQuery(this).attr("class").replace('btn', '');
		change_style(style_class);

	});

	/*sizer*/
	jQuery('select#dx_fa_sizes').change(function(){
		var mivalor = jQuery("select#dx_fa_sizes").val();

		//remove all classes
		fa_preview.removeClass('fa-lg');
		fa_preview.removeClass('fa-2x');
		fa_preview.removeClass('fa-3x');
		fa_preview.removeClass('fa-4x');
		fa_preview.removeClass('fa-5x');
		fa_preview.addClass(mivalor);
	});

	/*rotator*/
	jQuery('select#dx_fa_rotated_fs').change(function(){
		var mivalor = jQuery("select#dx_fa_rotated_fs").val();
		//remove all classes
		fa_preview.removeClass('fa-rotate-90');
		fa_preview.removeClass('fa-rotate-180');
		fa_preview.removeClass('fa-rotate-270');
		fa_preview.removeClass('fa-flip-horizontal');
		fa_preview.removeClass('fa-flip-vertical');
		fa_preview.addClass(mivalor);
	});

	/*fixed width*/
	jQuery('input#dx_fa_fixedw').change(function(){
		if(jQuery('input#dx_fa_fixedw').is(':checked')) {  
            fa_preview.addClass('fa-fw');
        } else {  
            fa_preview.removeClass('fa-fw');
        }
	});


	/* border */
	jQuery('input#dx_fa_border').change(function(){
		if(jQuery('input#dx_fa_border').is(':checked')) {  
            fa_preview.addClass('fa-border');
        } else {  
            fa_preview.removeClass('fa-border');
        }
	});


	/* pull */
	jQuery('input#dx_fa_pull').change(function(){
		var mivalor = jQuery("#dx_fa_pull_fs input[type='radio']:checked").val();
		//remove all classes
		fa_preview.removeClass('pull-right');
		fa_preview.removeClass('pull-left');
		fa_preview.addClass(mivalor);
	});

	/* spin */
	jQuery('input#dx_fa_spin').change(function(){
		if(jQuery('input#dx_fa_spin').is(':checked')) {  
            fa_preview.addClass('fa-spin');
        } else {  
            fa_preview.removeClass('fa-spin');
        }
	});

	/* color */
	jQuery('input#dx_fa_color').change(function(){
		/*if(jQuery('input#dx_fa_spin').is(':checked')) {  
            fa_preview.addClass('fa-spin');
        } else {  
            fa_preview.removeClass('fa-spin');
        }*/

        fa_preview.css('color',jQuery(this).val());
	});



	//BUSQUEDA V4
	if(fa_version == 5){

		var elemento = jQuery('#dx_fa_wrapper i').parent();

		jQuery('#dx_search .dx_filter_button').on('click',function(){

	 			var busqueda = jQuery('input#dx_filter_search').val();

	 			if(busqueda == ''){
	 				elemento.removeClass('dxdisplaynone');
	 			}else{
	 				elemento.addClass('dxdisplaynone');
					jQuery('i[class*='+busqueda+']').parent().removeClass('dxdisplaynone');
	 			}

		});



	}else{

		var elemento = jQuery('#dx_fa_wrapper a.fa');

		jQuery('#dx_search .dx_filter_button').on('click',function(){

	 			var busqueda = jQuery('input#dx_filter_search').val();

	 			if(busqueda == ''){
	 				elemento.removeClass('dxdisplaynone');

	 			}else{
	 				elemento.addClass('dxdisplaynone');
					jQuery('a[class*='+busqueda+']').removeClass('dxdisplaynone');
	 			}

		});


	}	

	//reset
	jQuery('.dx_filter_button_reset').on('click',function(){

 			jQuery('input#dx_filter_search').val('');
		 	elemento.removeClass('dxdisplaynone');

	});


	jQuery('input#dx_filter_search').on('keypress',function(){
		//console.log("pressed");
		if(event.keyCode == 13){

			if(fa_version == 5){
				var elemento = jQuery('#dx_fa_wrapper i').parent();
			}else{
				var elemento =  jQuery('#dx_fa_wrapper a.fa')
			}


			//jQuery('a[class*='+busqueda+']').removeClass('dxdisplaynone');
 			event.preventDefault();

 			var busqueda = jQuery('input#dx_filter_search').val();

 			if(busqueda == ''){
 				elemento.removeClass('dxdisplaynone');
 			}else{
 				elemento.addClass('dxdisplaynone');
				jQuery('a[class*='+busqueda+']').removeClass('dxdisplaynone');
				jQuery('i[class*='+busqueda+']').removeClass('dxdisplaynone');
 			}


 		}
	});
}



function change_style(newclass){

	var elements = jQuery('.fa-hover a');

	if(fa_version == 5){
		var elemento = jQuery('#dx_fa_wrapper i').parent();

		elemento.addClass('dxdisplaynone');

		newclass = newclass.split(' ').join('');

		jQuery('#dx_fa_wrapper i.'+newclass).parent().removeClass('dxdisplaynone');

		jQuery('input#dx_filter_search').val('');

		//elemento.removeClass('fa').removeClass('fas').removeClass('far').removeClass('fab').addClass(newclass);

	}else{
		var elemento =  jQuery('#dx_fa_wrapper a');
		elemento.removeClass('fa').removeClass('fas').removeClass('far').removeClass('fab').addClass(newclass);
	}

	


}




jQuery(document).ready(function(e) {
	fa4();
});

