var markerArray = new Array(); // array of markers

function setEventsTab(enable, disableArr){
    document.getElementById(enable).style.display = "block";
    document.getElementById(enable + "But").className = "selected nobar";
    for (i = 0; i < disableArr.length; i++) {
        document.getElementById(disableArr[i]).style.display = "none";
        document.getElementById(disableArr[i] + "But").className = "";
    }
}

//<!-- BEGIN WORLD ZOOM CONTROL -->
  function TextualZoomControl() {
  }
  
  // To "subclass" the GControl, we set the prototype object to
  // an instance of the GControl object
  TextualZoomControl.prototype = new GControl();
  
  // Creates a one DIV for each of the buttons and places them in a container
  // DIV which is returned as our control element. We add the control to
  // to the map container and return the element for the map class to
  // position properly.
  TextualZoomControl.prototype.initialize = function(map) {
    var container = document.createElement("div");
  
    var zoomInDiv = document.createElement("div");
    zoomInDiv.setAttribute("title","Zoom in to street level");
    this.setButtonStyle_(zoomInDiv);
    container.appendChild(zoomInDiv);
    zoomInDiv.appendChild(document.createTextNode("StreetZoom"));
    GEvent.addDomListener(zoomInDiv, "click", function() {
      map.setZoom(12);
      map.setMapType(G_NORMAL_MAP);
    });
  
    var zoomOutDiv = document.createElement("div");
    zoomOutDiv.setAttribute("title","Zoom out to world level");
    this.setButtonStyle_(zoomOutDiv);
    container.appendChild(zoomOutDiv);
    zoomOutDiv.appendChild(document.createTextNode("WorldView"));
    GEvent.addDomListener(zoomOutDiv, "click", function() {
      map.setZoom(2);
      map.setMapType(G_PHYSICAL_MAP);
    });
  
    map.getContainer().appendChild(container);
    return container;
  }
  
  // Sets the proper CSS for the given button element.
  TextualZoomControl.prototype.setButtonStyle_ = function(button) {
  	//button.style.textDecoration = "underline";
  	button.style.color = "black";
  	button.style.backgroundColor = "white";
  	button.style.font = "85% Arial";
  	button.style.border = "2px solid black";
  	button.style.padding = "2px";
  	button.style.marginBottom = "3px";
  	button.style.textAlign = "center";
  	button.style.width = "6em";
  	button.style.cursor = "pointer";
  }
  
  
  // By default, the control will appear in the top left corner of the
  // map with 7 pixels of padding.
  TextualZoomControl.prototype.getDefaultPosition = function() {
  	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
  }
  
//<!-- END WORLD ZOOM CONTROL -->

function setupMap(latitude,longitude, type){
    if (GBrowserIsCompatible()) {
		map = ($("sMap") == null) ? new GMap2($("map")) : new GMap2($("sMap"));
		map.setCenter(new GLatLng(latitude, longitude), 2);
		if(type === undefined){
			map.addControl(new GSmallMapControl());
		}else{
			map.addMapType(G_PHYSICAL_MAP);
	  		map.addControl(new GMapTypeControl());
	  		map.addControl(new TextualZoomControl());
	  		var leftBelowTZC = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(19,63));
	  		map.addControl(new GLargeMapControl(), leftBelowTZC);
	  		
			// ====== Restricting the range of Zoom Levels =====
			// Get the list of map types
			var mt = map.getMapTypes();
			// Overwrite the getMinimumResolution() and getMaximumResolution() methods
			for (var i=0; i<mt.length; i++) {
				mt[i].getMinimumResolution = function() {return 2;}
				mt[i].getMaximumResolution = function() {return 17;}
			}
			
			map.setMapType(G_PHYSICAL_MAP);
		}
    }	
}

