if(window.location.href.match(/\?reload/)) {
	window.location.href = 'http://purosol.com/products/checkout/'; // hack to fix wp ecom not showing reset of payment page, fail   
}
  
Cufon.replace('h1, blockquote, #info_boxes h3, .shoppingcart h3');

/*
* Input field labelizer.
* Makes form elements' value attribute act as a label 
* Ronnie Miller (me@ronniemlr.com)
* http://ronniemlr.com/jquery/labalize/
*/
(function($) {
$.fn.labelize = function() {
  return this.each(function() {
    elements = $(this).is('form') ? $(this).find('input, textarea') : $(this);
    elements.each(function() {
      $(this)
        .data('default', $(this).val())
        .focus(function() { if($(this).val() == $(this).data('default')) $(this).val(''); })
        .blur(function()  { if($(this).val() == '') $(this).val($(this).data('default')); });
    });
  });
}
})(jQuery);

function emailLink() {
  var argv = emailLink.arguments;
  return '<a href="mailto:'+argv[0]+'@'+argv[1]+'.'+argv[2]+'">'+((argv[3]) ? argv[3] : argv[0]+'@'+argv[1]+'.'+argv[2])+'</a>';
}

$(function() {
  // Homepage slider
  if($('#slider').length) {
    $('#slider').nivoSlider({
      effect: 'fade',
      controlNav: false,
      directionNavHide: false,
      pauseTime: 5000
    });
  }

  // Feature description boxes
  $('.features a').click(function(e) {
    e.preventDefault();
    $(this).parent().siblings().find('a').removeClass('active');
    klass = $(this).addClass('active').parent().attr('class');
    $('#descriptions div').hide();
    $('#descriptions div.'+klass).show();
    return false;
  });

  // FAQ toggling
  if($('.question').length) {
    $('.question').click(function(e) {
      e.preventDefault();
      $(this).parent().next().toggle();
    });
  }

  // Contact form
  $('#contactform').labelize();

  // Product information tabs
  if($('#product_tabs').length) {
    $('#product_tabs a').click(function(e) {
      e.preventDefault();

      class_name = $(this).attr('class');
      $('#product_content').find('div').hide();
      $('#product_content .'+class_name).show();
      $('#product_tabs li').removeClass('active')
      $('#product_tabs .'+class_name).parent().addClass('active');

      return false;
    });
  }
  
  // Product page tabs
  if($('#subcategory_tabs').length) {
    $('.subcategory_container').hide().eq(0).show();
    $('#subcategory_tabs a').click(function(e) {
      e.preventDefault();

      class_name = $(this).attr('class');
      $('.subcategory_container').hide();
      $('.wpsc_default_product_list .'+class_name).show();
      $('#subcategory_tabs li').removeClass('active');
      $('#subcategory_tabs .'+class_name).parent().addClass('active');

      return false;
    });
  }
  
  // Override / add behavior to add to cart button
  $('.wpsc_buy_button').click(function() {
    var button = $(this);
    setTimeout(function() { 
      id = button.attr('id').match(/\d+/)[0];
      $('body div.shoppingcart #product_'+id).animate({ backgroundColor: '#fffcbe' }, 500).delay(1000).animate({ backgroundColor: '#e5e6e8' }, 500);
      $.scrollTo('div.shoppingcart', 250);
    }, 100);
  });
  
  if(window.location.href.match(/checkout/)) {
  	if($('.wpsc_email_address').length > 0) return;
  
    $('.wpsc_shipping_quote_radio').mouseup(function() {
      setTimeout(function() { window.location.href = 'http://purosol.com/products/checkout/?reload'; }, 200);  
    });
    
    /*
    	if(!$.browser.msie) {
	      window.location.reload(); // hack to fix wp ecom not showing reset of payment page, fail 
	     } else {
				window.location.href = 'http://purosol.com/products/checkout/?reload'; // hack to fix wp ecom not showing reset of payment page, fail 
	     }
    });
    */
  }
  
  if(window.location.href.match(/transaction-results/)) {
    $('.shoppingcart').html('<p>Thank you for your purchase!</p>');
  }
});
