// First redirect jQuery to avoid collisions
// see http://docs.jquery.com/Using_jQuery_with_Other_Libraries for this trick
var $jQuery = jQuery.noConflict();

// globally define function to replot flot graph
// Input: 
// dataArray = array of X,Y values
// label = label string
//
// Function requires various global variables:
// - options
// - placeholder
// ToDo: write general flot API
//
// Note: for drawing more plots in a single graph we would
// require a different function. ToDo
// The data variable should then be:
// var data = [ { dataArray1, label: label1} { dataArray2, label: label2 } ... ]

function prepareDataPlGraph(plArray) {
	// A P/L array (plArray) is expected to be like the following form:
	// { strikeVector: { strike vector values },
	// optionValues: { option values at strikes },
	// ...
	// }
	valueArray = new Array();
	nullLine = new Array();
	// Construct data
	for (var i = 0; i < plArray.strikeVector.length; ++i) {
		valueArray[i] = [plArray.strikeVector[i], plArray.optionValues[i]];
		nullLine[i] = [plArray.strikeVector[i], plArray.nullLine[i]];
		}

	// Prepare actual plot data
	data = new Array();
	data = [
        { label: "Profit/loss (PL)",  data: valueArray},
        { label: "Break even",  data: nullLine, hoverable: false}
		];
	return data;
	}

function replotGraph(dataArray) {

	// (Re)plot flot graph
	var placeholder = $jQuery("#flotPicture");
	$jQuery.plot(placeholder, dataArray, $jQuery.extend(true, {}, options, {
			// Rescale the y axis
			yaxis: { min: null, max: null},
                        points: { show: false },
                        lines: { show: true}


		})
		);

	};
	

