function quantityUp() {
  $('quantity').value = parseInt($('quantity').value) + 1;
}

function quantityDown() {
  if (parseInt($('quantity').value) > 1) {
    $('quantity').value = parseInt($('quantity').value) - 1;
  }
}

function checkSwitch() {
  if($('ccType').value == 'switch') {
    Effect.Appear('ccSwitch');
  } else {
    Effect.Fade('ccSwitch');
  }
}

function checkAgree() {
  if($('agree').checked == true) {
    $('submit').disabled = false;
  } else {
    $('submit').disabled = true;
  }
}

// function $(element) {
//   if (arguments.length > 1) {
//     for (var i = 0, elements = [], length = arguments.length; i < length; i++) {
//       elements.push($(arguments[i]));
//     }
//     return elements;
//   }
//   if (typeof(element) == 'string') {
//     element = document.getElementById(element);
//   }
//   return element;
// }

function quantityForm(value, formId) {
  $('itemQuantity' + formId).value = value;
  $('formQuantity' + formId).submit();
}


window.onload = function() {
  qs = $('quickSearch');
  qs.onblur = function() {
    if (this.value == '') {
      this.value = 'Search...';
    }
  }
  qs.onfocus = function() {
    if (this.value == 'Search...') {
      this.value = '';
    }
  }
}

function runQuickSearch() {
  var s = $('quickSearch').value;
  $('suggest').empty();
  
  if (s.length >= 3) {
    // we need 3 characters to mysql search
    new Request.HTML({
      url: '/suggest/?q=' + escape(s),
      method: 'get',
      onRequest: function() {
        new Element('p').addClass('loading').appendText('Searching, please wait...').inject($('suggest'));
        showQuickSearch();
      },
      update: $('suggest')
    }).send();

  } else {
    new Element('p').appendText('Please enter 3 or more characters to search').inject($('suggest'));
    showQuickSearch();
  }
  
  return true;
}

function showQuickSearch() {
  $('suggest').setStyle('display', 'block');
  
  return false;
}

function hideQuickSearch() {
  window.setTimeout(function() {
    $('suggest').setStyle('display', 'none');
  }, 500);
  
  return false;
}

function changeImage(img, dir) {
  $('focusImg').src = "/dyn/"+dir+img;
  return true;
}

window.addEvent('domready', function() {
  $('quickSearch').addEvent('change', function() {
    runQuickSearch();
  });

  $('quickSearch').addEvent('keyup', function() {
    runQuickSearch();
  });

  $('quickSearch').addEvent('focus', function() {
    this.value = (this.value == 'Search...') ? '' : this.value;
    showQuickSearch();

    return true;
  });

  $('quickSearch').addEvent('blur', function() {
    this.value = (this.value == '') ? 'Search...' : this.value;
    hideQuickSearch();

    return true;
  });
  
  SqueezeBox.assign($$('a.boxed]'), {
      parse: 'rel'
  });
  
});

