    $(function () {

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

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

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

				
				//bug fix for ie
        
				if (jQuery.browser.msie) {
						$('#step1Box').css({ background:"#f9f9f9"});
						$('#step2Box').css({ background:"#f9f9f9"});
						$('#step3Box').css({ background:"#f9f9f9"});
						$('#step4Box').css({ background:"#f9f9f9"});						
						$('#results').css({ background:"#f9f9f9"});
				}						
        
			}        
			
			$.fn.loadPast = function () {
        var sels1 = $.cookie('biminisel1');
        var sels2 = $.cookie('biminisel2');
        var sels3 = $.cookie('biminisel3');
        var sels4 = $.cookie('biminisel4');
     		//query the database for matching props 
     		 $.post("/biminiguide/biminiGuide.php", {step1: sels1, step2: sels2, step3: sels3, step4: sels4, queryGo: true}, function(data){
          if(data.length >0) {
              $('#results').html(data);
      				$('#results').slideDown(600);
              $("a[rel='lgView']").colorbox({transition:"fade"});
          	}
         });        				
			} 			
								
				
				
				//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");			
					});

				step3Sel.click(function(){
						$('#step4Box').animate({opacity: "1"});           
						$("#step4Box select").removeAttr("disabled");			
					});
	
				
				$('#resetAll a').click(function(){
   				$().setDefault();
				}); 		
					
				$("#step4Box 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 items 
     			 $.post("/biminiguide/biminiGuide.php", {step1: criteria[0], step2: criteria[1], step3: criteria[2], step4: criteria[3], queryGo: true}, function(data){
            if(data.length >0) {
                $('#results').html(data);
                $("a[rel='lgView']").colorbox({transition:"fade"});
                $('#results').slideDown(600);
                $.cookie('biminisel1', criteria[0]);
                $.cookie('biminisel2', criteria[1]);
                $.cookie('biminisel3', criteria[2]);
                $.cookie('biminisel4', criteria[3]);                
          	}
           });
          }
          
				});
        
        $(".selHolder select").click( function() {
						$('#results').html(""); 
				});  
				
				//tooltips    
        
        // note that we're assigning in reverse order
        // to allow the chaining change trigger to work				
        
        step3Sel.selectChain({
            target: step4Sel,
            url: '/biminiguide/biminiGuide.php',
            data: { ajax: true}             
        }).trigger('change');         

        step2Sel.selectChain({
            target: step3Sel,
            url: '/biminiguide/biminiGuide.php',
            data: { ajax: true}             
        }).trigger('change');         

        step1Sel.selectChain({
            target: step2Sel,
            url: '/biminiguide/biminiGuide.php',
            data: { ajax: true}
        }).trigger('change');    
        


		return false;
    });
    
    
    $(document).ready(function(){
        if($.cookie('biminisel1')==null){
				  $().setDefault();
          return false;
				}else{
				  $().loadPast();					
		     	return false;
				}		
    });