function showGeo(lat, lang, address, title, id, hash, filename, pageindex, type){
    var icon = new GIcon();
    icon.image = "http://www.wuzthere.com/images/scene_map.png";
    icon.shadow = "http://www.wuzthere.com/images/shadow.png";
    icon.iconSize = new GSize(27.0, 32.0);
    icon.shadowSize = new GSize(44.0, 32.0);
    icon.iconAnchor = new GPoint(13.0, 16.0);
    icon.infoWindowAnchor = new GPoint(13.0, 16.0);
    var marker = new GMarker(new GLatLng(lat, lang), icon);
    markerArray[id] = marker;
    map.addOverlay(marker);
    
    GEvent.addListener(marker, "mouseover", function(){
        if (typeof(pageStart) != "undefined" && (pageindex > pageStart || pageindex < pageStart)) {
            pageindex = parseInt(pageindex / 5) * 5;
            setTimeout("getIndexTab(null, null ," + pageindex + ", 5, true)", 1000);
        }
		showGeoBubble(marker, lat, lang, address, title, id, hash, filename, pageindex, type);
    });
    GEvent.addListener(marker, "click", function(){
        location.href = "view?id=" + id;
    });
	GEvent.addListener(marker, "mouseup", function(){
		showGeoBubble(marker, lat, lang, address, title, id, hash, filename, pageindex, type)
	});
}

function showGeoBubble(marker, lat, lang, address, title, id, hash, filename, pageindex, type){
	var img_src;
	var media_type = 'PIC';
    if (hash == "Facebook") {
        img_src = "<img src=\"" + filename + "\"/>";
	}else{
		img_src = "<img src=\"postimages/" + hash + "/" + filename + "\"/>";
		if (typeof(type) != "undefined" && type=="VID")
			media_type = 'VID';
	}
    var bubble = [];
	bubble[bubble.length] = "<div class=\"bubble\"><div class=\"txt_data\"><div class=\"title\">" + title + "</div>";
	bubble[bubble.length] = "<div class=\"location\">" + address  + "</div>";
	bubble[bubble.length] = "<div class=\"location\"><a href='search?in=" + media_type + "&scnid=" + id + "&lat=" + lat + "&long=" + lang + "&address=" + escape(address) + "'>View more at this location</a></div></div>";
	bubble[bubble.length] = "<div class=\"img_data\" align=\"center\">" + img_src + "</div>";
	bubble[bubble.length] = "<div class=\"clear\"></div></div>";
    marker.openInfoWindowHtml(bubble.join(" "));	
}

function showGeoEvent(lat, lang, address, title, id, hash, filename){
	if(hash.length == 0){
		hash = "../images";
		filename = "placeholder.jpg";
	}
    var icon = new GIcon();
    icon.image = "http://www.wuzthere.com/images/event_map.png";
    icon.shadow = "http://www.wuzthere.com/images/shadow.png";
    icon.iconSize = new GSize(27.0, 32.0);
    icon.shadowSize = new GSize(44.0, 32.0);
    icon.iconAnchor = new GPoint(13.0, 16.0);
    icon.infoWindowAnchor = new GPoint(13.0, 16.0);
    var marker = new GMarker(new GLatLng(lat, lang), icon);
    markerArray[id] = marker;
    map.addOverlay(marker);
    GEvent.addListener(marker, "mouseover", function(){
        showGeoEventBubble(marker, lat, lang, address, title, id, hash, filename);
    });
    GEvent.addListener(marker, "click", function(){
        location.href = "event?id=" + id;
    });
	GEvent.addListener(marker, "mouseup", function(){
		showGeoEventBubble(marker, lat, lang, address, title, id, hash, filename);
	});
}

function showGeoEventBubble(marker, lat, lang, address, title, id, hash, filename){
	var img_src;
	if (hash == "Facebook") {
	    img_src = "<img src=\"" + filename + "\" />";
	}else {
		img_src = "<img src=\"postimages/" + hash + "/" + filename + "\" />";
	}
	var bubble = [];
	bubble[bubble.length] = "<div class=\"bubble\"><div class=\"txt_data\"><div class=\"title\">" + title + "</div>";
	bubble[bubble.length] = "<div class=\"location\">" + address + "</div>";
	bubble[bubble.length] = "<div class=\"location\"><a href='search?in=EVT&evtid=" + id + "&lat=" + lat + "&long=" + lang + "&address=" + escape(address) + "'>View more at this location</a></div></div>";
	bubble[bubble.length] = "<div class=\"img_data\" align=\"center\">" + img_src + "</div>";
	bubble[bubble.length] = "<div class=\"clear\"></div></div>";
	marker.openInfoWindowHtml(bubble.join(" "));
}

