// testmap.js
// Copyright (c) 2008 Michael Geary
// http://mg.to/
// Free Beer and Free Speech License (any OSI license)
// http://freebeerfreespeech.org/

// Outer wrapper function
(function( $ ) {

var states = PolyMap.states;
var polyTimer;

function S() {
	return Array.prototype.join.call( arguments, '' );
}



function load() {
	var state, region, frameStart;
	
	var pm = new PolyMap({
		container: $('#testmap')[0],
		shapes: '../shapes/json/',
		events: {
			load: function( region_ ) {
				region = region_;
				colorize( region );				
			},
			over: function( place ) {
				$('#status').html( placename(place) );
			},
			click: function( place ) {
				alert( 'Clicked ' + placename(place) );
			}
		}
	});
	
	
	//$('#chkSubpixel').click( function() {
	//	pm.redraw();
	//});
	
	loadState( 'al' );
	
	function colorize( region ) {
		// Test with random colors
		( region.places || [region] ).forEach( function( place ) {
			if(placename(place) == "N/A"){
				place.fillColor = '#C0C0C0';
				place.fillOpacity = .8;
			}else{
				place.fillColor = '#ff0000';
				place.fillOpacity = .3;
			}
			//place.fillOpacity = .3;
			//place.fillColor = '#' + Math.random().toString(16).slice(2,8);
			//place.fillOpacity = Math.random() * .5 + .1;
			place.strokeColor = '#000000';
			place.strokeOpacity = 0.5;
			place.strokeWidth = 1.5;
		});
	}
	
	function placename( place ) {
		if( ! place ) return '';
		return place.name;
	}
	
	
	function loadState( value ) {
		if( value == state ) return;
		state = value;
		pm.load({ region:state });
	}
}

$(window).bind( 'load', load );

})( jQuery );
// end outer wrapper function
