// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


// function wireUpDisplayTextboxes() {
//   var e1 = $j('input[Title]');
//   
//   e1.each(function (i) {
//     $j(this).attr('value', $(this).attr('title'));
//   });
//   
//   e1.focus(function () {
//     if ($j(this).attr('value') == $j(this).attr('title'))
//       $j(this).attr('value', '');
//   }).blur(function () {
//     if ($j(this).attr('value') == '')
//       $j(this).attr('value', $j(this).attr('title'));
//   })
// }
var counter_options = "";

$j(document).ready(function(){
	
	// Functions defined by psd2html in jquery.main.js
	initTabs();
	// wireUpDisplayTextboxes();
	
	// GearSlash functions.
	var new_order_element = $j("#new_order");
	
	$j('div#invite-login a').click(function () {
	  $j('div#customer-login').slideToggle();
	});
	
	$j('form.ajax').jaxy();
	
	$j('select#order_shipping_method').change(function () {
	  $j.post("/cart/update_shipping", $j("form#new_order :select[value]").serialize(), null, "script");
	  return false;
	});

	$j("input#order_shipping_is_different").click(function () {
	  $j("input#order_ship_to_first_name").val($j("input#order_bill_to_first_name").val());
	  $j("input#order_ship_to_last_name").val($j("input#order_bill_to_last_name").val());
		$j("div#shipping-address").toggle();
	});
  
  if ($j('input#order_shipping_is_different').is(":checked")) {
    $j("div#shipping-address").css("display", "block");
  }
	
	$j(".title-order select").change(function () {
	  $j.post($j("form#new_order").attr("action"), $j("form#new_order :select[value]").serialize(), null, "script");
	  return false;
	});

	$j("div.inner-vote2").submitOnClick();
		
	var current_time = new Date();
  $j('li.time').counter(counter_options);
	
	// Set up jquery.lightbox
	$j('a.lightview').lightBox();
	
	// Preload image
	$j('').attr("src", "images/submit_order_off.gif");
      
  // Adding the image change to the above submit handler doesn't swap images. Not sure why.
  $j('form#new_order').submit(function () {
    $j('form#new_order div.submit-box input').attr('src', 'images/submit_order_off.gif');
    $j('form#new_order div.submit-box input').attr('disabled', 'disabled');
});
  
  // Tooltips for sales
  // $j('.general-vote2').tooltip({
  //   track: true,
  //   delay: 0,
  //   opacity: 1
  // });
  
  $j('.general-vote2').mouseenter(function () {
    $j(this).siblings('.product-info-hover').slideDown();
  });
  
  $j('.general-vote2').mouseleave(function () {
    $j(this).siblings('.product-info-hover').slideUp();
  });
    
});