/* 
-------------------------------------------------------------------------
	
	To execute scripts with the new version of jQuery, use
	'$jq' instead of the '$' standard.
	
	Ex: $jq('#my-div').function();
	
-------------------------------------------------------------------------
*/


/*
  redefine the postUpdateAnimations action to simply callback and return.  Disables the animation entirely.
  removes the need to hide/show the division while the uniform process is working
*/
Drupal.HierarchicalSelect.postUpdateAnimations = function(hsid, updateType, lastUnchanged, callback) {  
  callback();
  return;
}

function updateBoxes(){
  $('#edit-child-test1-wrapper').hide();
  $('#edit-child-test2-wrapper').hide();
  
  if($('#edit-filter-hierarchical-select-selects-2').length == 0){
    $('#edit-child-test2').show();  
    $('#edit-child-test2-wrapper').show();  
  }
  
  if($('#edit-filter-hierarchical-select-selects-1').length == 0){
    $('#edit-child-test1').show();
    $('#edit-child-test1-wrapper').show();
  }
  
  
};

$(function() {
		// Add preloader to search form button
		$('input#edit-apply').click(function() {
			$(this).val('');
			$(this).css("backgroundPosition", "0 -60px");
		});
		
		// Call to alert
		$('.sign-ins a.button-delete').click(function() {
			var confirmation = confirm('Are you sure you would like to remove this user from your account, this action cannot be undone? ');
			
			return confirmation;
		});
    
    // Call to jQuery Fancybox
    $jq("body.products #main-content .content .view-solr-search-results table.views-table td.views-field-field-image-cache-fid a").fancybox({
      'opacity': true,
      'overlayShow': true,
      'transitionIn': 'elastic',
      'transitionOut': 'elastic'
    });
    
    $jq("a.imagecache-uc_thumbnail").fancybox({
      'opacity': true,
      'overlayShow': true,
      'transitionIn': 'elastic',
      'transitionOut': 'elastic'
    });
    
    $jq(".product-image a[rel=gallery]").fancybox({
      'transitionIn': 'elastic',
      'transitionOut': 'elastic',
      'titlePosition': 'over',
      'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
          return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
      }
    });
    
    // Call to jQuery tooltip
    $jq(".product-details #part-numbers").tooltip({
      effect: 'slide',
      offset: [15, 0],
      relative: true
    });
    $jq(".view-solr-search-results .views-table .views-field-title .tooltip_part_number a").tooltip({
      effect: 'slide',
      offset: [15, 0],
      relative: true
    });
		
    $jq(".view-solr-search-results .views-table .views-field-field-product-description2-value .tooltip_part_extended a").tooltip({
      effect: 'slide',
			direction: 'right',
			position: 'center right',
      offset: [-7, -9],
      relative: true
    });
    
    //Update boxes on load
    updateBoxes();
    //Update the selects to use uniform
    $jq("#pb-search-block-form select").uniform();
    $jq("#pb-search-block-form #edit-title").uniform();
    
    $jq('#pb-auth-request-password-form input[type=password]').uniform();
    
    //$jq('#order-history #filter-by select').uniform();
    
    $jq('#pb-search-block-form #edit-title').click(function (){
      $jq(this).val('');      
    });
    
    //Hide the boxes just before updating the select dropdowns
    $('.hierarchical-select-wrapper').bind('before-update-hierarchical-select', function() {
      $('#edit-child-test2-wrapper').hide();
      $('#edit-child-test1-wrapper').hide();
    });
    
    //Update the boxes when a select is changed
    $('.hierarchical-select-wrapper').bind('change-hierarchical-select', function (){
      updateBoxes();
      //Update the selects to use uniform
      $jq("#pb-search-block-form .selects select").uniform();
    });

});


