/*******************************************************************
********************************************************************/
// GRAPHICS CODE
// Copyright 2007-2008 Collaborative Bike Map Project
/*******************************************************************
********************************************************************/

/*******************************************************************
********************************************************************/
// COLOR STUFF
/*******************************************************************
********************************************************************/

// Constants used in polyline bi-color combinations 
// Each color value occupies 8 bits within a combination value (rightmost used first) 
var CC_INVALID = 0;
var CC_GREEN = 1;
var CC_BLUE = 2;
var CC_RED = 3; 
var CC_PURPLE = 4;
var CC_YELLOW = 5;
var CC_ORANGE = 6;
var CC_MAGENTA = 7;
var CC_BROWN = 8;
var CC_GRAY = 9;
var CC_WHITE = 10;
var CC_BLACK = 11;
var CC_LTGREEN = 12;
var CC_LTBLUE = 13;
var CC_MAXCOLOR = 13;
var CC_BLUE_GREEN = (CC_BLUE * 256) + CC_GREEN;
var CC_BLUE_BROWN = (CC_BLUE * 256) + CC_BROWN;
var CC_BLUE_LTGREEN = (CC_BLUE * 256) + CC_BROWN;
var CC_RED_GREEN = (CC_RED * 256) + CC_GREEN;
var CC_RED_BROWN = (CC_RED * 256) + CC_BROWN;
var CC_RED_LTGREEN = (CC_RED * 256) + CC_BROWN;
var CC_LTBLUE_GREEN = (CC_RED * 256) + CC_BROWN;
var CC_LTBLUE_BROWN = (CC_RED * 256) + CC_BROWN;
var CC_LTBLUE_LTGREEN = (CC_BLUE * 256) + CC_BROWN;
// Sidepath = green
// Separated path = light green
// None = red
// Road = blue
// Sidewalk = brown
// Bike lanes = light blue
// Zip route = purple

var ColorsObject = new Colors;

/****************************************************************/
// Colors object for mapping bi-color constants to actual colors
/****************************************************************/
function Colors () {
	// debugger;
	this.colorarray = new Array ();	
	/* this.colorarray.push (null);
	this.colorarray.push ("#009933");
	this.colorarray.push ("#0000ff");
	this.colorarray.push ("#ff0000");
	this.colorarray.push ("#660099");
	this.colorarray.push ("#ffff00");
	this.colorarray.push ("#0f0000");
	this.colorarray.push ("#f404c5");
	this.colorarray.push ("#993300");
	this.colorarray.push ("#999999");
	this.colorarray.push ("#ffffff");
	this.colorarray.push ("#000000");
	this.colorarray.push ("#00e100");
	this.colorarray.push ("#000088"); */ 
//	for (i=0; i<20; i++) 
//		this.colorarray.push (null);
	this.colorarray[CC_INVALID] = null;
	this.colorarray[CC_GREEN] = "#007726";
	this.colorarray[CC_BLUE] = "#0000ff";
	this.colorarray[CC_RED] = "#ff0000";
	this.colorarray[CC_PURPLE] = "#660099";
	this.colorarray[CC_YELLOW] = "#ffff00";
	this.colorarray[CC_ORANGE] = "#0f0000";
	this.colorarray[CC_MAGENTA] = "#f404c5";
	this.colorarray[CC_BROWN] = "#993300";
	this.colorarray[CC_GRAY] = "#999999";
	this.colorarray[CC_WHITE] = "#ffffff";
	this.colorarray[CC_BLACK] = "#000000";
	this.colorarray[CC_LTGREEN] = "#00e100";
	this.colorarray[CC_LTBLUE] = "#000088"; 
}

/****************************************************************/
// Get first color value for given bi-color constant.
/****************************************************************/
Colors.prototype.getColorValue1 = function (colorcombo) {
	var i = colorcombo & 255;
	var v = this.colorarray[i];
	return v;
	// return (this.colorarray[colorcombo & "#FF"]);	
}

/****************************************************************/
// Get second color value for given bi-color constant
// Returns null if there is no second color.
/****************************************************************/
Colors.prototype.getColorValue2 = function (colorcombo) {
	var i = (colorcombo & 65280) >> 8;
	var v = this.colorarray[i];
	return v;
	// 65280
	// return (this.colorarray[colorcombo & "#FF00"]);	
}

