//clear priority and other tasks if people reload the page or lost connection while a wizard was active
	$(hyperion).one("ready", function(event) {
		if(getStorage("wizardactive") === 'true')
		{
			requestPriorityClear();
			setStorage("wizardactive", false);
			if(getStorage("kodiAddress" != null))
			{
				kodiAddress = getStorage("kodiAddress");
				sendToKodi("stop");
			}
		}
	});
	function resetWizard()
	{
		$("#wizard_modal").modal('hide');
		clearInterval(wIntveralId);
		requestPriorityClear();
		setStorage("wizardactive", false);
		$('#wizp1').toggle(true);
		$('#wizp2').toggle(false);
		$('#wizp3').toggle(false);
		//cc
		if(withKodi)
			sendToKodi("stop");
		step = 0;
	}
	//rgb byte order wizard
	var wIntveralId;
	var new_rgb_order;
	function changeColor()
	{
		var color = $("#wiz_canv_color").css('background-color');
		if (color == 'rgb(255, 0, 0)')
		{
			$("#wiz_canv_color").css('background-color','rgb(0, 255, 0)');
			requestSetColor('0','255','0');
		}
		else
		{
			$("#wiz_canv_color").css('background-color','rgb(255, 0, 0)');
			requestSetColor('255','0','0');
		}
	}
	function startWizardRGB()
	{
		//create html
		$('#wiz_header').html('
'+$.i18n('wiz_rgb_title')+' '+$.i18n('wiz_rgb_intro1')+'
'+$.i18n('wiz_rgb_intro2')+'
');
		$('#wizp1_footer').html(''+$.i18n('wiz_rgb_expl')+'
');
		$('#wizp2_body').append('');
		$('#wizp2_body').append(''+$.i18n('wiz_rgb_q')+' ');
		$('#wizp2_body').append(''+$.i18n('wiz_rgb_qrend')+' '+$.i18n('wiz_rgb_qgend')+' 
');
		$('#wizp2_footer').html(''+$.i18n('wiz_cc_adjustgamma')+'
';
			if(withKodi)
			{
				sendToKodi('playP',"HGradient");
				h +=''+$.i18n('wiz_cc_btn_switchpic')+' ';
			}
			else
				h += ''+$.i18n('wiz_cc_lettvshowm', "gey_1, grey_2, grey_3, HGradient, VGradient")+'
';
			$('#wiz_cc_desc').html(h);
			$('#wiz_cc_btn_sp').off().on('click', function(){
					switchPicture(["VGradient","grey_1","grey_2","grey_3","HGradient"]);
			});
		}
		if(step == 4)
		{
			updateWEditor(["red"]);
			h = $.i18n('wiz_cc_adjustit',$.i18n('edt_conf_color_red_title'));
			if(withKodi)
			{
				h += ''+$.i18n('wiz_cc_testintro')+'
';
			if(withKodi)
			{
				h += ''+$.i18n('wiz_cc_testintrok')+'
';
				sendToKodi('stop');
				for(var i = 0; i
';
			}
			else
				h += ''+$.i18n('wiz_cc_testintrowok')+' '+$.i18n('wiz_cc_link')+' 
';
			h += ''+$.i18n('wiz_cc_summary')+'
';
			$('#wiz_cc_desc').html(h);
			$('.videobtn').off().on('click', function(e){
				if(e.target.id == "stop")
					sendToKodi("stop");
				else
					sendToKodi("playV",e.target.id+'.mp4');
				$(this).attr("disabled", true);
				setTimeout(function(){$('.videobtn').attr("disabled", false)},10000);
			});
			$('#btn_wiz_next').attr("disabled", true);
			$('#btn_wiz_save').toggle(true);
		}
		else
		{
			$('#btn_wiz_next').attr("disabled", false);
			$('#btn_wiz_save').toggle(false);
		}
	}
	function updateWEditor(el, all)
	{
		for (var key in cobj)
		{
			if(all === true || el[0] == key || el[1] == key || el[2] == key)
				$('#editor_container_wiz [data-schemapath*=".'+profile+'.'+key+'"]').toggle(true);
			else
				$('#editor_container_wiz [data-schemapath*=".'+profile+'.'+key+'"]').toggle(false);
		}
	}
	function startWizardCC()
	{
		//create html
		$('#wiz_header').html(''+$.i18n('wiz_cc_title')+' '+$.i18n('wiz_cc_intro1')+'
'+$.i18n('wiz_cc_kwebs')+' 
');
		$('#wizp2_footer').html(''+$.i18n('general_btn_next')+' '+$.i18n('wiz_cc_kodidiscon')+'
'+$.i18n('wiz_cc_kodidisconlink')+' '+$.i18n('wiz_cc_link')+' 
');
					withKodi = false;
				}
				else
				{
					$('#kodi_status').html(''+$.i18n('wiz_cc_kodicon')+'
');
					withKodi = true;
				}
				$('#btn_wiz_cont').attr('disabled', false);
			});
		});
		//listen for continue
		$('#btn_wiz_cont').off().on('click',function() {
			beginWizardCC();
			$('#wizp1').toggle(false);
			$('#wizp2').toggle(true);
		});
		$('#wiz_cc_kodiip').trigger("change")
		colorLength = serverConfig.color.channelAdjustment;
		cobj = schema.color.properties.channelAdjustment.items.properties;
		websAddress = document.location.hostname+':'+serverConfig.webConfig.port;
		imgAddress = 'http://'+websAddress+'/img/cc/';
		setStorage("wizardactive", true);
		//check profile count
		if(colorLength.length > 1)
		{
			$('#multi_cali').html(''+$.i18n('wiz_cc_morethanone')+'
'+$.i18n('wiz_hue_title'));
		$('#wizp1_body').html(''+$.i18n('wiz_hue_title')+' '+$.i18n('wiz_hue_intro1')+'
');
		$('#wizp1_footer').html('
');
		$('#wh_topcontainer').append(''+$.i18n('wiz_hue_desc1')+'
'+$.i18n('wiz_hue_desc2')+'
'+$.i18n('wiz_hue_press_link')+'  '+$.i18n('wiz_hue_ids_disabled')+' '+$.i18n('conf_leds_layout_cl_top')+' '+$.i18n('conf_leds_layout_cl_bottom')+' '+$.i18n('conf_leds_layout_cl_left')+' '+$.i18n('conf_leds_layout_cl_right')+' '+$.i18n('wiz_hue_ids_entire')+' '+$.i18n('wiz_hue_blinkblue',lightid)+' ']));
					}
					$('.hue_sel_watch').bind("change", function(){
						var cC = 0;
						for(key in lightIDs)
						{
							if($('#hue_'+key).val() != "disabled")
							{
								cC++;
							}
						}
						cC == 0 ? $('#btn_wiz_save').attr("disabled",true) : $('#btn_wiz_save').attr("disabled",false);
					});
					$('.hue_sel_watch').trigger('change');
				}
				else
				{
					$('#wizp2_body').html(''+$.i18n('wiz_hue_noids')+' ')
				}
			}
		});
	}
	function abortConnection(UserInterval){
		clearInterval(UserInterval);
		$('#wizp1').toggle(false);
		$('#wizp2').toggle(true);
		$('#wizp3').toggle(false);
		$("#wiz_hue_usrstate").html($.i18n('wiz_hue_failure_connection'));
	}