function log(text) {
	if (typeof console != 'undefined') {
		console.log(text);
	}
}

function showRadius(v) {
	document.getElementById("radiusimg").src = '/gfx/rekenmodule/' + v + '.gif';
}

function showHoek(v) {
	document.getElementById("hoekimg").src = '/gfx/rekenmodule/' + v + 'graden.gif';
}


$(document).ready(function() {
	$(".imradio").click(function() {
		v = $(this).attr("rel");
		n = $(this).attr("names");
		
		$("a." + n).find("img").attr("src", "/gfx/form/radio.gif");
		
		if($("#" + v).attr("checked")) {
			$("#" + v).attr("checked", false);
		} else {
			$("#" + v).attr("checked", true);
			$(this).find("img").attr("src", "/gfx/form/radioc.gif");
		}
		
		if(n == "waterverbruik" || n == "gasverbruik") {
			v = $("#" + v).val();
			$("#" + n + "_div_ja").hide();
			$("#" + n + "_div_nee").hide();
			$("#" + n + "_div_" + v).show();
		}
		if(n == "zonnewarmte"){
			v = $("#" + v).val();
			if(v == "water") {
				$("#water_div_ja").hide();
			} else {
				$("#water_div_ja").show();	
			}
				
		}
		
		$('#pane').jScrollPane();
	});
	

	$('.degreebox').live('click', function(e) {
		var locX = Math.round(e.pageX - $(this).offset().left);
		var locY = Math.round(e.pageY - $(this).offset().top);
	    a = locX;
	    b = ((locY - 100) * -1);
	    c = (a*a) + (b*b);
	    sqrtvalue = Math.round(Math.sqrt(c));

		cosval = (b / a)
	    degrees = Math.atan( cosval) * (180 / Math.PI);
		degrees = Math.round( (degrees / 10) );
		degrees = degrees *10;
		if (degrees < 20) {
			degrees = 20;	
		}
	
	    r = $(this).attr("rel");
		$("#" + r).val(degrees);
		
		
		
		//doRotateHoek(this, (degrees), (-degrees) );
		doRotateHoek(this, (90 - degrees), 0);
	});
	
	function doRotateHoek(who, sp, whence) {
		if($(who).find("img").length > 0) {
			bl = $(who).find("img");
		} else {
			bl = $(who).find("canvas");
		}
		$(bl).rotate(sp, (90-whence));
	}
	
	
	$(".radiusbox").click(function() {
		rot = doRotate(this, 45);
		r = $(this).attr("rel");
		
		val = '';
		
		switch(rot) {
			case 0: case null:
				val = 'oost';
			break;
			case 45:
				val = 'zuid-oost';
			break;
			case 90:
				val = 'zuid';
			break;
			case 135:
				val = 'zuid-west';
			break;
			case 180:
				rot = doRotate(this, 180);
				val = 'oost';
		}
		
		$("#" + r).val(val);
	});

	
	
	
	
	var wh = 100;
	function doRotate(who, sp) {
		if($(who).find("img").length > 0) {
			bl = $(who).find("img");
		} else {
			bl = $(who).find("canvas");
		}
		$(bl).rotate(sp);
		bl = $(who).find("canvas");
		w = $(bl).width();
		
		tmpw = Math.ceil(((wh-w)/2));
		
		$(bl).css("left", tmpw);
		$(bl).css("top", tmpw);
		return $(bl).attr("angle");
	}
});

function getForm(what) {
	$("#thisisaform").html("");
	$.get(document.location.pathname, {form_id: $(what).val()}, function(data){
	   f = $("#thisisaform", data).html();
	   $("#thisisaform").html(f);
	   
	   $('#pane').jScrollPane();
	 });
	 
	
}
