jQuery(document).ready(function() {
  jQuery('.round').corner();
  jQuery('.round-top').corner('top');
  jQuery('.round-small-top').corner('top');
  jQuery('.round-small, .pagination a, .pagination span, .flash, .edit-link').corner('3px');
  jQuery('#search-button').hover(
    function() {
      $(this).attr({ src : '/images/search-over.gif'});
    },
    function() {
      $(this).attr({ src : '/images/search-out.gif'});
		});
		jQuery("#query").labelify({ labelledClass: "labelHighlight" });
});

function beforeSubmit(submitButton) {
  submitButton.attr("disabled", "disabled")
  submitButton.addClass("loader");
}

function success() {}

if (typeof punkter == "undefined") {
  punkter = new Object();
}

punkter.round = {
  init:function(selector, size) {
    jQuery(selector).corner(size);
  }
};

/* stars */
punkter.stars = {
  config: {
    split: 2
  },
  init:function(wraper, exConfig, degree) {
    wraper.stars(jQuery.extend(punkter.stars.config, exConfig));
    wraper.stars("select", degree);
  }
};

/* rating */
punkter.rating = {
  config: {},
  stars:function(wraper) {
    wraper.stars();
  },
  voute:function(form, target, submitButton) {
    form.submit(function() {
      var options = {
        target: target,
        beforeSubmit: beforeSubmit(submitButton)
      };
      jQuery(this).ajaxSubmit(options);
      return false;
    });
  },
  stars_view:function(wraper, exConfig, degree) {
    wraper.stars(exConfig);
    wraper.stars("select", degree);
  }
};

/* channel */
punkter.channel = {
  config: {},
  open:function(form, target, submitButton) {
    jQuery('.round-small').corner('3px');
    form.submit(function() {
      var options = {
        target: target,
        beforeSubmit: beforeSubmit(submitButton),
        success: function(responseText, statusText) {
          var res = responseText.split(":");
          if(res[0] == "OK") {
            tb_remove();
            jQuery("#rating-index > li[id='rating-" + res[1] + "']").remove();
          }
        }
      };
      jQuery(this).ajaxSubmit(options);
      return false;
    });
  }
}

/* tabs */
punkter.tabs = {
  config: {},
  init:function(wraper, select) {
    var $tabs = wraper.tabs();
	$tabs.tabs('select', select);
	$('.add-rating-repeat').click(function() {
        $tabs.tabs('select', 2);
        return false;
    });
    wraper.children("ul").removeClass("ui-corner-all");
    wraper.children("ul").addClass("ui-corner-top");
  }
};

punkter.element = {
  config: {},
  descEdit:function(wraper, url) {
    wraper.editable(url, {
      indicator: 'Zapisywanie...',
      type: 'textarea',
      submitdata: { _method: 'put' },
      submit: 'Zapisz',
      cancel: 'Anuluj',
      tooltip: 'Kliknij aby edytować'
    });
  },
  tagsEdit:function(wraper, url) {
    wraper.editable(url, {
      inicator: 'Zapisywanie...',
      submitdata: { _method: 'put' },
      submit: 'Zapisz',
      cancel: 'Anuluj',
      tooltip: 'Kliknij aby edytować'
    });
  },
  editor:function(textArea) {
      nicEditors.findEditor(textArea);
  }
};

punkter.selectInput = {
	init:function(selector) {
		jQuery(selector).click(function() {
			this.select();
		});
	}
};

/* end */