$.getScript('http://relle.ufsc.br/exp_data/18/1/visir.js', function () {
	visir.Load(init);
});

$.getScript('http://relle.ufsc.br/exp_data/18/1/zoom.js');
//$.getScript('https://raw.githubusercontent.com/twbs/bootstrap/master/js/transition.js');
$.getScript('http://relle.ufsc.br/exp_data/1/1/welcome.js', function () {
    var shepherd = setupShepherd();
    addShowmeButton('<button id="btnIntro" class="btn btn-sm btn-default"> <span class="long">' + lang.showme + '</span><span class="short">' + lang.showmeshort + '</span> <span class="how-icon fui-question-circle"></span></button>')
    $('#btnIntro').on('click', function (event) {
        event.preventDefault();
        shepherd.start();
    });
});

$.getScript('http://relle.ufsc.br/exp_data/18/1/zoom.js');
//$.getScript('https://raw.githubusercontent.com/twbs/bootstrap/master/js/transition.js');

$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/zoom.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instruments/breadboard/breadboard.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instruments/flukemultimeter/flukemultimeter.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instruments/tripledc/tripledc.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instruments/hp_funcgen/hp_funcgen.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instruments/ag_oscilloscope/ag_oscilloscope.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instruments/ni_oscilloscope/ni_oscilloscope.css" type="text/css"/>');
$('head').append('<link rel="stylesheet" href="http://relle.ufsc.br/exp_data/18/1/instrumentframe/instrumentframe.css" type="text/css"/>');

/* --- Leave experiment for no queue ---*/
$( "#btnLeaveExp" ).click(function() {
  location.reload(true);
});

function init() {
	function MakeMeasurement() {
		reg.MakeRequest(transport);
	}

	trace("starting up..");

	var transport = new visir.JSTransport(visir.SetWorking);
	transport.onerror = function (err) { alert("Error: " + err); }

	transport.Connect(visir.Config.Get("mesServer"), "fnord");

	var extservice = new visir.ExtServices({ MakeMeasurement: MakeMeasurement });
	var reg = new visir.InstrumentRegistry(extservice);
	var frame = new visir.InstrumentFrame(reg, transport, $("#instrumentframe"));

	emptyexperiment = '<save version="2"><instruments htmlinstruments="Breadboard|FlukeMultimeter|HPFunctionGenerator|AgilentOscilloscope|TripleDC"></instruments><circuit></circuit></save>';
	
	// variavel para carregar o circuito inicial
	// gerar a lista de componentes na interface original do visir, gerar um .cir (save) e colar abaixo
	// veja o arquivo ../exp_script.js
        saved = '<save version="2"><instruments htmlinstruments="Breadboard|FlukeMultimeter|HPFunctionGenerator|AgilentOscilloscope|TripleDC"></instruments><circuit><circuitlist><component>R 3.9k 78 13 0</component><component></save>';

	reg.LoadExperiment(saved, frame.GetInstrumentContainer()); 

	$(".measure").click(function () {
		MakeMeasurement(); 
	});

	$("#showlog").click(function () {
		$("#logwindow").css("display", "block");
	});
	$("#hidelog").click(function () {
		$("#logwindow").css("display", "none");
	});

}

$(document).ready(function(){
window.matchMedia("(orientation: portrait)").matches
	//console.log("teste");
});


