$(function() {
	
	$(".field").focus(function () {      
		$(this).addClass('focus');
	});

	$(".field").blur(function () {      
		$(this).removeClass('focus');
	});

	$("input.submit").hover(function () {
		$(this).addClass('buton');
	}, function () {
		$(this).removeClass('buton');
	});

	$('img.tmb').hover(function () {
		  $(this).addClass('tmb2');
	}, function () {
		  if($('div#viewit img').attr('id') != $(this).attr('id')){
		  $(this).removeClass('tmb2');
		  }
	});

	$.listen('click','.tmb',function(){
		
		$('img.tmb2').removeClass('tmb2');
		
		$.get("/image.php", { id: $(this).attr('id') },
		function(data){       
		   $("div#viewit").html(data).show("fast");        
		});

		$(this).addClass('tmb2');

	});


	function makeSublist(parent,child){
		$("body").append("<select style='display:none' id='"+parent+child+"'></select>");
		$('#'+parent+child).html($("#"+child+" option"));
		
		var parentValue = $('#'+parent).attr('value');
		$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());		
		
		$('#'+parent).change(
		  function()
		  {
			var parentValue = $('#'+parent).attr('value');
			$('#'+child).html($("#"+parent+child+" .sub_"+parentValue).clone());
		  }
		);
	}

    makeSublist("type","period");
	makeSublist("type","starting_payment");
	makeSublist("type","person_type");

});