var play = document.querySelector("#button-play");
var pause = document.querySelector("#button-pause");
var skip = document.querySelector("#button-skip");
var up = document.querySelector("#button-up");
var down = document.querySelector("#button-down");
var power = document.querySelector("#button-power");

play.addEventListener("click", function(ev){

	ev.preventDefault();
	var result = fetch('/play', {
		method: 'get',
		body: {"Command":'play'}
	});
	result.then(function(response) {
        if (response.status === 200) {
					var line = document.querySelector('#progress')
					line.animate(1);
        }
        console.log(response);
    });
});
pause.addEventListener("click", function(ev){

	ev.preventDefault();
	var result = fetch('/pause', {
		method: 'get',
		body: {"Command":'pause'}
	});
	result.then(function(response) {
        if (response.status === 200) {
						var line = document.querySelector('#progress')
						line.stop();
        }
        console.log(response);
    });
});
skip.addEventListener("click", function(ev){

	ev.preventDefault();
	var result = fetch('/skip', {
		method: 'get',
		body: {"Command":'skip'}
	});
	result.then(function(response) {
        if (response.status === 200) {
            console.log("submitted successfully");
        }
        console.log(response);
    });
});
up.addEventListener("click", function(ev){

	ev.preventDefault();
	var result = fetch('/up', {
		method: 'get',
		body: {"Command":'up'}
	});
	result.then(function(response) {
        if (response.status === 200) {
            console.log("submitted successfully");
        }
        console.log(response);
    });
});
down.addEventListener("click", function(ev){

	ev.preventDefault();
	var result = fetch('/down', {
		method: 'get',
		body: {"Command":'down'}
	});
	result.then(function(response) {
        if (response.status === 200) {
            console.log("submitted successfully");
        }
        console.log(response);
    });
});

power.addEventListener("click", function(ev){

	ev.preventDefault();
	var cmd = {};
	var action = '';
	console.log(power.className.indexOf("on"));
	if (power.className.indexOf("power") < 0){
		cmd = {action: 'on', button: 'Off'};
		action = 'power'
	} else {
		cmd = {action: 'off', button: 'On'};

	}

	var result = fetch('/power/'+cmd.action, {
		method: 'get',
		type: 'json',
		body: JSON.stringify({"Command":cmd.action})
	});
	result.then(function(response) {
        if (response.status === 200) {
            console.log("submitted successfully");
						power.className = "pure-button " +action;
						power.innerHTML = '<i class="fa fa-power-off"></i> Turn '+cmd.button;
        }
        console.log(response);
    });
});

@@ -418,37 +418,9 @@
 get'
-,%0A%09%09body: %7B%22Command%22:'play'%7D
 %0A
+
 %09%7D);
@@ -740,37 +740,8 @@
 get'
-,%0A%09%09body: %7B%22Command%22:'pause'%7D
 %0A%09%7D)
@@ -1058,36 +1058,8 @@
 get'
-,%0A%09%09body: %7B%22Command%22:'skip'%7D
 %0A%09%7D)
@@ -1351,34 +1351,8 @@
 get'
-,%0A%09%09body: %7B%22Command%22:'up'%7D
 %0A%09%7D)
@@ -1648,36 +1648,8 @@
 get'
-,%0A%09%09body: %7B%22Command%22:'down'%7D
 %0A%09%7D)
@@ -2192,16 +2192,16 @@
  'get',%0A
+
 %09%09type: 
@@ -2210,56 +2210,8 @@
 son'
-,%0A%09%09body: JSON.stringify(%7B%22Command%22:cmd.action%7D)
 %0A%09%7D)

remove body from get requests... Stupid Nathan...