// Headline scroller
var headline_count;
var headline_interval;
var current_headline = 0;
var old_headline = 0;


// Web site effects.
$(document).ready(function() {

  headline_count = $("div.headline").size();
  $("div.headline:eq("+current_headline+")").css('top', '5px');

  headline_interval = setInterval(headline_rotate,6000);
  $('#scrollup').hover(function() {
    clearInterval(headline_interval);
  }, function() {
    headline_interval = setInterval(headline_rotate,6000);
//     headline_rotate();
  });


 $(".mailme").defuscate();

// Enable 'read more type toggle'
   // toggles
   $("a.toggle").click(function(){
      $("#" + this.rel).slideToggle("slow");
//       return false;
   });
//    $("a.toggle").attr({ href: "javascript:;"});


   $('input#product').hide();

   $("#bi_query #submit").click(function(){
      var url = site_url + '/site/livequery/bi/';
      $.post(url,
         {
            name        : $("#name").val(),
            email       : $("#email").val(),
            comment     : $("#comment").val(),
            product     : $("#product").val(),
            service     : 'bi',
            Submit      : 'Submit'
         },
         function(data){

            if (data == 'false') {
               msg = 'Warning. Your message could not be send.';
            }
            else {
                  msg = data;
            }

            $('#msg').html(msg);
            $('#msg').fadeIn(2000).fadeTo(5000, 1).fadeOut(2000);
            $("#bi_query").fadeOut(2000);

         }
      );
      return false;

   });

   $("#contact_form #submit").click(function(){
      var url = site_url + '/site/contactus/';
      $.post(url,
         {
            name        : $("#name").val(),
            email       : $("#email").val(),
            phone       : $("#phone").val(),
            comment     : $("#comment").val(),
            product     : $("#product").val(),
            service     : 'all',
            Submit      : 'Submit'
         },
         function(data){

            if (data == 'false') {
               msg = 'Warning. Your message could not be send.';
            }
            else {
                  msg = data;
            }

            $('#msg').html(msg);
            $('#msg').fadeIn(2000).fadeTo(5000, 1).fadeOut(2000);

         }
      );
      return false;

   });


   $("input.acidtestitem").click(function(){
//       debugger;
      var count = 0;
      $("input.acidtestitem").each(function(){
//          debugger;
         if (this.checked == true) {
            count = count + 1;
         }
         x = this;
      });

//       debugger;

      var percent_on = (count/18) * 100;

      $("div#passmeter").width(percent_on + '%');
      $("#bi_acid_test_score").html(parseInt(percent_on) + '%');

//       onkeyup="document.getElementById('passmeter').style.width

   });

});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count;
  $("div.headline:eq(" + old_headline + ")")
    .animate({top: -205},"slow", function() {
      $(this).css('top', '210px');
    });
  $("div.headline:eq(" + current_headline + ")")
    .animate({top: 5},"slow");
  old_headline = current_headline;
}

// Die bot
 jQuery.fn.defuscate = function() {
   return this.each(function(){
     var email = String($(this).html()).replace(/\s*\(.+\)\s*/, "@");
     $(this).before('<a href="mailto:' + email + '">' + email + "</a>").remove();
   });

};

