/* ------------------------------------
---- Main jquery code -----------------
---- Original Author: Karen Comber ----
----   Creation Date: 20/07/2010   ----
----    Webexpectations.com Ltd    ----
-------------------------------------*/

$(document).ready(function() {

    if ($('body').is('.brickcalc')) {

       if( $.browser.safari ) {
            //$('body.brickcalc div#calculator div#tabset').css('margin-top','-6px');
            $('body.brickcalc div#calculator div.inner').css('padding-bottom','17px');
       }

       $('body.brickcalc div#calculator').show();
       var pointer = 0;
       var type = 'single';
       var calc = calcArray(type);
       var nos = nosArray(type);
       var end = calc.length;
       var value = $('div#value');
       var results = $('table#bricks td.result');
       var units = '<span>m<sup>2</sup></span>';
       var tabs = 'body.brickcalc div#calculator div#tabset div.tabs';
       var singleinfo = 'for a 102.5mm thick wall';
       var doubleinfo = 'for 2 skins x 102.5mm thick wall';

       $("body.brickcalc div#calculator div#tabset div.tabs a#single").click(function() {
           $(this).parent().removeClass('double');
           $("body.brickcalc div#tabset div#calcpanel div#notes span.subnote").html(singleinfo);
           type = 'single';
           results.each(function(e){
                $(this).html(nos[pointer][e]);
           });
       });
       $("body.brickcalc div#calculator div#tabset div.tabs a#double").click(function() {
           $(this).parent().addClass('double');
           $("body.brickcalc div#tabset div#calcpanel div#notes span.subnote").html(doubleinfo);
           type = 'double';
           results.each(function(e){
                $(this).html(nos[pointer][e]*2);
           });
       });

       $("a.plus,a.minus").mousedown(function(){return false;});

       $("a.plus").click(function() {
           value.html('');
           if (pointer < end-1) pointer++;
           if (pointer < end-1) {
              $(this).removeClass('plus-disable');
              $("a.minus").removeClass('minus-disable');
           } else {
              $(this).addClass('plus-disable');
           }
           value.html(calc[pointer]+units);
           results.each(function(e){
              if (type=='double') {
                  $(this).html(nos[pointer][e]*2);
              } else {
                  $(this).html(nos[pointer][e]);
              }
           });

       });

       $("a.minus").click(function() {
           value.html('');
           if (pointer > 0) pointer--;
           if (pointer > 0) {
              $(this).removeClass('minus-disable');
              $("a.plus").removeClass('plus-disable');
           } else {
              $(this).addClass('minus-disable');
           }
           value.html(calc[pointer]+units);
           results.each(function(e){
              if (type=='double') {
                  $(this).html(nos[pointer][e]*2);
              } else {
                  $(this).html(nos[pointer][e]);
              }
           });

       });

    }



});

function calcArray(type) {

  var calc = [1,5,10,20,50,100];
  return calc;

}

function nosArray(type) {

  var nos = new Array();
  nos[0] = [75,60,57,54];
  nos[1] = [371,297,285,268];
  nos[2] = [741,593,570,536];
  nos[3] = [1482,1186,1140,1071];
  nos[4] = [3704,2963,2850,2678];
  nos[5] = [7408,5926,5699,5355];
  return nos;

}