$(document).ready(function(){

  $('.showhide:checked').filter(function () {
    $($(this).attr('title')).hide(800);
  });

  $('.showhide').change(function(){
    if ($(this).attr('checked'))
      $($(this).attr('title')).hide(800);
    else
      $($(this).attr('title')).show(800);
  });

  $('#cl_ct_all').change(function(){
    if ($(this).attr('checked')){
      $('#cl_fs_html').show(800);
      $('#cl_fs_xml').show(800);
    }else{
      if ($('#cl_ct_html').attr('checked')){
        $('#cl_fs_html').show(800);
      }else{
        $('#cl_fs_html').hide(800);
      }
      if ($('#cl_ct_xml').attr('checked')){
        $('#cl_fs_xml').show(800);
      }else{
        $('#cl_fs_xml').hide(800);
      }
    }
  });

  $('#cl_ct_html').change(function(){
    if ($('#cl_ct_html').attr('checked')){
      $('#cl_fs_html').show(800);
    }else{
      $('#cl_fs_html').hide(800);
    }
  });

  $('#cl_ct_xml').change(function(){
    if ($('#cl_ct_xml').attr('checked')){
      $('#cl_fs_xml').show(800);
    }else{
      $('#cl_fs_xml').hide(800);
    }
  });
  $('textarea.string-val').each(function(){
    var val = $(this).val();
    var lines = val.split("\n");
    var cols = 0;
    for (i in lines){
      if (cols < lines[i].length) cols = lines[i].length;
    }
    $(this).attr('cols',cols+1).css({overflow:'hidden',whiteSpace:'pre',margin:0});
    if (lines.length < 3){
      $(this).height((lines.length==1)?'1.4em':'2.6em');
    }else{
      $(this).height('').attr('rows',lines.length);
    }
  }).keyup(function(){
    var val = $(this).val();
    var lines = val.split("\n");
    var cols = 0;
    for (i in lines){
      if (cols < lines[i].length) cols = lines[i].length;
    }
    $(this).attr('cols',cols+1);
    if (lines.length < 3){
      $(this).height((lines.length==1)?'1.4em':'2.6em');
    }else{
      $(this).height('').attr('rows',lines.length);
    }
  });
  $('input.int-val, input.float-val, input.array-val, input.object-val').css('font-family','monospace');
  
  var dd_type = '<select class="var-type">'
   +'<optgroup label="Scalar">'
   +'<option value="bool">Boolean</option>'
   +'<option value="int">Integer</option>'
   +'<option value="float">Float</option>'
   +'<option value="string">String</option>'
   +'</optgroup><optgroup label="Compound">'
   +'<option value="array">Array</option>'
   +'<option value="object">Object</option>'
   +'</optgroup><optgroup label="Special">'
   +'<option value="null">NULL</option>'
   +'</optgroup></select>';
  
  var dd_ktype = '<select class="var-type">'
   +'<option value="int">Integer</option>'
   +'<option value="string">String</option>'
   +'</select>';
  
  $('.el-add').click(function(e){
	var isarr = $(this).hasClass('is-array');
	var wspace = $(this).parent().get(0).html()
	 .match(/\s+<a[^>]*>add child/gi).toString()
	 .match(/\s+/gi).toString();
	if (isarr){
		//$('')
		//alert('is array');
	}else{
		//alert('is object');
	}
	//$(this).prev('span.el').clone().insertAfter($(this).prev('span.el'));
    e.preventDefault();
  });
  $('.el-del').hover(function(){
    var elname = $(this).parent('span').fadeTo(0,0.2);
  },function(){
    var elname = $(this).parent('span').fadeTo(0,1);
  }).click(function(e){
    var elname = $(this).parent('span').slideUp(500,function(){
      $(this).remove();
    });
    e.preventDefault();
  });
  //$('.var-type').width('3em');

});
