    $(function () {

        var step1Sel = $('#step1Select');
        var step2Sel = $('#step2Select');
        var step3Sel = $('#step3Select');
        var criteria = new Array();  

			$.fn.setDefault = function () {
        $('#results').hide();	
        $('#results').html("");
        $.cookie('paintsel1', null);
        $('#step1Box select').find('option:first').attr('selected', 'selected');

        //fade/disable boxes
				$('#step2Box, #step3Box').animate({opacity: "0.1"});
				$("#step2Box select").attr("disabled", "disabled");	   
				$("#step3Box select").attr("disabled", "disabled");	   
				$('#paintTypes').css("display","none");

				
				//bug fix for ie
				if (jQuery.browser.msie) {
						$('#step1Box').css({ backgroundColor:"#f9f9f9"});
						$('#step2Box').css({ backgroundColor:"#f9f9f9"});
						$('#step3Box').css({ backgroundColor:"#f9f9f9"});
						$('#results').css({ backgroundColor:"#f9f9f9"});
				}						
			}        
			
			$.fn.loadPast = function () {
//				alert('loading');
        var sels1 = $.cookie('paintsel1');
        var sels2 = $.cookie('paintsel2');
        var sels3 = $.cookie('paintsel3');
     		//query the database for matching props 
     		 $.post("/paintguide/paintGuide.php", {step1: sels1, step2: sels2, step3: sels3, queryGo: true}, function(data){
          if(data.length >0) {
              $('#results').html(data);
      				$('#results').slideDown(600);
      				//scroll pane
      				var originalSizes = new Array();
								$('#pane5').jScrollHorizontalPane({scrollbarHeight:20, scrollbarMargin:10,showArrows:false});

          	}
         });        				
			} 			
								
				
				
				//fade/enable next box upon click        
				step1Sel.click(function(){
						$('#step2Box').animate({opacity: "1"});           
						$("#step2Box select").removeAttr("disabled");	
					});        			

				step2Sel.click(function(){
						$('#step3Box').animate({opacity: "1"});           
						$("#step3Box select").removeAttr("disabled");	
						$('#paintTypes').css("display","block");
						//$('#aluminumdeepv-hullfishingboatswithmotorhood').css("display","block");
						
					});
	
				
				$('#resetAll a').click(function(){
   				$().setDefault();
				}); 		
					
				$("#step3Box select").change( function() {
					
					if($(this).children("option:selected").attr("value") != "-"){
					 //get the values select for each box
					 $("select").each(function(i) {
						 criteria[i] = $(this).children("option:selected").attr("value");
     			 });

     			 //query the database for matching props 
     			 $.post("/paintguide/paintGuide.php", {step1: criteria[0], step2: criteria[1], step3: criteria[2], queryGo: true}, function(data){
            if(data.length >0) {
                $('#results').html(data);
    						$('#results').slideDown(600);
                $.cookie('paintsel1', criteria[0]);
                $.cookie('paintsel2', criteria[1]);
                $.cookie('paintsel3', criteria[2]);
                var originalSizes = new Array();
								$('#pane5').jScrollHorizontalPane({scrollbarHeight:20, scrollbarMargin:10,showArrows:false});

          	}
           });
          }
          
				});
				
				//tooltips    
        
        // note that we're assigning in reverse order
        // to allow the chaining change trigger to work				
        
        step2Sel.selectChain({
            target: step3Sel,
            url: '/paintguide/paintGuide.php',
            data: { ajax: true}             
        }).trigger('change');         

        step1Sel.selectChain({
            target: step2Sel,
            url: '/paintguide/paintGuide.php',
            data: { ajax: true}
        }).trigger('change');    
        
        if($.cookie('paintsel1')==null){
				  $().setDefault();			
				}else{
				  $().loadPast();					
		     					
				}		

		return false;
    });