var total_curr_tab = -1;
function showRoute(){
	is_show_route = document.getElementById('show_route').checked?1:0;
	if(is_show_route==1){
		if(path.length > 1){
			map.removeOverlay(path_overlay);
			path_overlay = new GPolyline(path);
			map.addOverlay(path_overlay);
		}
	}else{
		if(path_overlay){
			map.removeOverlay(path_overlay);
		}
	}
}
function showRedRoute(){
	is_show_red_route = document.getElementById('show_red_route').checked?1:0;
	if(is_show_red_route==1){
		if(path_red.length > 1){
			map.removeOverlay(path_red_overlay);
			path_red_overlay = new GPolyline(path_red);
			map.addOverlay(path_red_overlay);
		}
	}else{
		if(path_red_overlay){
			map.removeOverlay(path_red_overlay);
		}
	}
}
function openTourInfoWindow(marker,edit_save,curr_tab){
	total_curr_tab = curr_tab;
	current_marker = marker;
    var tab1 = new GInfoWindowTab('Stage','<div align=center class=tinyblack >' +
                '<span class=\"style10\">' + current_marker.days + '</span><br>' +current_marker.desc1);
    var tab2 = new GInfoWindowTab('Other details','<div align=center class=tinyblack >' + current_marker.desc2);
    var tabs = new Array(tab1,tab2);
    marker.openInfoWindowTabsHtml(tabs,{maxWidth:max_width,selectedTab:curr_tab});
}
function openLocationInfoWindow(marker){
	marker.openInfoWindowHtml('<div align="center">' + marker.desc1 + '<br></div>');
}
function createTourMarker(point,order,days,desc1,desc2){
	icon.image = "http://labs.google.com/ridefinder/images/mm_20_orange.png";
    var marker = new GMarker(point,icon);
	marker.order = order;
	marker.days = parseTagsToHtml(days?days:'Day: 0');
	marker.desc1 = parseTagsToHtml(desc1);
	marker.desc2 = parseTagsToHtml(desc2);
	path[marker.order] = point;
	
	map.addOverlay(marker);

	GEvent.addListener(marker,'click', function(){
        openTourInfoWindow(marker,'Edit',0);
	});
	    
	if(path.length > 1 && is_show_route==1){
		map.removeOverlay(path_overlay);
		path_overlay = new GPolyline(path);
		map.addOverlay(path_overlay);
	}
		
    return marker;
}
function createLocationMarker(point,desc1,title,seo_url){
	icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    var marker = new GMarker(point,{icon:icon,title:title});
	marker.desc1 = parseTagsToHtml(desc1);
	path_red.push(point);
	
	map.addOverlay(marker);

	GEvent.addListener(marker,'click', function(){
		if(seo_url){
			document.location.href = seo_url;
		}
        //openLocationInfoWindow(marker);
		current_marker = null;
	});
	if(path_red.length > 1 && is_show_red_route==1){
		map.removeOverlay(path_red_overlay);
		path_red_overlay = new GPolyline(path_red,'#ff0000');
		map.addOverlay(path_red_overlay);
	}   
    return marker;
}
function initialiseMap(){
    map = new GMap2(document.getElementById("map"));
    // map.addControl(new GLargeMapControl());
    map.addControl(new GSmallMapControl());
    // map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(14,14),1);
    icon = new GIcon();
	icon.image = "http://labs.google.com/ridefinder/images/mm_20_orange.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);
    
	//is_show_route = document.getElementById('show_route').checked?1:0;
	//is_show_red_route = document.getElementById('show_red_route').checked?1:0;
}