jQuery(document).ready(function()
    {

    var curstep = "step1";
        var prevstep = "";

    var step1 = "";
    var step1desc = "";

    var pantype = "";

    var step2 = "";
    var step2desc = "";
    var step2old = "";

    var step3 = "";
    var step3desc = "";
    var step3old = "";

    var step4 = "";

    var litre = '3star';

    $("#step3proceed").hide();

    $("#"+curstep+"content").slideDown();
    

  $(".stepbar").click(function () { 
      
    var clicked = $(this).attr("id");
        
    changesteps(clicked);
      
    });
  
  $("#hway-nav li").click(function () { 
  
    var clicked = $(this).attr("title");
    
    if(clicked=="back") return true;
        
    changesteps(clicked);
    
    return false;
      
    });
  

  $('.selectpan').click(function (){

    $.colorbox.close();


    step1 = $(this).attr("rel");

    step1desc = $(this).attr("title");
    pantype = $(this).attr("name");

    if (step1desc=="Kado Lux Back To Wall Pan"||step1desc=="Kado Lux Wall Hung Pan"||step1desc=="Axa Uno Back To Wall Pan"||step1desc=="Axa Uno Wall Hung Pan"||step1desc=="Ideal Standard Concept Back To Wall Pan"||step1desc=="Ideal Standard Acacia Back To Wall Pan"||step1desc=="Ideal Standard Acacia Wall Hung Pan"||step1desc=="Porcher Renso Wall Hung Pan"||step1desc=="Ideal Standard Active Wall Hung Pan"||step1desc=="Ideal Standard Active Back To Wall Pan"||step1desc=="Porcher Studio Back To Wall Pan"){ litre = '4star'; $('#access3').show();} else {$('#access3').hide();};

    //clear values
    $('.cisternaccess').removeClass("selected");
    $("#step2").html('');
    $("#step3").html('');
    step2 = '';
    step3 = '';

    $(".products div").removeClass("selected");
    $("#"+step1).addClass("selected");
    $("#step1").html(step1desc) ;
    
    
    $('input[name=step1]').val(step1);
    
    
    $("#step1proceed").slideDown();
  });
  

  
  $("#step1proceed").click(function () { 
    changesteps('step2');
  });
  
    
  $(".cisternaccess").click(function () {
    step2old = step2;
    step2 = $(this).attr("id");
    step2desc = $(this).attr("title");

    $(".cisternaccess").removeClass("selected");
    $("#"+step2).addClass("selected");

    $("#step2").html(step2desc) ;
    
  
    $('input[name=step2]').val(step2);   
    
    
    $("#step2proceed").slideDown();

  });    
    
  
  $("#step2proceed").click(function () { 

    changesteps('step3');

  });
  
  $(".buttons input").click(function () { 
    
    step3old = step3;
    step3 = $(this).attr("title");
    step3desc = $(this).attr("alt");
    var step3color = $(this).attr("value");

   
    
//    $('#values #step3buttons').val(step3desc);
    
      $('input[name=step3buttons]').val(step3desc);  
    
  //  $('#values #step3color').val(step3color);
    
      $('input[name=step3color]').val(step3color);  
    
    
    
      $("#step3proceed").slideDown();

 
  
      
    });
  
  $("#step3proceed").click(function () { 

    changesteps('step4');

  });
  
  
  $(".cisternchoice input").click(function () { 
    
  /*  step4old = step4;
    step4 = $(this).attr("value");
    step4desc = $(this).attr("id");

    $("#step4").html(step4desc) ;
    
    $("#printform").slideDown(); */
      
    });
  
  function changesteps(clicked){

    //Prevents skipping forward 2 steps
  
    var stepOld = parseInt(curstep.substr(4))+1;
    var stepNew = parseInt( clicked.substr(4) );
  
    if( stepOld <= stepNew && stepOld != stepNew ){ return false};

    prevstep = curstep;
    curstep = clicked;

    //constructs step 3 or 4
  
    if(clicked == 'step3') makestep3();
    if(clicked == 'step4') makestep4();

    $("#"+prevstep).removeClass("current");
    $("#"+curstep).addClass("current"); 
    $("#"+prevstep+"nav a").removeClass("current");
    $("#"+curstep+"nav a").addClass("current"); 
    
    $("#"+prevstep+"content").slideUp( 'slow', function () {  
      $("#"+curstep+"content").slideDown('slow'); 
      scrollWin();
    });
  
  };
  
  function makestep3(){
  
  $('.suiterow').attr('style', 'display:none;');
  $('#step3content #warning').hide();
    
  if(step1==''){$("#step3content #warning").show(); return;}

  switch(step2)
  {
    case 'access1':
      $("#mechanical").show();
      $("#pneumatic2").show(); 
      break;
    case 'access2':
      $("#pneumatic").show();
      break;
    case 'access3':
      $("#undercounter").show();
      break;

    default: 
      $("#step3content #warning").show();
      break;
    }; 
  
  };
  
  function makestep4(){
  
  $('.3star').hide();
  $('.4star').hide();
  $('.cisternchoice').attr('style', 'display:none;');
  $('#step4content #warning').hide();
  
  if(step1==''||step2==''||step3==''){$("#step4content #warning").show(); return;}

  //alert("Step1: " + step1 + ", Step2: " + step2 + ", Step3: " + step3 + ", Pan : " + pantype + ", Litre : " + litre); 

  if(step3=='Mechanical Buttons'){
    if(pantype=='backtowall'){ $("#step4content #mech-btw").show(); $("#step4content #mech-btw ."+litre).show();  $('input[name=step4]').val('mech-btw'); };
    if(pantype=='wallhung'){ $("#step4content #mech-wh").show(); $("#step4content #mech-wh ."+litre).show();  $('input[name=step4]').val('mech-wh'); };
    };
  if(step3=='Pneumatic Buttons'){
    if(pantype=='backtowall'){ $("#step4content #pneu-btw").show(); $("#step4content #pneu-btw ."+litre).show();  $('input[name=step4]').val('pneu-btw'); };
    if(pantype=='wallhung'){ $("#step4content #pneu-wh").show(); $("#step4content #pneu-wh ."+litre).show();  $('input[name=step4]').val('pneu-wh'); };
    };
  if(step3=='Undercounter Buttons'){
    if(pantype=='backtowall'){ $("#step4content #under-btw").show(); $("#step4content #under-btw ."+litre).show();  $('input[name=step4]').val('under-btw'); };
    if(pantype=='wallhung'){ $("#step4content #under-wh").show(); $("#step4content #under-wh ."+litre).show();  $('input[name=step4]').val('under-wh'); };
    };
    
    $("#printform").slideDown();

  };

  
  $('#printform a').click(function(){
  
 // alert("Step1: " + step1 + ", Step2: " + step2 + ", Step3: " + step3 + ", Pan : " + pantype + ", Litre : " + litre); 
 //  alert("Step1: " + $('#values #step1').val() + ", Step2: " + $('#values #step2').val() + ", Step3: " + step3 + ", Pan : " + pantype + ", Litre : " + litre); 
 

      $('#values').submit();
      
      return false;
  
   });
   
      $(".button").hover(function () {
      $(this).css({'background-position' : 'bottom'});
    }, function () {
      var cssObj = {'background-position' : 'top'};      
      $(this).css(cssObj);
    });
    
    function scrollWin(){
      $('html').animate({
        scrollTop: $("#hideaway_selector").offset().top
      }, 500);
    };    
    

});



