jQuery(function($){
  $('#packages').jcarousel({ wrap: 'circular'});
  $('.next-btn').click(function() {
    $('.small-fieldset').hide();
    $('.large-fieldset').show();
    $(this).hide();
    $('.prev-btn').show();
    $('.submit-btn').show();
    hightlighActiveStep('forward');
  });
  $('.prev-btn').click(function() {
    $('.large-fieldset').hide();
    $('.small-fieldset').show();
    $(this).hide();
    $('.next-btn').show();
    $('.submit-btn').hide();
    hightlighActiveStep('prev');
    $('.wpcf7-response-output').hide();
  });
  $('.left-col select').change(function() {
    document.location.href = $(this).val();
  });
  $('.left-col input').click(function() {
    document.location.href = '/contact-us/?usp='+$(this).attr('name');
  });
  $('.plan-changer a').click(function() {
    $('.change-dialog').dialog('open');
    return false;  
  });
  $('.change-dialog').dialog({height:260, autoOpen:false, width:750, title: 'Select a new package', modal:true, buttons: { "Ok": function() { selectPackage(this); } }});
  if(typeof selectedPlan!='undefined') {
    $('.wpcf7 input[name=selected-plan]').val(selectedPlan);
  }
});  
  DD_roundies.addRule('.roundify', '10px 10px 0 0');
  DD_roundies.addRule('.roundify-bottom', '0 0 10px 10px');
  DD_roundies.addRule('.roundify-all', '10px');
  
function hightlighActiveStep(direction) {
  var nextActive = false;
  if(direction == '') direction = 'forward';
  jQuery('div.steps li').each(function() {
    if(!jQuery(this).hasClass('non-active')) {
      if(!nextActive) {
        nextActive = (direction == 'forward')? jQuery(this).next() : jQuery(this).prev();
      } 
    }
    jQuery(this).addClass('non-active');
  });
  jQuery(nextActive).removeClass('non-active');
}

function selectPackage(modalDialog) {
  var selectedCheckbox = jQuery('input[type=radio]:checked', modalDialog); 
  var checkboxVal = jQuery(selectedCheckbox).val();
  var imgPath = '';
  if(checkboxVal) {
    imgPath = jQuery(selectedCheckbox).parent().children('img').attr('src');
    if(imgPath) {
      jQuery('.selected-plan span:nth-child(3)').text(jQuery(selectedCheckbox).parent().children('span').text());
      jQuery('.selected-plan img').attr('src', imgPath);
    } else {
      jQuery('.selected-plan').hide();  
    }
    jQuery('.wpcf7 input[name=selected-plan]').val(checkboxVal);  
  }
  jQuery(modalDialog).dialog("close");
}
  