function showGeoSceneOnEvent(lat, lang, address, title, id, eid, hash, filename){
    var marker, icon = new GIcon();
    icon.iconSize = new GSize(27.0, 32.0);
    icon.shadowSize = new GSize(44.0, 32.0);
    icon.iconAnchor = new GPoint(13.0, 16.0);
    icon.infoWindowAnchor = new GPoint(13.0, 16.0);
    icon.shadow = "http://www.wuzthere.com/images/shadow.png";
    if (id != 0) {
        icon.image = "http://www.wuzthere.com/images/scene_map.png";
        marker = new GMarker(new GLatLng(lat, lang), icon);
        markerArray[id] = marker;
    }
    else {
        icon.image = "http://www.wuzthere.com/images/event_map.png";
        marker = new GMarker(new GLatLng(lat, lang), icon);
        markerArray[eid] = marker;
    }
    map.addOverlay(marker);
    GEvent.addListener(marker, "mouseover", function(){
		showGeoSceneOnEventBubble(marker, lat, lang, address, title, id, eid, hash, filename);
    });
    GEvent.addListener(marker, "click", function(){
        location.href = "event?id=" + eid + "&sceneid=" + id;
    });
	GEvent.addListener(marker, "mouseup", function(){
		showGeoSceneOnEventBubble(marker, lat, lang, address, title, id, eid, hash, filename);
	});
}

function showGeoSceneOnEventBubble(marker, lat, lang, address, title, id, eid, hash, filename){
	var img_src, search_type;
	if (hash == "Facebook") {
        img_src = "<img src=\"" + filename + "\" />";
   	}else {
        img_src = "<img src=\"postimages/" + hash + "/" + filename + "\" />";
    }
    if (id != 0)
		search_type = "in=PIC&scnid=" + id;
	else
		search_type = "in=EVT&evtid=" + eid;
    var bubble = [];
	bubble[bubble.length] = "<div class=\"bubble\"><div class=\"txt_data\"><div class=\"title\">" + title + "</div>";
	bubble[bubble.length] = "<div class=\"location\">" + address +  "</div>";
	bubble[bubble.length] = "<div class=\"location\"><a href='search?" + search_type + "&lat=" + lat + "&long=" + lang + "&address=" + escape(address) + "'>View more at this location</a></div></div>";
	bubble[bubble.length] = "<div class=\"img_data\" align=\"center\">" + img_src + "</div>";
	bubble[bubble.length] = "<div class=\"clear\"></div></div>";
    marker.openInfoWindowHtml(bubble.join(" "));
}

function convertToXML(text){
	var doc;
    if (document.implementation && document.implementation.createDocument) {
        // code for Mozilla, Firefox, Opera, etc.
        var parser = new DOMParser();
        doc = parser.parseFromString(text, "text/xml");
    }
    else {
        doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async = "false";
        doc.loadXML(text);
    }
	return doc;
}

function xmlPeopleScenesToWindow(xml, window){
	if(typeof(xml) == 'string'){
		xml = convertToXML(xml);
	}
    var sceneItems = xml.getElementsByTagName('user');
    for (var i = 0; i < sceneItems.length; i++) {
        window.innerHTML += "<div class=\"sMediaNode\" onmouseover=\"this.style.background = '#D5DFF3';\" onmouseout=\"this.style.background ='#FDFDFD';\"> <div class=\"thumbnail\"><img src=\"userimages/" + sceneItems[i].getAttribute('id') + ".jpg\" border=\"0\"></div> <div class=\"title\"><A HREF=\"profile.php?id=" + sceneItems[i].getAttribute('id') + "\">" + sceneItems[i].getElementsByTagName('name')[0].childNodes[0].nodeValue + "</a></div> <div class=\"marker\"> <div class=\"left\">At: " + sceneItems[i].getElementsByTagName('time')[0].childNodes[0].nodeValue + "</div> <div class=\"right\">Joined on: " + sceneItems[i].getElementsByTagName('joined')[0].childNodes[0].nodeValue + "</div> </div> <div class=\"clear\"></div> </div>";
    }
}

function xmlScenesToWindow(xml, updateNode, dontredraw, mapType){
	if(typeof(xml) == 'string'){
		xml = convertToXML(xml);
	}
    var sceneItems = xml.getElementsByTagName('scene');
    if (sceneItems && sceneItems.length > 0 && dontredraw != true) {
    	
    	setupMap(sceneItems[0].getElementsByTagName('lat')[0].firstChild.nodeValue, 
    			 sceneItems[0].getElementsByTagName('long')[0].firstChild.nodeValue, mapType);
    }
	
	var sceneIndex = -1, filetype, classType, sourceType, fileLocation, source;
	var index, start, time, views,blurb, address, title, scn_id, lat, lang, sceneItem;
    for (var i = 0; i < sceneItems.length; i++) {
		sceneItem = sceneItems[i];
		index = sceneItem.getAttribute('index');
		start = sceneItem.getAttribute('start');
		sceneIndex = (index && start) ? index : -1;
		filetype = sceneItem.getElementsByTagName('type')[0].firstChild.nodeValue;
		lat = sceneItem.getElementsByTagName('lat')[0].firstChild.nodeValue;
		lang = sceneItem.getElementsByTagName('long')[0].firstChild.nodeValue;
		type = sceneItem.getElementsByTagName('type')[0].firstChild.nodeValue;
		scn_id = sceneItem.getAttribute('id');
		title = sceneItem.getElementsByTagName('title')[0].firstChild.nodeValue;
		if(title.length > 34){
			title = title.substring(0,32) + "...";
		}
		address = sceneItem.getElementsByTagName('address')[0].firstChild.nodeValue;
		blurb = sceneItem.getElementsByTagName('blurb')[0].firstChild.nodeValue;
		if(blurb.length > 60){
			blurb = blurb.substring(0,57) + "...";
		}
		views = sceneItem.getElementsByTagName('numviews')[0].firstChild.nodeValue;
		time = sceneItem.getElementsByTagName('time')[0].firstChild.nodeValue;
		classType = ($("sMap") == null) ? "mediaNode" : "sMediaNode";
		
		if (filetype == "PIC") 
			filetype = "<img style=\"border:none;vertical-align:middle;\" alt=\"[image]\" src=\"images/image.png\"/> ";
		else 
			filetype = "<img style=\"border:none;vertical-align:middle;\" alt=\"[video]\" src=\"images/video.gif\"/> ";
		
		
		if (sceneItem.getElementsByTagName('webaddress')[0].childNodes.length > 0) {
			sourceType = "Facebook";
			fileLocation = sceneItem.getElementsByTagName('webaddress')[0].firstChild.nodeValue;
		}
		else {
			sourceType = sceneItem.getElementsByTagName('hash')[0].firstChild.nodeValue;
			fileLocation = sceneItem.getElementsByTagName('filename')[0].firstChild.nodeValue;
		}
		
		if (!sceneItem.getAttribute('limit') || i < sceneItem.getAttribute('limit')) {
			source = (sourceType === "Facebook") ? fileLocation : ("postimages/" + sourceType + "/" + fileLocation);
			var output = [];
			output[output.length] = "<div class=\"" + classType + "\" onmouseover=\"this.style.background= '#D5DFF3';\" onmouseout=\"this.style.background='#FDFDFD';\" onclick=\"sceneFocus(" + lat + ", " + lang + ", " + scn_id + ");\"> ";
			output[output.length] = "<div class=\"thumbnail\"><img src=\"" + source + "\" border=\"0\"></div>";
			output[output.length] = "<div class=\"title\"><a href=\"view?id=" + scn_id + "\">" + filetype + title + "</a></div>";
			output[output.length] = "<div class=\"description\"><i>" + address + "</i><br />" + blurb + "</div>";
			output[output.length] = "<div class=\"marker\"><div class=\"left\">Views: " + views + "</div>";
			output[output.length] = "<div class=\"right\">Posted on: " + time + "</div></div><div class=\"clear\"></div></div>";
			updateNode.innerHTML += output.join(" ");
		}
		if (dontredraw != true) {
			showGeo(lat, lang, address, title, scn_id, sourceType, fileLocation, sceneIndex, type);
		}
	}
	
    if ($("mediaPager") && sceneItems.length > 0) {
        var mediaPlayerText = "<ul>";
        if ((pageStart / 5) + 1 + 2 <= Math.ceil((sceneItems[0].getElementsByTagName('count')[0].childNodes[0].nodeValue - 0) / 5)) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, " + ((Math.ceil((sceneItems[0].getElementsByTagName('count')[0].childNodes[0].nodeValue - 1) / 5) - 1) * 5) + "); return false;\">>></a></li>";
        if ((pageStart / 5) + 1 + 1 <= Math.ceil((sceneItems[0].getElementsByTagName('count')[0].childNodes[0].nodeValue - 0) / 5)) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, " + (pageStart + 5) + "); return false;\">></a></li>";
        if ((pageStart / 5) + 1 + 1 <= Math.ceil((sceneItems[0].getElementsByTagName('count')[0].childNodes[0].nodeValue - 0) / 5)) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, " + (pageStart + 5) + "); return false;\">" + ((pageStart / 5) + 1 + 1) + "</a></li>";
        
		mediaPlayerText += "<li class=\"selected\"><a href=# onclick=\"getIndexTab(null, null, (pageStart)); return false;\">" + (Math.ceil(pageStart / 5) + 1) + "</a></li>";
        
		if (pageStart > 0) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, (pageStart -5 )); return false;\">" + ((pageStart / 5)) + "</a></li>";
        if (pageStart > 0) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, (pageStart -5 )); return false;\"><</a></li>";
        if (pageStart > 5) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, 0); return false;\"><<</a></li>";
        mediaPlayerText += "</ul>";
        $("mediaPager").innerHTML = mediaPlayerText;
    }
}

function xmlEventsToWindow(xml, updateNode, type, uid, evt, mapType){
	if(typeof(xml) == 'string'){
		xml = convertToXML(xml);
	}
    var sceneItems = xml.getElementsByTagName('event'), sceneItem;
    if (sceneItems && sceneItems.length > 0) {
    	setupMap(sceneItems[0].getElementsByTagName('lat')[0].firstChild.nodeValue, 
    			 sceneItems[0].getElementsByTagName('long')[0].firstChild.nodeValue, mapType);
    }
    if (sceneItems.length == 0) {
        updateNode.innerHTML = "<b>There is no media. Please try another tab or click Add Your Media to add some media to this event</b>";
    }
    
    var url, hash, filename, webaddress, filetype, lat, lang, scn_id, evt_id, title, address, blurb, views, time, output, margin;
    for (var i = 0; i < sceneItems.length; i++) {
    	
    	sceneItem = sceneItems[i]; output = []; 
    	hash = sceneItem.getElementsByTagName('hash')[0].firstChild.nodeValue;
    	filename = sceneItem.getElementsByTagName('filename')[0].firstChild.nodeValue;
        lat = sceneItem.getElementsByTagName('lat')[0].firstChild.nodeValue;
        lang = sceneItem.getElementsByTagName('long')[0].firstChild.nodeValue;
        scn_id = sceneItem.getAttribute('sceneid');
        evt_id = sceneItem.getAttribute('id');
        title = sceneItem.getElementsByTagName('title')[0].firstChild.nodeValue;
        if(title.length > 34){
			title = title.substring(0,32) + "...";
		}
        address = sceneItem.getElementsByTagName('address')[0].firstChild.nodeValue;
        blurb = sceneItem.getElementsByTagName('blurb')[0].firstChild.nodeValue;
        if(blurb.length > 60){
			blurb = blurb.substring(0,57) + "...";
		}
        views = sceneItem.getElementsByTagName('numviews')[0].firstChild.nodeValue;
        time = sceneItem.getElementsByTagName('time')[0].firstChild.nodeValue;
        
        if (sceneItem.getElementsByTagName('webaddress')[0].childNodes.length > 0){ 
            url = sceneItem.getElementsByTagName('webaddress')[0].firstChild.nodeValue
            hash = "Facebook";
            filename = url;
            margin = "style=\"margin-top:-59px\"";
        }else{
        	url = "postimages/" + hash + "/" + filename;
        	margin = "style=\"margin-top:-40px\"";
        }	
        if (sceneItem.getElementsByTagName('type').length > 0) {
            filetype = sceneItem.getElementsByTagName('type')[0].firstChild.nodeValue;
            if (filetype == "PIC") 
                filetype = "<img style=\"border:none;vertical-align:middle;\" alt=\"[image]\" src=\"images/image.png\"/> ";
            else 
                filetype = "<img style=\"border:none;vertical-align:middle;\" alt=\"[video]\" src=\"images/video.gif\"/> ";
        }
        
        if ((type == "SME" || type == "OTH") && uid != 0){
			output[output.length] = "<div class=\"sMediaNode\" onclick=\"sceneFocus(" + lat + ", " + lang + ", " + scn_id + ");\" onmouseover=\"this.style.background='#D5DFF3';\" onmouseout=\"this.style.background='#FDFDFD';\">";
        	output[output.length] = "<div class=\"thumbnail\"><img src=\"" + url + "\" border=\"0\">";
        	output[output.length] = "<div "+margin+"><a title=\"Set as default media\" onclick=\"setSceneToEvent(" + evt + ", " + scn_id + "); return false;\">";
        	output[output.length] = "<img src=\"images/default.gif\" onmouseover=\"this.src='images/default_hover.gif'\" onmouseout=\"this.src='images/default.gif'\"/></a></div></div>";
        	output[output.length] = "<div class=\"title\"><a href=\"event?id=" + evt_id + "&sceneid=" + scn_id + "\">" + filetype + title + "</a></div>";
        	output[output.length] = "<div class=\"description\"> <i>" + address + "</i> <br /> " + blurb + " </div>";
        	output[output.length] = "<div class=\"marker\"> <div class=\"left\">Views: " + views + "</div> <div class=\"right\">Posted on: " + time + "</div> </div>";
        	output[output.length] = "<div class=\"clear\"></div> </div>";
            updateNode.innerHTML += output.join(" ");
        }else {
        	var svar = ($("sMap") == null) ? "mediaNode" : "sMediaNode";
			var focusId = (scn_id != "" && scn_id != 0)? scn_id : evt_id;
			output[output.length] = "<div class=\"" + svar + "\" onclick=\"sceneFocus(" + lat + "," + lang + "," + focusId + ");\" onmouseover=\"this.style.background = '#D5DFF3';\" onmouseout=\"this.style.background ='#FDFDFD';\">";
			output[output.length] = "<div class=\"thumbnail\"><img src=\"" + url + "\" border=\"0\"></div> ";
			output[output.length] = "<div class=\"title\"><a href=\"event?id=" + evt_id + "&sceneid=" + scn_id + "\">" + title + "</a></div>";
			output[output.length] = "<div class=\"description\"> <i>" + address + "</i> <br /> " + blurb + " </div> ";
			output[output.length] = "<div class=\"marker\"> <div class=\"left\">Views: " + views + "</div> <div class=\"right\">Posted on: " + time + "</div> </div> ";
			output[output.length] = "<div class=\"clear\"></div> </div>";
            updateNode.innerHTML += output.join(" ");
        }
		showGeoSceneOnEvent(lat, lang, address, title, scn_id, evt_id, hash, filename);
    }
    if (document.getElementById("mediaPager") && sceneItems.length > 0) {
        var mediaPlayerText = "<ul>";
        if ((pageStart / 5) + 1 + 2 <= Math.ceil(sceneItems[0].getElementsByTagName('count')[0].firstChild.nodeValue / 5)) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, " + ((Math.ceil(sceneItems[0].getElementsByTagName('count')[0].firstChild.nodeValue / 5) - 1) * 5) + "); return false;\">>></a></li>";
        if ((pageStart / 5) + 1 + 1 <= Math.ceil(sceneItems[0].getElementsByTagName('count')[0].firstChild.nodeValue / 5)) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, " + (pageStart + 5) + "); return false;\">></a></li>";
        mediaPlayerText += "<li class=\"selected\"><a href=# onclick=\"getIndexTab(null, null, (pageStart)); return false;\">" + (Math.ceil(pageStart / 5) + 1) + "</a></li>";
        if (pageStart > 0) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, (pageStart -5 )); return false;\"><</a></li>";
        if (pageStart > 5) 
            mediaPlayerText += "<li><a href=# onclick=\"getIndexTab(null, null, 0); return false;\"><<</a></li>";
        mediaPlayerText += "</ul>";
        document.getElementById("mediaPager").innerHTML = mediaPlayerText;
    }
}

function addSceneToEvent(event, scene, uid, refresh_type){
	var xhr = new Ajax("ajaxaddsceneevent.php", {
    	method: 'get',
        data: Object.toQueryString({'scene': scene,'event': event}),
        update: null,
        onComplete: function(text, xml){
        	getEventsTab(refresh_type, event, scene, uid);
        }
	});
    xhr.request();
}

function setSceneToEvent(event, scene){
	var xhr = new Ajax("ajaxsetsceneevent.php", {
    	method: 'get',
        data: Object.toQueryString({'scene': scene,'event': event}),
        update: null,
        onComplete: function(text, xml){
        	location.href = "event?id=" + event;
        }
	});
    xhr.request();
}

function findPos(obj){
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
    }
    return [curleft, curtop];
}

function toggleShare(obj){
    var position = findPos(obj);
    var di = document.getElementById("sharepopup");
    di.style.left = position[0] + 'px';
    di.style.top = position[1] * 1 + 20 * 1 + 'px';
    if (di.style.visibility == "visible") 
        di.style.visibility = "hidden";
    else 
        di.style.visibility = "visible";
}

function toggleWuzThere(obj){
    var position = findPos(obj);
    var di = document.getElementById("wuztherepopup");
    di.style.left = position[0] + 'px';
    di.style.top = position[1] * 1 + 20 * 1 + 'px';
    if (di.style.visibility == "visible") 
        di.style.visibility = "hidden";
    else 
        di.style.visibility = "visible";
}

function sceneFocus(lat, lang, id){
    map.setCenter(new GLatLng(lat, lang));
    GEvent.trigger(markerArray[id], 'mouseup');
}

function centerMap(input){
    setCookie("startaddress", input);
    centerTheMap(input);
}

function setCookie(c_name, value, expiredays){
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name){
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) 
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return ""
}

function centerTheMap(address){
    var center_request = false;
    if (window.XMLHttpRequest) {
        center_request = new XMLHttpRequest();
        if (center_request.overrideMimeType) {
            center_request.overrideMimeType('text/html');
            // See note below about this line
        }
    }
    else 
        if (window.ActiveXObject) {
            try {
                center_request = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    center_request = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {
                }
            }
        }
    if (!center_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    center_request.onreadystatechange = function(){
        if (center_request.readyState == 4) {
            if (center_request.status == 200) {
                addressArray = center_request.responseText.split(",");
                if (addressArray[0] == "200") {
                    map.setCenter(new GLatLng(addressArray[1], addressArray[2]), 12);
                }
            }
            else {
                alert('There was a problem with the request.');
            }
        }
    }
    center_request.open('GET', 'getaddress.php?address=' + escape(address), true);
    center_request.send(null);
}
