var offset = 0;
var use_fx = true;

function showMore(value) {
  if(value == "more") {
    document.getElementById("numberOfPagesMore").style.visibility = 'visible';
    document.getElementById("numberOfPagesMore").focus();
    calcEstimate(document.getElementById("numberOfPagesMore").value);
  } else {
    document.getElementById("numberOfPagesMore").style.visibility = 'hidden';
    calcEstimate(value);
  }
}

function updateFormat(value) {
  setOffset(value);
  var noPages = document.getElementById("numberOfPages");
  showMore(noPages[noPages.selectedIndex].value);
}

function calcEstimate(value) {
  if( parseInt(value).toString() == 'NaN' ) {
    document.getElementById("estimate").innerHTML = "$---";
    return;
  }
  value = parseInt(value) -1;
  sum = (175 + offset);
  sum += (value * (75 + offset));
  document.getElementById("estimate").innerHTML = "$"+ sum;
}

function setOffset(format) {
  switch(format) {
    case 'email':     window.offset = 10; break;
    case 'haml':      window.offset = 25; break;
    case 'markaby':   window.offset = 25; break;
    case 'rails':     window.offset = 35; break;
    case 'merb':      window.offset = 35; break;
    case 'radiant':   window.offset = 20; break;
    case 'frog':      window.offset = 20; break;
    case 'blogger':   window.offset = 35; break;
    case 'wordpress': window.offset = 35; break;
    default:          window.offset = 0;  break;
  }
}

function validateForm(form) {
  var name = form['clientName'].value;
  var email = form['clientEmail'].value;
  if( name != null && name != "" && email != null && email != "")
          return true
  else
          alert("Please enter your name and email before submitting this form. Thank you.");
  return false;
}

$(function(){
  
  if(use_fx) {
    $('.order-link').spanize('anim',1);
    
    window.shine = setInterval(function(){
      try {
        $('#main-navigation LI:not(.selected) .order-link').textscan({
          spanize:-1,          unspanize:-1,      spanClass:'anim',
          amplitude:20,        step: 10,
          initColor: '679866', transColor: 'FFF', endColor: '679866'
        });
      } catch(ex) {
        clearInterval(shine);
      }
    }, 10000);
    $('.question-list A').each(function(){
      var id = this.hash +"-container";
      $(id).spanize('anim',1);
      $(this).click(function(){ 
        var id = this.hash +"-container";
        $(id).textscan({
          spanize:-1,         unspanize:-1,      step:10,
          spanClass:'anim',   amplitude:20,      
          initColor:'fa8112', endColor:'679866', transColor:'FFF',
          cb:function() {
            $(id).textscan({
              spanize:-1,         unspanize:-1,      spanClass:'anim', 
              amplitude:20,       step:10,
              initColor:'679866', endColor:'fa8112', transColor:'FFF'
            });
          }
        });
      });
    });

    if(document.location.hash) {
      $( document.location.hash +"-anchor").click();
    }
  }
})