//CHARGEMENT DE LA PAGE
function init_plugin_customiser(){
	switch($.urlParam('page')){
		default:
		break;
	}
}


//Enregistrement des configurations
function customiser_setting_save(){
	var fields = [];
	$('input,select','#customiser-setting-form').each(function(i,element){
		element = $(element);
		var value = element.val();
		if(element.attr('type') == 'file'){
			value = element[0].files[0];
		}
		fields.push({
			signature : element.attr('data-signature'),
			instruction : element.attr('data-instruction'),
			value : value,
			type : element.attr('data-field-type'),
			id : element.attr('id')
		});
	});

	$.action({ 
		action : 'customiser_setting_save', 
		fields :  fields 
	},function(){
		$.message('success','Enregistré');
	});
}


function customiser_preview(element){
	element = $(element);
	var value =  element.val();
	if(element.attr('data-field-type')=='image'){
		
		var reader = new FileReader();
    	reader.onload = function (e) {
    		$(element.attr('data-signature')).css(element.attr('data-instruction'),'url('+e.target.result+')');
    	}
    	reader.readAsDataURL(element[0].files[0]);
	}else{
		$(element.attr('data-signature')).css(element.attr('data-instruction'),value);
		console.log(element.attr('data-signature'),element.attr('data-instruction'),value);
	}

	
}