var scroll_to_top = function() {
  window.scrollTo(0, 0);
  return false;
}

// MySparkfly

var jump_to = function(el) {
  if(el[el.selectedIndex].value != "") {
    window.location.href = el[el.selectedIndex].value;
  }
}


/*
 * // spark_store/index
 * 
 * On the fly calculation of total and rounding up to 5.
 */

// Used to round up values to the nearest delta.
// 
var ensure_value_by_delta = function(el, delta) {
  if(arguments.length<2){var delta = 5;}
  var diff = parseInt(el.value) % delta;
  if(diff > 0){
    el.value = parseInt(el.value) + (delta - diff);
  };
}

// Updates the SparkBucks Store value and select boxes with the appropriate values.
// 
var spark_store_update_total_cost = function(el) {
  ensure_value_by_delta(el);
  ensure_value_by_delta($('quantity'), 500);
  $('quantity').value = parseInt(el.value) * 100;
  $('total_cost').update(el.value);
}

var update_total_sparkbucks = function(value, price, id) {
  var total_id = "total_sparkbucks";
  if(arguments.length>2 && id != undefined){total_id = total_id+"_for_"+id;}
  $(total_id).update(parseInt(value) * price);
}

var update_total_with_or_without_variations = function(quantity, id) {
  var item_id = "item_id";
  if(arguments.length>1){item_id = item_id+"_for_"+id;}
  var item = $(item_id);
  if(item.selectedIndex == undefined) {
    // single
    var price = parseInt(item.getAttribute('price'));
  } else {
    // variations
    var price = parseInt(item[item.selectedIndex].getAttribute('price'));
  }
  update_total_sparkbucks((price / 100), parseInt(quantity), id);
}

/* 
 * search / forms that need clearing
 *  -- clears values out of the form on click, utilizing the "alt" field
 *  as the default value to not clear user input
 *
 */
var clear_value_in_field = function(el)
{  
	if (el.value == el.alt) {
    el.value = "";  
  }
}


// toggles an element while toggling off others -- takes in:
// el: element to toggle on
// toggle_els:  elements to toggle off
//
var multiple_element_toggle = function(el, toggle_els)
{
  toggle_els.invoke('hide'); 
  el.show();  
}        
  
