/* Hash of state name abbreviations */
var states = $H({ AL:'Alabama', AK:'Alaska', AZ:'Arizona', AR:'Arkansas', CA:'California', CO:'Colorado', CT:'Connecticut', DE:'Delaware', DC:'District Of Columbia', FL:'Florida', GA:'Georgia', HI:'Hawaii', ID:'Idaho', IL:'Illinois', IN:'Indiana', IA:'Iowa', KS:'Kansas', KY:'Kentucky', LA:'Louisiana', ME:'Maine', MD:'Maryland', MA:'Massachusetts', MI:'Michigan', MN:'Minnesota', MS:'Mississippi', MO:'Missouri', MT:'Montana', NE:'Nebraska', NV:'Nevada', NH:'New Hampshire', NJ:'New Jersey', NM:'New Mexico', NY:'New York', NC:'North Carolina', ND:'North Dakota', OH:'Ohio', OK:'Oklahoma', OR:'Oregon', PA:'Pennsylvania', RI:'Rhode Island', SC:'South Carolina', SD:'South Dakota', TN:'Tennessee', TX:'Texas', UT:'Utah', VT:'Vermont', VA:'Virginia', WA:'Washington', WV:'West Virginia', WI:'Wisconsin', WY:'Wyoming' });

var regions = $H({2:'VANCOUVER',3:'VICTORIA', 5:'CALGARY', 7:'EDMONTON', 8:'SASKATOON', 167:'OTTAWA', 166:'COLLINGWOOD', 168:'HAMILTON', 9:'TORONTO', 10:'MONTREAL', 11:'NOVA SCOTIA'})

//function getContentByRegion(region) {alert("Get some content");}

function getContentByRegion(region) {
	if (region != ""){
	//alert(region);
	/* Show the offers window if it's hidden */
	if($('popup').hasClassName('closed')){$('popup').removeClassName('closed');}
	
	/* Get a list of subregions for this region ... */
		new Ajax.Request('get-content.php', 	
	  {
		method:'get',
		parameters: {type: 'region_list', region: region},
		onSuccess: function(transport){
		  var region_list_response = transport.responseText || "No content for this category";
		  //$('subregions').innerHTML = region_list_response;
		},
		onFailure: function(){$('subregions').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
	/* ... and get all the offers for this region */
	new Ajax.Request('get-content.php',
	  {
		method:'get',
		parameters: {type: 'region', region: region, rname:regions[region]},
		onSuccess: function(transport){

		  var region_response = transport.responseText || "No content for this category";
		  $('state-name').innerHTML = region;
		  clearOffers();
		  $('content').innerHTML = region_response;
		  			initLightbox();
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
	}
}

function getContentBySubregion(subregion) {
	
	/* Get all the offers for this subregion */
	new Ajax.Request('get-content.php',
	  {
		method:'get',
		parameters: {type: 'subregion', subregion: subregion},
		onSuccess: function(transport){

 		  $('state-name').innerHTML = subregion;
		  var subregion_response = transport.responseText || "No content for this category";
		  $('content').innerHTML = subregion_response;

		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
}

function getCity(state) {
if (state != ''){

	/* Get all the offers for this subregion */
	new Ajax.Request('get-content.php',
	  {
		method:'get',
		parameters: {type: 'city', state: state},
		onSuccess: function(transport){

		  var subregion_response = transport.responseText || "No content for this category";
		  $('city').innerHTML = subregion_response;
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
	}
	
}

function getState(country) {
	if (country != ""){
	/* Get all the offers for this subregion */
	new Ajax.Request('get-content.php',
	  {
		method:'get',
		parameters: {type: 'state', country: country},
		onSuccess: function(transport){

		  var subregion_response = transport.responseText || "No content for this category";
		  $('prov').innerHTML = subregion_response;
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
	}
}

function getCountry() {
	/* Get all the offers for this subregion */
	new Ajax.Request('get-content.php',
	  {
		method:'get',
		parameters: {type: 'country'},
		onSuccess: function(transport){

		  var subregion_response = transport.responseText || "No content for this category";
		  $('country').innerHTML = subregion_response;
		},
		onFailure: function(){$('content').innerHTML = '<h2>Error connecting to server</h2>';}
	  });
}


function clearOffers() {
	/* Remove every offer from the DOM */
	$('content').descendants().each(function(offer){offer.remove();});
	return false;
}

function closeOfferWindow() {
	/* Close the popup window */
	$('popup').addClassName('closed');
	$('content').descendants().each(function(offer){offer.remove();});
	//$('subregions').descendants().each(function(offer){offer.remove();});
}

function loadFlash() {
	var soMap = new SWFObject("assets/map.swf", "map-flash", "343", "336", "9", {wmode:'transparent'});
	soMap.write("flash-map");
}