$(document).ready( function() {

	if ($('#body1').length != 0) {
		//Create an image element
		var photo = new Array();
		photo[1] = $('<img />').attr('src', '/themed/gorhamsandgravel/img/template/largeproject1.jpg');
		photo[2] = $('<img />').attr('src', '/themed/gorhamsandgravel/img/template/largeproject2.jpg');
		photo[3] = $('<img />').attr('src', '/themed/gorhamsandgravel/img/template/largeproject3.jpg');
		photo[4] = $('<img />').attr('src', '/themed/gorhamsandgravel/img/template/largeproject4.jpg');
		
		var alt = new Array();
		alt[1]="Portland Jetport Foundation";  
		alt[2]="Shaker Pond Commons";
		alt[3]="Skvorak Dental";
		alt[4]="Read Our Story";
		
		var link = new Array();
		link[1]="http://www.portlandjetport.org/portland_jetport_info/terminal_expansion";  
		link[2]="/projects/view/156";
		link[3]="/projects/view/157";
		link[4]="/our-story.php";
		
		var txt = new Array();
		txt[1]="<h2><a href='http://www.portlandjetport.org/portland_jetport_info/terminal_expansion' title='Portland Jetport Terminal Expansion'>Portland Jetport</a><span>We are moving 100,000 cubic yards of earth to make way for the Terminal Expansion</span></h2>";  
		txt[2]="<h2><a href='/projects/view/156' title='Shaker Pond Commons'>Shaker Pond Commons</a><span>Increased efficiency and lowered the upfront cost.</span></h2>";
		txt[3]="<h2><a href='/projects/view/157' title='Skvorak Dental'>Skvorak Dental</a><span>Something we can all smile about.</span></h2>";
		txt[4]="<h2><a href='/our-story.php' title='Read Our Story'>Gorham Sand & Gravel</a><span> A Foundation of Excellence and Hard Work</span></h2>";
		
		//get to small images and add class - bad
		$('.carouselHolder li>img:eq(0)').addClass('1');
		$('.carouselHolder li>img:eq(1)').addClass('2');
		$('.carouselHolder li>img:eq(2)').addClass('3');
		$('.carouselHolder li>img:eq(3)').addClass('4');
	}
	
	$(".carouselHolder .contentCarousel").jCarouselLite({
   		btnNext: ".carouselHolder #btnNext",
    	btnPrev: ".carouselHolder #btnPrev",
    	visible: 3
	});
	
	$(".carouselHolder li>img").click(function() {
		var imgClass = $(this).attr('class');
		var $imgSrc = $(photo[imgClass]).attr('src');
		$('img#carouselImg').fadeIn('fast', function() {
			$('img#carouselImg').attr({src: $imgSrc,
										alt: alt[imgClass]
										});
		});
		$('a#carouselA').attr({href: link[imgClass]});
		$('#summary').html(txt[imgClass]);
	});
	

	$("A.extlink").click( function() {
	    $.jqURL.loc($(this).attr('href') + '&winext=1',
			{w:500,h:500,wintype:'_blank'});
	      return false;
	});
	

		$('input.quantity').attr('autocomplete', 'off');	//have to use keyboard
		$('input.quantity').keyup( function(event) {
			var product = jQuery.metadata.get(this);
			var amount = 0;
			var quantity = $(this).val();
			quantity = quantity.replace('$', '');	//get rid of dollar sign if they enter one
			quantity = quantity.replace(',', '');
			//product.price from class on input
			if(product.price > 0) {
				if(product.special_price) {
					amount = product.special_price * quantity;
				} else {
					amount = product.price * quantity;
				}
			} else {
				amount = quantity;	//donation
			}
			if(amount >= 0) {
				$(this).parents('td').next('td').html(amount).formatCurrency();			
			} else {
				$(this).parents('td').next('td').html('&nbsp;');
			}
			resetOrderTotal();
			event.preventDefault();
	    });
		
	
		if($.browser.msie && $.browser.version=="6.0")	{
			//do nothing
		} else {
			$(".halfColumns").columnize({width:200});
		}	
});

function resetOrderTotal() {
	var order_total = 0;
	
	 $("input.quantity").each(function() {
	        var product = jQuery.metadata.get(this);
			var amount = 0;
			var quantity = $(this).val();
			quantity = quantity.replace('$', '');	//get rid of dollar sign if they enter one
			quantity = quantity.replace(',', '');
			
			//product.price from class on input
			if(product.price > 0) {
				if(product.special_price) {
					amount = product.special_price * quantity;
				} else {
					amount = product.price * quantity;
				}
			} else {
				amount = quantity;	//donation
			}
			
			if(amount > 0) {
				order_total = parseFloat(order_total) + parseFloat(amount);
			}
	    });
	 $('div.avorderTotal h3 span').text(order_total).formatCurrency();
}

$(function() {
    $('#imgMaineMap').maphilight({strokeColor:'ff0000',strokeWidth:1,fillColor:'ff0000',fillOpacity:0.2});
});

