$(document).ready(function(){

  if (typeof(subdir)=='undefined') { subdir = ''; }

  $.ajax({
	type: "GET",
	url: "/static/accuweather/" + subdir + "beach.xml",
	dataType: "xml",
	success: function(xml) {

	var beach_data =   $(xml).find('day:first').find('data').text(); 
	beach_data = beach_data.replace(/^\s+/g,"");	
	beach_data = beach_data.replace(/\n+/g, "<br />");

	$("#marineForecast #beach").html(beach_data);
    }
  });

  var tideItems = new Array();
  tideItems['lowtime'] = 'Low Time';
  tideItems['lowtide'] = 'Low Tide';
  tideItems['hightime'] = 'High Time'; 
  tideItems['hightide'] = 'High Tide';

  $.ajax({
	type: "GET",
	url: "/static/accuweather/" + subdir + "tides.xml",
	dataType: "xml",
	success: function(xml) {

	var name;
	var html='';
	var item_name;
	var data;
	$(xml).find('site').each(function (i) {

		TideLocation = $(this).find('name').text();
			
		html = html+'<div class="tideLocation">' +
			    '<div class="tideLocationName">'+TideLocation+'</div>';
	
		$kids = $(this).children().not('name');
		$kids.each(function(i){
			//alert (this.tagName+' '+$(this).text());
			item_name = tideItems[this.tagName];
			data = $(this).text();
			if (this.tagName=='lowtime' || this.tagName=='hightime') { 
				html = html+'<div class="tideItem">'; 
			}
			html = html+item_name+': '+data+'<br />';
			if (this.tagName=='lowtide' || this.tagName=='hightide') { 
				html = html+'</div>'; 
			}
		});
		html = html+'</div>';

	});
	$("#marineForecast #tides").html(html);
    }
  });

});