/*******************************************************************
********************************************************************/
// CREATE ALL THE MARKER ICONS
/*******************************************************************
********************************************************************/
function createCustomMarkers () {
	// Create custom markers
	Iconset = new Object();
	
	// Big red
	Iconset.red = new GIcon(G_DEFAULT_ICON);
	// Big blue 
	Iconset.blue = new GIcon(G_DEFAULT_ICON);    // size of default icon = 20 x 34; anchor = (9, 34)
	Iconset.blue.image = "markers/blue.png";      // http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png
	// Big red transparent 
	Iconset.yellowtrans = new GIcon(G_DEFAULT_ICON);
	Iconset.yellowtrans.image = "markers/yellow-transp.png";
	// Big yellow 
	Iconset.yellow = new GIcon(G_DEFAULT_ICON);
	Iconset.yellow.image = "markers/yellow-trans.png";   // "http://www.google.com/intl/en_us/mapfiles/ms/micons/yellow.png, clipped to 20x34";

	// Little red 
	Iconset.redlit = new GIcon();
	Iconset.redlit.image = "markers/redlit.png"       // "http://labs.google.com/ridefinder/images/mm_20_red.png";
	Iconset.redlit.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	Iconset.redlit.iconSize = new GSize(12, 20);
	Iconset.redlit.shadowSize = new GSize(22, 20);
	Iconset.redlit.iconAnchor = new GPoint(6, 20);
	Iconset.redlit.infoWindowAnchor = new GPoint(5, 1);
	// Little blue 
	Iconset.bluelit = new GIcon(Iconset.redlit);
	Iconset.bluelit.image = "markers/bluelit.png";
	// Little green 
	Iconset.greenlit = new GIcon(Iconset.redlit);
	Iconset.greenlit.image = "markers/greenlit.png";
	// Little dark green 
	Iconset.dkgreenlit = new GIcon(Iconset.redlit);
	Iconset.dkgreenlit.image = "markers/dkgreenlit.png";
	// Little yellow 
	Iconset.yellowlit = new GIcon(Iconset.redlit);
	Iconset.yellowlit.image = "markers/yellowlit.png";
	// Little orange 
	Iconset.orangelit = new GIcon(Iconset.redlit);
	Iconset.orangelit.image = "markers/orangelit.png";
	// Little purple 
	Iconset.purplelit = new GIcon(Iconset.redlit);
	Iconset.purplelit.image = "markers/purplelit.png";
	// Little magenta 
	Iconset.magentalit = new GIcon(Iconset.redlit);
	Iconset.magentalit.image = "markers/magentalit.png";
	// Little red transparent 
	Iconset.redlittrans = new GIcon(Iconset.redlit);
	Iconset.redlittrans.image = "markers/redlit-trans.png";

	// Red square
	Iconset.redsquare = new GIcon();
	Iconset.redsquare.image = "markers/redsquare.png"       
	Iconset.redsquare.iconSize = new GSize(11, 11);
	Iconset.redsquare.iconAnchor = new GPoint(5, 5);
	Iconset.redsquare.infoWindowAnchor = new GPoint(10, 1);
	/* Only works in Firefox...
	Iconset.redsquare.dragCrossAnchor = new GPoint(15, 11);
	Iconset.redsquare.dragCrossImage = "markers/bigx.png";
	Iconset.redsquare.dragCrossSize = new GPoint(30, 22);	*/
	Iconset.redsquare.maxHeight = 0;
	// Blue square
	Iconset.bluesquare = new GIcon(Iconset.redsquare);
	Iconset.bluesquare.image = "markers/bluesquare.png"       
	// Yellow square
	Iconset.yellowsquare = new GIcon(Iconset.redsquare);
	Iconset.yellowsquare.image = "markers/yellowsquare.png"       
	// Green square
	Iconset.greensquare = new GIcon(Iconset.redsquare);
	Iconset.greensquare.image = "markers/greensquare.png"       

	// Red square little
	Iconset.redsquarelit = new GIcon(Iconset.redsquare);
	Iconset.redsquarelit.image = "markers/redsquarelit.png"       
	Iconset.redsquarelit.iconSize = new GSize(7, 7);
	Iconset.redsquarelit.iconAnchor = new GPoint(3, 3);
	Iconset.redsquarelit.infoWindowAnchor = new GPoint(6, 1);
	// Yellow square little
	Iconset.yellowsquarelit = new GIcon(Iconset.redsquarelit);
	Iconset.yellowsquarelit.image = "markers/yellowsquarelit.png"       

	// Red square big
	Iconset.redsquare_big = new GIcon(Iconset.redsquare);
	Iconset.redsquare_big.image = "markers/yellowsquare-sel.png"       
	Iconset.redsquare_big.iconSize = new GSize(15, 15);
	Iconset.redsquare_big.iconAnchor = new GPoint(7, 7);
	Iconset.redsquare_big.infoWindowAnchor = new GPoint(14, 1);
	// Yellow square big
	Iconset.yellowsquare_big = new GIcon(Iconset.redsquare_big);
	Iconset.yellowsquare_big.image = "markers/yellowsquare-big.png"       
	
	// Red star
	Iconset.redstar = new GIcon(Iconset.redsquare);
	Iconset.redstar.image = "markers/redstar.png"       
	Iconset.redstar.iconSize = new GSize(19, 21);
	Iconset.redstar.iconAnchor = new GPoint(10, 12);
	Iconset.redstar.infoWindowAnchor = new GPoint(19, 1);
	//Iconset.redstar.dragCrossAnchor = new GPoint(15, 11);
	//Iconset.redstar.dragCrossImage = "markers/bigx.png";
	//Iconset.redstar.dragCrossSize = new GPoint(30, 22);
	// Yellow star
	Iconset.yellowstar = new GIcon(Iconset.redstar);
	Iconset.yellowstar.image = "markers/yellowstar.png"       

	// Red glow
	Iconset.redglow = new GIcon(Iconset.redsquare);
	Iconset.redglow.image = "markers/redglow.png"       
	Iconset.redglow.iconSize = new GSize(23, 23);
	Iconset.redglow.iconAnchor = new GPoint(11, 11);
	Iconset.redglow.infoWindowAnchor = new GPoint(22, 1);
	// Yellow glow
	Iconset.yellowglow = new GIcon(Iconset.redglow);
	Iconset.yellowglow.image = "markers/yellowglow.png"       

	///////// Pick which markers to use ///////////////
	Iconset.interior = Iconset.redsquare;
	Iconset.boundary = Iconset.yellowsquare;
	Iconset.interior_sel = Iconset.redglow;
	Iconset.boundary_sel = Iconset.yellowglow;
	Iconset.interior_inact = Iconset.redsquarelit;
	Iconset.boundary_inact = Iconset.yellowsquarelit;
	Iconset.interior_inact_sel = Iconset.redsquarelit;
	Iconset.boundary_inact_sel = Iconset.yellowsquarelit;
}


