$(document).ready(function() {
	var oldState = $("#chosenState").html();
	var oldColor;
	var oldBGColor;
	// map functions
	// reload map 
	$(".stateList").click(function() {
		stateInitials = $(this).attr('id');
		oldState = $("input", this).val();
		$("#chosenState").html(oldState);
		loadMap(stateInitials);
		return false;
	});
	$(".stateList").hover(
		function() {
			oldState = $("#chosenState").html();
			var newState = $("input", this).val(); 
			$("#chosenState").html(newState);
			oldColor = $(this).css('color');
			oldBGColor = $(this).css('background-color');
			$(this).css('color','#000');
			$(this).css('background-color','#8f8');
		},
		function() {
			$("#chosenState").html(oldState);
			$(this).css('color',oldColor);
			$(this).css('background-color',oldBGColor);
	});
	
// twitter functions	
	// ajax in a new list of top ten twitter trends
	$('#trendWrapper .button').click(function() {
		xajax_trends();
		return false;
	});

	// add styling to new tooltips when they get ajaxed into the page
	$('.tip').livequery(function() {
		$(this).tooltip();
		$('#tooltip').addClass('ui-corner-all');
	});

	// when a trend is clicked, ajax in a new set of tweets and add
	// appropriate styling to new entries and trend list
	$('#trendUL li') .livequery(function() { 
    	$(this).click(function(){
    	var trend = $(this).html();
    	xajax_searchTrends(trend); 											// ajax in new tweets
    	$('#tweets h3').html("last ten tweets with '" + trend + "'");		// update tweets header
        }); 
    	$(this).click( function() {											// these lines manage the highlighting when
    		$('#trendUL li').removeClass('trendClick');						// when hovering/clicking in the trends list
    		$(this).addClass('trendClick');		
    	});
    	$(this).hover( function(){
			if($(this).css("background-color") == "transparent") {
				$(this).addClass('trendHover'); 
			}
		}, function(){
			if($(this).css("background-color") != "#cccccc") {
				$(this).removeClass('trendHover');
			}
		});
    }); 


	$('#zzzsubtext').click(function(){animate('.red')});


});

