jQuery(function($) {

var states		= new Array('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY');

var states_long	= new Array('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming');

var i	= 0;

if ( $("input#random_state") )
{
	i	= $("input#random_state").val();
}

//	-------------------------------
//	Set images
//	-------------------------------

var arr		= new Object;
arr[i]		= new Image;
arr[i].src	= "/img/green_map/map_" + states[i] + ".gif";

arr[i + 1]		= new Image();
arr[i + 1].src	= "/img/green_map/map_" + states[i+1] + ".gif";

/*
$.each( states, function(i,n) {
	arr[n]		= new Image();
	arr[n].src	= "/img/green_map/map_" + n + ".gif";
});
*/

//	-------------------------------
//	Handle hover
//	-------------------------------

$("map#map_area area").hover(
	function() {
		var st	= $(this).attr("alt");
		// $("#map").attr( "src", arr[ st ].src );
		
		// $("div#photobox").load( "/featured_properties/ajax_property", {state: st} );		
	},
	function() {
		// $("#map").attr( "src", arr[0].src );
		// $("li#photobox_" + st).hide();
	}
);

//	-------------------------------
//	Slideshow of states
//	-------------------------------

$.timer( 3000, function(timer) {

	st	= states[i];
	
	$("#map").attr( "src", arr[i].src );
	
	$("div#photobox").load( "/featured-properties/ajax_property", {state: st, state_long: states_long[i]} );	
	
	if ( i >= 50 )
	{
		i = 0;
	}
	else
	{
		i++;
	}
	
	//	Load next state image
	
	arr[i]		= new Image();
	arr[i].src	= "/img/green_map/map_" + states[i] + ".gif";
})


});

/*
 *
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 *
 */
 
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };