$(document).ready(function() {
	build_calendar();
	build_map();	
});

function build_calendar() {
	 if($("body").attr("id") == "calendar") { 
	 
	 //take the day from the class in the body tag and subtract 1 to deal with array starting at 0
	 var adjusted_current_day = ($('body').attr("class").split("-")[1]) - 1;
	
	 $.getJSON("/cgi-bin/WebObjects/ElectricDecember.woa/wa/calendarJSONData?year=07",
	   function(json){
			list = $("ol#calendar-list li")
			for(i=0;i<list.length;i++) {
				list[i].title = json.data[i].title;
				list[i].description = json.data[i].description;
				list[i].image = json.data[i].image
				list[i].contributer = json.data[i].contributer;
				list[i].day = i+1;
				list[i].onmouseover = function() {
					if(sIFR.callbacks.length == 0) {
						$("#day").html('Day <span class="pink">'+this.day+'</span>')
					}
					else {
						sIFR.callbacks['.day-project h2, .content-block h1'][0].replaceText('Day <span class="pink">'+this.day+"</span>");
					}
					$("div.day-project p").html(this.description);
					$("#contributer").html(this.contributer);
					$("div#project-meta h3 a").html(this.title);
					$("div#project-meta img").attr({src:this.image});
				}
				
				list[i].onmouseout= function() {
					if(sIFR.callbacks.length == 0) {
						$("#day").html('Day <span class="pink">'+$('body').attr("class").split("-")[1]+'</span>')
					}
					else {
						sIFR.callbacks['.day-project h2, .content-block h1'][0].replaceText('Day <span class="pink">'+$('body').attr("class").split("-")[1]+"</span>");
					}
						
					$("div.day-project p").html(json.data[adjusted_current_day].title);
					$("#contributer").html(json.data[adjusted_current_day].contributer);
					$("div#project-meta h3 a").html(json.data[adjusted_current_day].title);
					$("div#project-meta img").attr({src:json.data[adjusted_current_day].image});
				}
		}

	   }
	  );
	}
}

function build_map() {
	if($("body").attr("id") == "present") {
		
	//take the day from the class in the body tag and subtract 1 to deal with array starting at 0
	var adjusted_current_day = ($('body').attr("class").split("-")[1]) - 1;
	  
	$.getJSON("/07/json/locations",
	   function(json){
			
			if (GBrowserIsCompatible()) {
					lat = json.data[adjusted_current_day].lat
					lng = json.data[adjusted_current_day].lng
					point = new GLatLng(lat, lng)
					
			        var map = new GMap2(document.getElementById("map"));
			        //map.setCenter(point, 18);
			        map.setCenter(point, 6);
					map.setMapType(G_SATELLITE_MAP);
					
					var icon = new GIcon();
			        icon.image = "/07/images/ed-map-icon.png";
			     	icon.iconSize = new GSize(30, 30);
			     	icon.iconAnchor = new GPoint(10,13);
			        var marker = new GMarker(point, icon);
			        map.addOverlay(marker);
			    }
			}

	   
	  );
	}
}

function init(){
    var iBase = TextResizeDetector.addEventListener( onFontResize,null );
  	// alert( "The base font size = " + iBase );
}
function onFontResize( e, args ){
    window.location.reload();
}
// id of element to check for and insert control
TextResizeDetector.TARGET_ELEMENT_ID = 'screen';
// function to call once TextResizeDetector has init'd
TextResizeDetector.USER_INIT_FUNC = init;