jQuery(function () {
  Cufon.replace('div#menu a, table.RedTable p, .tilbudSvartidBox span', { fontFamily: 'SignaSerifOT-Book' });
  Cufon.replace('h1, h2, h3, h4.contourPageName, fieldset.contourFieldSet legend', { fontFamily: 'SignaSerifOT-Light' });
  initImageRotation();
  initPersonalOfferForm();
});
/* Live methods */
initSearch();

function initSearch(){
  jQuery('a#btnSearch').live('click', function(){
    search(jQuery(this).prev().val());
    return false;
  });
  jQuery('input#searchText').live('keypress', function(e){
    if(e.which === 13){
      search(jQuery(this).val());
      return false;
    }
  });
}

function search(word){
  window.location.href = '/da/soeg.aspx?q=' + escape(word);
}

function initImageRotation(){
  var settings = {
    showTime: 4000
  };
  jQuery('.imageRotator').each(function(){
    var jQEle = jQuery(this);
    jQEle.readyContentRotator(settings);
  });
}

function initPersonalOfferForm() {
  var tilbudsformular = jQuery('#bodyText .tilbudsformular');
  if(tilbudsformular[0]){
  
    jQuery('#bodyText .tilbudsformular .bestiltilbudpåforsikring .checkboxlist input')
      .each(function(){
        toggleFormFieldset(jQuery(this), tilbudsformular);
      }).click(function(){
        toggleFormFieldset(jQuery(this), tilbudsformular);
      });
    tilbudsformular.find('.postnr input').blur(function(){
      if(parseInt(tilbudsformular.find('.postnr input').val()) < 6000){
        return confirm('Vi må desværre beklage, men det postnummer, som du har indtastet, ligger uden for vort tegningsområde.');
          
        
        
      }
    });
  }
  
}

function toggleFormFieldset(input, tilbudsformular){
  var value = input.val(),
      checked = input[0].checked,
      showEle = null;
      
  switch(value){
    case '7cb9ce9e-218f-4e5e-916b-0f8ac229a6d8':
      showEle = tilbudsformular.find('.vedbestillingaftilbudpåbil')
      break;
    case 'd7e953af-7533-41cb-8db6-6df51db4a32d':
      showEle = tilbudsformular.find('.vedbestillingaftilbudpåmotorcykel')
      break;
    case 'a5c00fd4-f13d-4cea-98e5-c652b41f36f4':
      showEle = tilbudsformular.find('.vedbestillingaftilbudpåulykkesforsikring')
      break;
    case '0511ce10-d597-48c4-917e-28c792c8d169':
      showEle = tilbudsformular.find('.vedbestillingafindboforsikring')
      break;
   
  }
  if(showEle && showEle[0]){
    if(checked){
      showEle.removeClass('hide');
    }else{
      showEle.addClass('hide');
    }
  }
}

