/*********************************************************************
 * DOJO editing stuff
 *********************************************************************/
var editors = {};
function addEditor(myid,mykey){
	var editorArgs = {
    	items: ["bold", "italic", "underline"]
	};
	editors[mykey+myid] = dojo.widget.createWidget("Editor2", editorArgs,document.getElementById(mykey + 'edit'+ myid));
}

function getEditorData(myid,mykey){
	if(editors[mykey+myid] != undefined && editors[mykey+myid] != null){
		retData = editors[mykey+myid].getEditorContent();
		editors[mykey+myid] = null;
		return retData;
	}else{
		alert('Could not get editor for key: '+ mykey +' ,id: ' + myid);
	}
}


//switches between the tabs
var ctab = null;
function pSwitchTab(tab){
	$('plocation').style.display = 'none';
	$('pdescription').style.display = 'none';
	$('pimages').style.display = 'none';
	
	$('p'+tab).style.display = 'block';
	if(tab == 'location') setTimeout(doMap,100);
	ctab = tab;
}

function checkTab(){
	if(ctab != null){
		pSwitchTab(ctab);
	}else{
		setTimeout(doMap,300)
	}
}

/*********************************************************************
 * Google maps stuff
 * *******************************************************************/
//create icons
var oicon = new GIcon();
oicon.image = "images/gicon.png";
oicon.shadow = "images/gsicon.png";
oicon.iconSize = new GSize(70, 52);
oicon.shadowSize = new GSize(70, 52);
oicon.iconAnchor = new GPoint(35, 51);
oicon.infoWindowAnchor = new GPoint(26, 1);

var icon = new GIcon();
icon.image = "images/gselicon.png";
icon.shadow = "images/gsselicon.png";
icon.iconSize = new GSize(70, 52);
icon.shadowSize = new GSize(70, 52);
icon.iconAnchor = new GPoint(35, 51);
icon.infoWindowAnchor = new GPoint(26, 1);

// Creates a marker at the given point with the given number label
function createMarker(point, sitid,ico) {
  var marker = new GMarker(point,ico);
  GEvent.addListener(marker, "click", function() {
  		if(sitid > 0){
 			window.location = "property.php5?site=" + sitid;
		}
  });
  return marker;
}

function drawMap(elem,lat,lng,sitid){
	map = new GMap2($(elem));
	//add controls
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());

	//do markers
	siteMarker = new GLatLng(lat,lng);
	map.setCenter(siteMarker, 13);

	//add marker for current site
	map.addOverlay(createMarker(siteMarker,sitid,icon));
	for(var n in maps){
		if(maps[n]['lat'] != lat && maps[n]['lng'] != lng){
			var point = new GLatLng(maps[n]['lat'],maps[n]['lng']);
			map.addOverlay(createMarker(point,maps[n]['sitid'],oicon));
		}
	}
	map.load();
}
/*********************************************************************
 * End of Google maps stuff
 * *******************************************************************/
