

	$(document).ready(function() 
	{ 
		var INITIAL_DELAY = 5000;
		var DELAY = 60000;
		var etag = "";
		
		var load = function()
		{
			
			// show its working
			$('div#mm_updates').append(".");
			
			$.ajax({
				// pull data
				url: "campaign/campaignupdates.php",
				dataType: "html",
				timeout: 10000,
				cache: false,
				ifModified: true,
				beforeSend: function(xmlHttpRequest) {
					//alert("before!");
					if (etag != "")
						xmlHttpRequest.setRequestHeader("If-None-Match",etag);

					$('div#box_getinvolved div.title').append('<img id="ajaxIcon" src="images/siteelements/ajax.gif"/>');
				},
				
				error: function() {
					// we failed to get an update, so lets leave the text area alone, and try again later
				},
				success: function(data, textStatus, xmlHttpResponse)
				{
					if (etag != xmlHttpResponse.getResponseHeader("Etag"))
					{
						etag = xmlHttpResponse.getResponseHeader("Etag");
					
						flashColor('div#box_getinvolved div.box');
						
						// hide then, remove all bits
						//$('div#mm_updates').hide("fast").empty();
						$('div#mm_updates').fadeOut("fast").delay(1).empty();
						
						//$('div#mm_updates').html(data).show("slow");
						$('div#mm_updates').html(data).fadeIn("slow");
						
						
					}
				},
				complete: function(data, status)
				{
					$('img#ajaxIcon').remove();
					setTimeout(load, DELAY);
				}
				
			});
		}
		
		setTimeout(load, INITIAL_DELAY);
		
		
		function flashColor(id)
		{
		    var container = $(id);
		    container.css("backgroundColor", "white");
		    
		    var originalColor = container.css('backgroundColor');
		    
	        container.animate(
	        	{
	        		backgroundColor:'yellow'
	        	}
	        	,'normal'
	        	,'linear'
	        	, function()
        		{
        			$(this).animate(
        			{
        				backgroundColor:'white'
        			})
        		}
        		
	        	);
		}

		
	});
	
	
	
	
	/*
	// javascript to download all the written answers from theyworkforyou.com

		// constants
		var LINK_URL = "http://www.theyworkforyou.com";
		var TOTAL_TO_DISPLAY = 4;
		var LOADING_MESSAGE = "<p>Downloading information from <b>theyworkforyou.com</b> ...</p>";
		var ERROR_MESSAGE = "<p><b>Error: unable to connect</b></p><p>Unfortunately. we were unable to download any information from <b>theyworkforyou.com</b>.  Please try this page again later.</p>";
		var RESULTS_START = "<p><b>Don Foster's most recent appearances in Parliament</b></p>";
		var RESULTS_END   = "<p><b>For more information</b><br>See more of Don Foster's appearances in Parliament at <a href=\"http://www.theyworkforyou.com/mp/don_foster/bath\" target=\"_blank\">theyworkforyou.com</a>.</p>";

		// variables
		var theHTML = "";
		
		var count = 0;
		
		// executable code	
		$(document).ready(function() {
			// state we are loading
			$("#theyworkforyoudata").append(LOADING_MESSAGE);
			
			$.ajax({
			  // lets pull the data off the local
			  url: "theyworkforyou.php",
			  dataType: "xml",
			  timeout: 10000,
			  cache: false,
			  error: function() { 
			  	$("#theyworkforyoudata").html(ERROR_MESSAGE);
			   },
			  success: function(xml) { 
			  	count = 1;
				
			  	$(xml).find('match').each(function() { 
					//count++;
					
					if (count <= TOTAL_TO_DISPLAY)
					{
						// title
						var title = $(this).find("parent body").text();
						
						if (title != "")
						{
							count++;
							// main url
							var url = $(this).find("listurl").eq(0).text();
							// main text
							var theBody = $(this).find("body").eq(0).text();
							var theDate = $(this).find("hdate").text();
							
							// compile it all up
							theHTML += '<p><a href="' + LINK_URL + url + '" target="_blank">' + title + ' (' + theDate + ')</a></p>';
							theHTML += "<p>" + theBody + "</p>";
						}
					}
				});
				
				
				theHTML = RESULTS_START + theHTML + RESULTS_END;
				
				$("#theyworkforyoudata").html(theHTML);
			   }
			});
		});

	*/
