var ClaimCalculator = {
	regions: Object,
	
	init: function()
	{
		// set up regions and text etc
		this.regions = {
			head: { 
				range: "10-20,000",
				description: '<table class="amounts">\
		      <tr>\
		        <td class="type">Very Severe Brain Damage</td><td>165,500 – 235,000</td>\
		      </tr>\
		      <tr>\
		        <td class="type">Moderately Severe Brain Damage</td><td>127,250 – 165,500</td>\
		      </tr>\
		      <tr>\
		        <td class="type">Moderate Brain Damage</td><td>25,000 – 127,250</td>\
		      </tr>\
		      <tr>\
		        <td class="type">Minor Brain Damage</td><td>9,000 – 25,000</td>\
		      </tr>\
		    </table>'
			},
			leg: {
				range: "34-56,000",
				description: '<table class="amounts">\
				                <tr>\
				                  <td class="type">Amputations</td><td>	52,950 – 165,500</td>\
				                </tr>\
                        <tr>\
                          <td class="type">Severe leg Injuries</td><td>16,300 – 79,000</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Less serious leg injuries</td><td>5,350 – 16,300</td>\
                        </tr>\
                        <tr>\
                          <td class="type" colspan="2">Knee injuries</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Severe</td><td>15,500 – 56,000</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Moderate</td><td>	8,150 – 15,500</td>\
                        </tr>\
				              </table>'
			},
			back:{
				range: "77-88,000",
				description: '<table class="amounts">\
				                <tr>\
				                  <td class="type">- Severe</td><td>22,650 – 98,500</td>\
				                </tr>\
                        <tr>\
                          <td class="type">- Moderate</td><td>7,125 – 22,650</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Minor	</td><td>4,575 – 7,125</td>\
                        </tr>\
				              </table>'
			},
			arm: {
				range: "7-175,000",
				description: '<table class="amounts">\
				                <tr>\
				                  <td class="type">Loss of both arms</td><td>140,500 – 174,500</td>\
				                </tr>\
                        <tr>\
                          <td class="type" colspan="2">Loss of one arm</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Arm amputated at shoulder</td><td>circa 79,000</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Above elbow amputation</td><td>63,625 – 76,350</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Below elbow amputation</td><td>56,000 – 63,625</td>\
                        </tr>\
                        <tr>\
                          <td class="type" colspan="2">Other arm injuries</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Severe</td><td>56,000 – 76,350</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Permanent/substantial disability</td><td>22,650 – 34,850</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Less severe injury</td><td>9,150 – 22,650</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Moderate or Minor injury</td><td>Up to 7,375</td>\
                        </tr>\
                    </table>'
			},
			hand: {
				range: "1-117,000",
				description: '<table class="amounts">\
				                <tr>\<td class="type">Hand injuries</td>						<td>500 – 117,000</td>\</tr>\
                        <tr>\
                          <td class="type">Finger injuries</td>						<td>1,250 – 32,000</td>\
                        </tr>\
                        </table>\
                        <table class="amounts">\
                        <tr>\
                          <td class="type" colspan="2">Hand Arm Vibration Syndrome (HAVS)/Vibration White Finger (VWF)</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Most Serious</td>					<td>18,325 – 22,400</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Serious</td>					<td>9,700 – 18,325</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Moderate</td>				<td>5,100 – 9,700</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Minor</td>						<td>1,775 – 5,100</td>\
                        </tr>\
				              </table>'
			},
			foot: {
				range: "1-117,000",
				description: '<table class="amounts">\
                          <tr>\
                            <td class="type">- Amputations</td>					<td>48,850 – 117,000</td>\
                          </tr>\
                          <tr>\
                            <td class="type">- Very Severe	</td>				<td>48,850 – 63,625</td>\
                          </tr>\
                          <tr>\
                            <td class="type">- Severe</td>					<td>	26,500 – 39,200</td>\
                          </tr>\
                          <tr>\
                            <td class="type">- Serious</td>					<td>14,500 – 22,650</td>\
                          </tr>\
                          <tr>\
                            <td class="type">- Moderate</td>					<td>8,150 – 14,500</td>\
                          </tr>\
                          <tr>\
                            <td class="type">- Modest</td>					<td>Up to 8,150</td>\
                          </tr>\
                      </table>'
			},
			organs: {
				range: "1-122,000",
				description: '<table class="amounts">\
                        <tr>\
                          <td class="type">Chest injuries</td><td>2,300 – 87,500</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Lung diseases</td><td>1,300 – 79,000</td>\
                        </tr>\
                      </table>\
                      <table class="amounts">\
                        <tr>\
                          <td class="type" colspan="2">Abestos related diseases</td>\
                        </tr>				\
                        <tr>\
                          <td class="type">- Mesothelioma</td><td>47,850 – 74,300</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Lung Cancer</td><td>45,800 – 58,500</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Asbestosis</td><td>28,000 – 61,500</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Pleural Thickening</td><td>22,400 – 45,800</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Pleural Plaques</td><td>6,100 – 7,125</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Asthma</td><td>3,000 – 38,175</td>\
                        </tr>\
                      </table>\
                      <table class="amounts">\
                        <tr>\
                          <td class="type" colspan="2">Reproductive system</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Male</td><td>3,800 – 86,500</td>\
                        </tr>\
                        <tr>\
                          <td class="type">- Female</td><td>5,850 – 98,500</td>\
                        </tr>\
                      </table>\
                      <table class="amounts">\
                        <tr>\
                          <td class="type">Digestive system</td><td>550 – 36,125</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Kidney</td><td>18,100 – 122,000</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Bowel</td><td>7,375 – 87,500</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Bladder</td><td>13,500 – 81,500</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Spleen</td><td>2,550 – 15,250</td>\
                        </tr>\
                        <tr>\
                          <td class="type">Hernia</td><td>2,000 – 14,000</td>\
                        </tr>\
                      </table>'
			}
		};
		
		// iterate through all elements of class trigger
		var regions = this.regions;
		
		$('.region').each( function() {
			var page_region = this;
			var region_name = page_region.id;

			if (typeof(region_name) == "string" && region_name in regions)
			{
				// if this region has an id, assume it's the region identifier
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);
        var distance = 10;
        var time = 500;
        var hideDelay = 200;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;

				var amount_text = regions[region_name].description + "<br/><br/><a href=\"/amounts.html#"+region_name+"\">View more details</a>" ;

				$("p", info)[0].innerHTML = "Claims between<br/> <strong>£" + regions[region_name].range + "</strong><br/>(click for details)";

				$([trigger.get(0), info.get(0)]).mouseover(function () {
				
					 if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;
                info.css({
                    display: 'block'
                }).animate({
                top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
				
				}).mouseout(function(){

          if (hideDelayTimer) clearTimeout(hideDelayTimer);
          hideDelayTimer = setTimeout(function () {
              hideDelayTimer = null;
              info.animate({
              top: '0px',
                  opacity: 0
              }, time, 'swing', function () {
                  shown = false;
                  info.css('display', 'none');
              });
							beingShown = false;
							shown = false;
          }, hideDelay);

          return false;
				
					
				}).mouseup(function(){
					$("p", "#ClaimAmounts")[0].innerHTML = amount_text;
					$("h2", "#ClaimAmounts")[0].innerHTML = "Amounts - " + region_name;
					$("#ClaimAmounts").highlightFade();
					//alert(regions[region_name].description);
				})

			}

		});

		// assign rollover text etc based on their class
		//alert(this.regions.head.description);
	},
	
	hover_region: function()
	{
		// draw popup
	},
	
	display_info: function()
	{
		// populate info panel with details for region
	}
	
	
}

