var leftcounter = 0;
function setEditButton(){
	$("#edit").click(function() {
		$("#weathertitle1").hide();
		$("#weathertitle2").show();
		
		$("#go").show();
		$("#edit").hide();
	});
	
	$("#go").hide();
	$("#go").click(changeLocation);
	$("#weathertitle2").submit(changeLocation);

}

function changeLocation(){
	// get the location from the input box
	var loc = $("#location").val();


	// set up the cookie
	var options = { path: '/', expires: 365 };
	$.cookie('hottopics', loc, options);
	//alert($.cookie('hottopics'));
	

	// this sends the data to the getlocation page which returns the
	// whole weather section
	$.post("getlocation.php", { location: loc},
		function(data){		  
			$("#weatherbox").replaceWith(data);
			$("#go").hide();
			$("#edit").show();
			setEditButton();
		}
	);
	
	return false;
}

function setTweetTips(leftcounter) {
        if(leftcounter == 0) {
            $("#leftarrow").hide();
        }

	$("#leftarrow").click(function() {
		if (leftcounter != 0) {
			leftcounter--;
		}
		$.post("gettweettips.php", { id: leftcounter},
		function(data){
			leftcounter-1;
			$("#ads").replaceWith(data);
			setTweetTips(leftcounter);
		});
	});
	
	
	$("#rightarrow").click(function() {
	   
		leftcounter++;
		  
		$.post("gettweettips.php", { id: leftcounter},
		function(data){
			  leftcounter+1;
			  $("#ads").replaceWith(data);
			  setTweetTips(leftcounter);
		});
	});
	
}

$(document).ready(function(){
	setEditButton();
	setTweetTips(leftcounter);
   
});
