/*  File: So Smooth Basketball JS
    Author: Ife Okwumabua - Copyright 2008	*/


//<![CDATA[
	var map;
	var geocoder;
	var address = "";
	var locationsOfInterest = new Array();
		//49.916508, -97.207881
		locationsOfInterest[0] = ({ name: 'Red River College (North Gym)', url: "", address: "2055 Notredame Avenue", logo: "images/logos/so-smooth-small.gif", city: "Winnipeg, Manitoba", sponsor: '', point: "", marker: "" , markerUp: "" });
	var locationIndex = 0;
	var stuffOfThings= new Array();
	var locationOfInterestObj;

	
	function createMarker(point, content) {     // Creates a marker at the given point with the given number label
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(content.toString());
	  });
	  return marker;
	}
	
	function createMarkerContent (activeIndex) {
	    //alert("Attempting to create a marker for activeIndex" + activeIndex);
	    return ('<div class="alignCenter"><img src="' + locationsOfInterest[activeIndex].logo + '" alt="' + locationsOfInterest[activeIndex].name + '" class="logo" /><div class="details"><b>' + locationsOfInterest[activeIndex].name + '</b><br />' + locationsOfInterest[activeIndex].address + '<br />' + locationsOfInterest[activeIndex].city + "</div></div>");
	}
	
	function addToMap(response) {
	  //alert ("response.Placemark.length = " + response.Placemark.length);
	  if (response.Placemark.length > 0) {
//	  	prompt("google points value = ", (response.Placemark[0].Point.coordinates[1] + ", " + response.Placemark[0].Point.coordinates[0]) );
	          locationsOfInterest[0].point = new GLatLng(49.916508, -97.207881);// response.Placemark[0].Point.coordinates[1], response.Placemark[0].Point.coordinates[0]);                              // Retrieve the latitude and longitude
	          locationsOfInterest[0].markerUp = createMarkerContent(0);
	          locationOfInterest = new GMarker(locationsOfInterest[0].point);
	          map.addOverlay( locationOfInterest );
	          locationOfInterestObj = locationOfInterest;
	          GEvent.addListener(locationOfInterest, "click", function() { locationOfInterest.openInfoWindow(locationsOfInterest[0].markerUp); });
	          locationOfInterest.openInfoWindow( locationsOfInterest[0].markerUp.toString() ); 
	  	  //locationIndex++;
	  }
	}

	function loadGoogleMap() {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById('map'));                                // Load DOM object into variable
			geocoder = new GClientGeocoder();                                               // Create new geocoding object
			if (locationsOfInterest.length > 0) {
				locationArray = new Array();
				for (x = 0; x < locationsOfInterest.length; x++) {
					geocoder.getLocations( (locationsOfInterest[x].address + ", " + locationsOfInterest[x].city), addToMap);               // Retrieve location information, pass it to addToMap()
				}
			}
			centerCoOrdinates = new GLatLng(49.9205592, -97.2095203);
			map.setCenter(centerCoOrdinates, 15);
			map.setZoom(15);
			map.addControl(new GLargeMapControl());
			map.setMapType(G_HYBRID_MAP);
		}
	}

	function initAccordion() {
		var accordion = new Accordion('h2.sessionTitle', 'div.sessionDetail', {
			opacity: false,
			onActive: function(toggler, element){
				//toggler.setStyle('color', '#ff3300');
				toggler.addClass("inFocus");
				updateSession((toggler.className.match("ballers")?"ballers":""));
			},
			onBackground: function(toggler, element){
				//toggler.setStyle('color', '#222');
				toggler.removeClass("inFocus");
			}
		}, $('sessionDescriptions'));
		
		/*var secondAccordion = new Accordion('h2.staffName', 'div.staffInfo', {
			opacity: false,
			onActive: function(toggler, element){
				//toggler.setStyle('color', '#ff3300');
				toggler.addClass("inFocus");
				//updateSession((toggler.className.match("ballers")?"ballers":""));
			},
			onBackground: function(toggler, element){
				//toggler.setStyle('color', '#222');
				toggler.removeClass("inFocus");
			}
		}, $('staffMembers'));*/
	}

	function resetMap() {           // special case: remove all markers (removeOverlays will remove paths as well)
	    var marker = map.getFirstMarker();
	    while (marker != null) {
	        marker.remove();    
	        marker = map.getFirstMarker();
	    }
	    if (locationsOfInterest.length > 0) {               // If there is a list of locations, always include the default(initial one)
	        geocoder.getLocations(locationsOfInterest[0].address, addToMap);
	    }
	}

//49.916508, -97.207881
	function changeContent(selfObj) {
		toggleObj = $(selfObj.id + "Area");
		//alert("toggleObj.id = " + toggleObj.id + ", activeContentArea = " + activeContentArea );
		if (activeContentArea != toggleObj.id) {
			if ( toggleObj.className != "" ) {
				toggleObj.removeClass("hideMe");
				if ( activeContentArea ) {
					$(activeContentArea).addClass("hideMe");
					$( activeContentArea.replace('Area','') ).removeClass("active");
				}
				if (selfObj.id == "location") {
					//alert("doing my thing for that thing" + centerCoOrdinates);
					//$('map').style.width = "800px";
					//$('map').style.height = "400px";
					//funk = new GMap2(document.getElementById('map'))
					if (!googleMapInitiated) {
						loadGoogleMap();
						//map.panTo(centerCoOrdinates);
						googleMapInitiated = true;
					}
				}
			   } else {
				toggleObj.addClass("hideMe");
			}
			$(selfObj.id).addClass("active");
		}
		activeContentArea = toggleObj.id;
		return false;
	}
	var activeContentArea = "summaryArea";
		
	function log(state) {
		if (state) {
			$("splash").addClass("hideMe");
			$("contentContainer").removeClass("hideMe");
		   } else {
			$("splash").removeClass("hideMe");
			$("contentContainer").addClass("hideMe");
			
		}
		return false;
	}

		function toggleCalendarView() {
			if (!calendarContainerObj) {
				calendarContainerObj = $('calendarContainer');
			}
			if ( calendarContainerIsFullScreen ) {
				calendarContainerObj.removeClass("fullscreen");
				calendarContainerObj.addClass("compact");
				calendarContainerIsFullScreen = false;
			   } else {
				calendarContainerObj.removeClass("compact");
				calendarContainerObj.addClass("fullscreen");
				calendarContainerIsFullScreen = true;
			}
			//alert("calendarContainerObj.className = " + calendarContainerObj.className);
		}
		var calendarContainerObj;
		calendarContainerIsFullScreen = true;

		function showHide(selfObj, targetAddon) {
			targetObj = $(selfObj.id + targetAddon);
			if (targetObj) {
				if (targetObj.className.test("hideMe")) {
					targetObj.removeClass("hideMe");
				   } else {
					targetObj.addClass("hideMe");
				}
				if (targetObj.id.test("expenseTotals")) {
					if (targetObj.className.test("hideMe")) {
						selfObj.innerHTML = "show details";
					   } else {
						selfObj.innerHTML = "hide details";
					}
				}
			}
			//return false;
			return true;
		}

		function updateSession(name) {
			targetObj = $('sessionCalendar');
			if (name.test("ballers")) {
				targetObj.addClass("ballerSession");
			   } else {
				targetObj.removeClass("ballerSession");
			}
			return false;
		}
