// Here's how to overwrite default behaviour, using this for demos
Starboxes.rerate = true;
Starboxes.onRate = starClicked;

// This function is used by some demos onRate
function starClicked(element, info) {
  $('notify').down('.element').update(element.id);
  $('notify').down('.rated').update(info.rated.toFixed(2));
  $('notify').down('.average').update(info.average.toFixed(2));
  $('notify').down('.total').update(info.total);

  if (!$('notify').visible()) $('notify').visualEffect('blindDown', {duration: 0.2, queue: 
    { position: 'end', scope: 'notify' }});
}

function starboxThankYou(event) {
	/* Here's how to show a simple thank you message,
     Some demos use it using the custom event 'starbox:rated', but this could also be used on onRate.

     You could use the same technique to show error/success using the callback function in your Ajax.Request:
	 	 
	 new Ajax.Request('/your/save/url', parameters, {
       onComplete: function() { ... },
	   onFailure: function() { ... },
	   onLoading: function() { ... }
	 );
	 
     More on Ajax.Request: http://www.prototypejs.org/api/ajax/request
  */
  var indicator = event.element().down('.indicator');
  var restore = indicator.innerHTML;
  indicator.update('Thanks for voting');
  window.setTimeout(function() { indicator.update(restore) }, 2000);
}

function addDemoObservers() {
  // starbox demo related
  $('demo_10').observe('starbox:rated', starboxThankYou);
  $('demo_11').observe('starbox:rated', starboxThankYou);
  $('demo_12').observe('starbox:rated', starboxThankYou);
  $('demo_ghosting').observe('starbox:rated', starboxThankYou);
  $('demo_inverse_indicator_callback').observe('starbox:rated', starboxThankYou);
  
  // other
  Projects.createIdeas('starbox');
}
document.observe('dom:loaded', addDemoObservers);
