var master_cruise_list = new Array();
var cruise_menu = new Object({html: ""});

function PrismCruise(cruise_name, cruise_fullname, cruise_date, dtime_start, dtime_end, coll_id, platform_id, cruise_route, stations, icon) {
	//this.vis = true;
	this.id = this.getPrismCruiseID(cruise_name); //Jun_2007, e.g.    //PrismCruise.getPrismCruiseID();
	
	this.cruise_name = cruise_name;
	this.cruise_name_abbrev = cruise_name.substr(cruise_name.length - 8); //ex: Jun_2006
	this.cruise_fullname = cruise_fullname;
	this.cruise_year = cruise_name.substr((cruise_name.length - 4), 4);
	this.cruise_month = abbrevMonthToLongMonth(cruise_name.substr((cruise_name.length - 8), 3));
	this.cruise_month_abbrev = cruise_name.substr((cruise_name.length - 8), 3);
	this.cruise_date = cruise_date;
	this.cruise_start_date = dtime_start;
	this.cruise_end_date = dtime_end;
	this.coll_id = coll_id; //what does coll_id mean?
	this.platform_id = platform_id; //what does platform_id mean?
	
	this.cruise_route = cruise_route;
	
	this.stations = stations;

	this.icon = (icon && eval(icon))? eval(icon): icon_default;
	this.icon_img = this.icon.image;
		
	this.cruise_route = (this.cruise_route.length > 0)? this.createCruiseRouteLine(this.cruise_route): null;
	this.crusie_route_vis = false;
	
	//register prism cruise in list
	master_cruise_list[this.id] = this;
}

PrismCruise.prototype.getPrismCruiseID = function(cruise_name) {
	var name_pieces = cruise_name.split(" ");
	return name_pieces[2]; //Jun_2007, e.g.
}

/*
PrismCruise.getPrismCruiseID = function() {
	PrismCruise.cruise_num = ++PrismCruise.cruise_num  ||  1;
	return "pc"+PrismCruise.cruise_num;
}
*/

PrismCruise.prototype.createCruiseRouteLine = function(cruise_route) {
	var points = new Array();
	for (var i in cruise_route) {
		points.push(new GLatLng(cruise_route[i].lat, cruise_route[i].lon));
	}
	
	/* VERSION 1 - FADING LINE
	var start_opacity = 1;
	var end_opacity = 0.3;
	var opacity_incr = (start_opacity - end_opacity) / (points.length - 1);
	
	var cruise_route_lines = new Array();
	for (var i = 0; i < points.length; i++) {
	
		var line = new Array(points[i], points[i+1]);
		var stroke_color = "#ff0000";
		var stroke_weight = 3;
		var stroke_opacity = start_opacity - (opacity_incr * i);
		stroke_opacity = Math.round(stroke_opacity * 100) / 100;
	
		cruise_route_lines.push(new GPolyline(line, stroke_color, stroke_weight, stroke_opacity));
	}
	/*
	
	/* VERSION 2 - CYCLING HUE */
	var start_hue = 60;
	var end_hue = 0;
	var hue_incr = -1 * ((start_hue - end_hue) / (points.length - 1));
	hue_incr = Math.round(hue_incr * 1000) / 1000;
	var saturation = 100;
	var value = 100;
	
	var cruise_route_lines = new Array();
	for (var i = 0; i < points.length; i++) {
	
		var line = new Array(points[i], points[i+1]);
		var stroke_hue = start_hue + (hue_incr * i);
		var stroke_color = getHexaFromHSV(stroke_hue, saturation, 20);
		var stroke_weight = 4;
		var stroke_opacity = 1;
	
		cruise_route_lines.push(new GPolyline(line, stroke_color, stroke_weight, stroke_opacity));
	}
	
	for (var i = 0; i < points.length; i++) {
	
		var line = new Array(points[i], points[i+1]);
		
		var stroke_hue = start_hue + (hue_incr * i);
		var stroke_opacity = 1;
		
		var stroke_color = getHexaFromHSV(stroke_hue, saturation, 50);
		var stroke_weight = 4;
		
		cruise_route_lines.push(new GPolyline(line, stroke_color, stroke_weight, stroke_opacity)); //border
		
		var stroke_color = getHexaFromHSV(stroke_hue, saturation, value);
		var stroke_weight = 2;
	
		cruise_route_lines.push(new GPolyline(line, stroke_color, stroke_weight, stroke_opacity)); //color
	}
	
	return cruise_route_lines;
}

PrismCruise.prototype.showCruiseRouteLine = function() {
	for (var i in this.cruise_route) {
		map.addOverlay(this.cruise_route[i]);
	}
	this.crusie_route_vis = true;
}

PrismCruise.prototype.hideCruiseRouteLine = function() {
	for (var i in this.cruise_route) {
		map.removeOverlay(this.cruise_route[i]);
	}
	this.crusie_route_vis = false;
}

/*
PrismCruise.prototype.createCruiseRouteLine = function(cruise_route) {
	var points = new Array();
	for (var i in cruise_route) {
		points.push(new GLatLng(cruise_route[i].lat, cruise_route[i].lon));
	}

	var stroke_color = "#ff0000";
	var stroke_weight = 2;
	var stroke_opacity = 1;
	
	var cruise_route_line = new GPolyline(points, stroke_color, stroke_weight, stroke_opacity);
	
	return cruise_route_line;
}


PrismCruise.prototype.showCruiseRouteLine = function() {
	map.addOverlay(this.cruise_route);
	this.crusie_route_vis = true;
}

PrismCruise.prototype.hideCruiseRouteLine = function() {
	map.removeOverlay(this.cruise_route);
	this.crusie_route_vis = false;
}
*/

