$(document).ready(function(){
	$.ajaxSetup({
		cache: false
	});
	
	$('#primaryNav li').hover(function(){
		$(this).toggleClass('hover').find('ul').toggle();
	}, function(){
		$(this).toggleClass('hover').find('ul').toggle();
	});
	
	$("#searchFuses").submit(function(){
		var str = $("#basicSearch").val();
		if(str.length <= 2){
			alert('Your search must be at least 3 characters');
			return false;
		}
		return true;
	});
	
	$("#basicSearch").focus(function() {
		if($(this).val() == $(this).attr('value')){
			$(this).val('');
		}
	});
	$("#basicSearch").blur(function() {
		if($(this).val() == ''){
			$(this).val($(this).attr('title'));
		}
	});
	
	/* !Multi-step forms. ============================== */
	$('.multi-step').multiStep();
	
	$('.contact-catch').hover(function(){
		var val = 'Contact us for more information on '+$(this).html()+' fuses.';
		$(this).append('<span>'+val+'</span>');
	}, function(){
		$(this).children('span').remove();
	});
	//$('.contact-catch').click(function(){return false;});
	
	/* !Contact Locations Dropdown ============================== */
	$('#contact-locations').click(function(){
		$('#location-list').slideToggle(100);
		return false;
	});
	$('#location-list').hover(false, function(){
		$('#location-list').slideToggle(100);
	});
/*
	$(function() {
		var zIndexNumber = 1000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	});	
*/
	

	/** Cart functionality  
	 ******************************/
	 
	/* ==== ADD TO QUOTE         ============================== */
	$('.addToQuoteForm').submit(function(){
		var quantity = $(this).children(".quantity").val();
		var action = $(this).attr('action');
		var location = action+'/'+quantity+'/';
		
		$("#buildAQuote").prepend('<span class="loading">&nbsp;</span>');
		$('.loading').css('opacity', 0);
		$('.loading').animate({'opacity': .5}, 'fast');
		$.ajax({
			url: location,
			cache: false,
			dataType: 'html',
			success: function(data){
				$('.loading').animate({'opacity': 0}, 'slow');
				$("#buildAQuote").html(data);
			}
		});
		
		$(this).effect('transfer',{ to: ".cart"},500);
		$('.ui-effects-transfer').css('opacity', .7);
		//$(this).children(".quantity").val('1');
		$(this).children(".addToQuote").val("Added "+quantity);
		return false;
	});
	
	/* ==== REMOVE FROM QUOTE         ============================== */
	$(".cart .remove").live('click', function(){
		var location = $(this).attr('href')+'/';
		$("#buildAQuote").prepend('<span class="loading">&nbsp;</span>');
		$('.loading').css('opacity', .5);
		$.ajax({
			url: location,
			cache: false,
			dataType: 'html',
			success: function(data){
				$("#buildAQuote").html(data);
			}
		});
		return false;
	});
	
	/* ==== CLEAR QUOTE         ============================== */
	$(".cart #emptyQuote").live('click', function(){
		var location = $(this).attr('href')+'/';
		$("#buildAQuote").prepend('<span class="loading">&nbsp;</span>');
		$("#buildAQuote .loading").css('opacity', .5);
		$.ajax({
			url: location,
			cache: false,
			dataType: 'html',
			success: function(data){
				$("#buildAQuote").html(data);
			}
		});
		return false;
	});
});