$(document).ready(function() {
	
	$("#slider").easySlider({
		controlsShow: true,
		auto: true, 
		continuous: true,
		pause: 10000,
		prevText: '&laquo; Previous',
		nextText: 'Next &raquo;'
	});
	
	$("#form-contact").validate();

	$("#form-purchase").validate({
	  rules: {
	    total_amount: {
	      required: true,
	      min: 1
	    },
	    postalcode: {
	      required: true,
	      minlength:4 
	    }
	    
	  }
	});
	
	$("#total_amount").keyup(function(e) {
		value = CurrencyFormatted($(this).val()*$("#price").val());
		$("#total-cost").html(value);
	});
	if ($("#total_amount").length > 0)
	{
		value = CurrencyFormatted($("#total_amount").val()*$("#price").val());
		$("#total-cost").html(value);
	}

	
	if ($("#gmap").length > 0)
	{
		var htmlcontent = "<h4>Visit us at:</h4><p>Unit 18/632-642 Clayton Road<br />Clayton South VIC 3169</p>";
	
		var map = new GMap2(document.getElementById('gmap'));
		var mycenter = new GLatLng(-37.94899,145.116199);
		map.setCenter(mycenter, 15);
		
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var lngSpan = northEast.lng() - southWest.lng();
		var latSpan = northEast.lat() - southWest.lat();

		var point = new GLatLng(-37.94899,145.116199);
	    marker = new GMarker(point);
	    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(htmlcontent);});
	    map.addOverlay(marker);
	    marker.openInfoWindowHtml(htmlcontent);

	}
	
});

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
