<?xml version="1.0" encoding="utf-8"?>
<program xmlns="http://www.kinoma.com/kpr/1">

    <script>
        <![CDATA[
			var THEME = require('themes/flat/theme');
			var SLIDERS = require('controls/sliders');
			var labelStyle = new Style( {font: "bold 40px", color: "white" } );
			var BUTTONS = require('controls/buttons');
			
			var greyS = new Skin({fill:"black"});
			var whiteS = new Skin({fill:"white"});
			
			var labelCon = new Container({
				left:0, right:500, top:0, bottom:500,
				contents:[
					new Label({left:0, right:0, height: 40, string:"hello", style: labelStyle})
				]
			});
			
			var labelCon2 = new Container({
				left:500, right:0, top:0, bottom:500,
				contents:[
					new Label({left:0, right:0, height: 40, string:"hello", style: labelStyle})
				]
			});
			
			var myRadioGroup2 = BUTTONS.RadioGroup.template(function($){ return{
				top:50, bottom:50, left:50, right:50,
				behavior: Object.create(BUTTONS.RadioGroupBehavior.prototype, {
				        getSelectedName: { value: function(){
           					 if ("selectedName" in this) return this.selectedName; 
        				}},
					onRadioButtonSelected: { value: function(buttonName){
						//trace("Radio button with name " + buttonName + " was selected.\n");
						buttonthing2 = buttonName;
						labelCon2[0].string = test();
				}}})
			}});
			
			var myRadioGroup = BUTTONS.RadioGroup.template(function($){ return{
				top:50, bottom:50, left:1150, right:50,
				behavior: Object.create(BUTTONS.RadioGroupBehavior.prototype, {
					onRadioButtonSelected: { value: function(buttonName){
						//trace("Radio sdfds with name " + buttonName + " was selected.\n");
						buttonthing1 = buttonName;
						labelCon2[0].string = test();
				}}})
			}});

			var mySlider = SLIDERS.HorizontalSlider.template(function($){ return{
				height:20, left:50, right:50,
				behavior: Object.create(SLIDERS.HorizontalSliderBehavior.prototype, {
					onValueChanged: { value: function(container){
						SLIDERS.HorizontalSliderBehavior.prototype.onValueChanged.call(this, container);
						//trace("Value is: " + this.data.value + "\n");
						labelCon[0].string = this.data.value;
						labelCon2[0].string = test();
				}}})
			}});
			
			
			
			function test() {
				original = parseFloat(labelCon[0].string)
				if (buttonthing2 == "Farenheit" && buttonthing1 == "Celcius") {
					return ((original-32)*(5/9)); 
					}
				else if (buttonthing2 == "Farenheit" && buttonthing1 == "Kelvin") {
					return ((original+459.67)*(5/9));
					}
				else if (buttonthing2 == "Celcius" && buttonthing1 == "Farenheit") {
					return ((original*(9/5))+32);
					}
				else if (buttonthing2 == "Celcius" && buttonthing1 == "Kelvin") {
					return (original+273.15);
					}
				else if (buttonthing2 == "Kelvin" && buttonthing1 == "Celcius") {
					return (original-273.15);
					}
				else if (buttonthing2 == "Kelvin" && buttonthing1 == "Farenheit") {
					return ((original*(9/5))-459.67);
					}
				else {
					return labelCon[0].string;
					}
			}
			
						
			var buttonthing1 = "";
			var buttonthing2 = "";
			
			var slider = new mySlider({ min:-100, max:100, value:1,  });
			var radioGroup = new myRadioGroup({ buttonNames: "Farenheit,Celcius,Kelvin" });
			var radioGroup2 = new myRadioGroup2({ buttonNames: "Farenheit,Celcius,Kelvin" });	
			var mainCon = new Container({left:0, right:0, top:0, bottom:0, skin: greyS});
			application.add(mainCon);
			application.add(labelCon);
			application.add(labelCon2);
			mainCon.add(radioGroup2);
			mainCon.add(radioGroup);
			mainCon.add(slider);
			

        ]]>
    </script>
</program>