function disableSaveButton() {
     $('input.save').attr('disabled', 'disabled')
}

function setDisplayOption(jElement) {
  if (jElement.attr('id') != 'displayTypeAll') {
      $('#genreSelectable').attr('checked', false);
  }
  if (jElement.attr('id') != 'displayTypeAuhtor') {
      $('#authorSelectable').attr('checked', false);
  }
  jElement.click();
}

$(document).ready(function() {

    var fbPicker = $.farbtastic('#colorpicker');
    var jInput = $( ":input" );
    jInput.focus(function(){disableSaveButton();})
            .change(function(){disableSaveButton();});
    $('input.txt.color')
        .each(function () {fbPicker.linkTo(this)})
        .focus(function() {fbPicker.linkTo(this)});
//    .focus(function() {fbPicker.linkTo(this)});
    $('input.preview').click(function(){
        $("p.note").attr('style','width:'+$("input[name=width]").val()+"px;");
    });

    $('input.reset').click(function(){
        $(this).parents("form")[0].reset();
        $('input.txt.color').each(function () {fbPicker.linkTo(this)});
    });
    $("p.note").attr('style','width:'+$("input[name=width]").val()+"px;");
    $("fieldset.collapsable legend").click(function() {
        var collabsable = $(this).parent("fieldset.collapsable");
        collabsable.toggleClass("collapsed");
    });

    $("div.tab-row a").click(function(event) {
       event.preventDefault();
       var tabRow  = $(this).parents("div.tab-row");
       tabRow.find("li").toggleClass("selected");
       tabRow.siblings("div.tab-panel").toggle(); 
    });

//   var zIndexNumber = 1000;
//    $('div').each(function() {
//		$(this).css('zIndex', zIndexNumber);
//		zIndexNumber -= 10;
//	});

    // widget code should have fixed position when scrolled
    var offset = $('#preview').offset();
//    $(window).scroll(function() {
//        if ($(this).scrollTop() > offset.top) {
//            $('#preview').css('position', "fixed");
//            $('#preview').css('left', $('#preview').css('left', offset.left+"px"));
//        } else {
//            $('#preview').css('left', "0px");
//            $('#preview').css('position', "relative");
//        }
//});

});
