dojo.declare("swx.inv.CommonLayout", null, {
  constructor: function() {    

  this.marginRight      = 1; // margin from right of graph border to the axis labels
  this.marginTop        = 0; // margin from the top of the surface
  this.marginBottom     = 1; // margin from the bottom of the graph border to the axis labels
  this.paddingLeft      = 0;
  this.paddingRight     = 0;
  this.paddingBottom    = 0;
  this.paddingTop       = 0;    // space between border and graph top
  this.axisOnLeft       = true; // If false or omitted, vertical axis is on right
  this.graphOutlineW    = 55;   // how many pixels we should leave for axis and Security labels
  this.graphOutlineH    = 40;   // how many pixels we should leave for axis and Security labels
  this.marginLeft       = 51; // margin from left of surface
  /**
   * nonDiagonalShape {true,false}
   * false: values will be connected by diagonal lines (triangle wave)
   * true: values will be connected by ether vertical or horizontal lines (rectangular wave)
   */
  this.nonDiagonalShape = true;                                     
  this.horizontalGrid   = true; // do we want to force drawing horizontal grid lines on intraday charts ?
  this.labelPrecision   = null; // number of decimal places in Y-axis labels, automatic if null
  this.useCrispEdges    = true; // turn off antialiasing when drawing the plot
  this.tradingStart     = '08:00'; // when trading starts (format HH24:MM) 
  this.tradingEnd       = '22:30'; // when trading ends   (format HH24:MM)


  /**
   * This are the definitions of colors used while drawing the graph object
   * Those values will overwrite default values present in swx.inv.ChartDrawer static field.
   */
  this.chartStyles = {
      INFO_LAYER_BGCOLOR   : "transparent", //"#ABCDEF",
      INFO_LAYER_TXT_COLOR : "transparent", //"#FFFFFF",
      BORDER_COLOR         : "#CBCBCB",
      ID_COLOR             : "#003366", // intraday line , value greater than last closing price
      ID_DOWN_COLOR        : "#003366", // intraday line , value less than last closing price
      IDX1_COLOR           : "green",
      IDX2_COLOR           : "red",
      TI1_COLOR            : "#7D007D", // violet
      TI2_COLOR            : "#A2A200", // dark yellow
      TI3_COLOR            : "#FF55FF", // pink
      TI4_COLOR            : "#FF55FF", // pink (same as TI3 for Bollinger bands)
      TI_COLOR             : "#7D007D", // purple

      OLD_CLOSING_COLOR    : "#70BC1E", // color of the line used to show old closing value

      PREVIEW_COLOR        : "#9999AA",

      ID_FILL_COLOR        : [110,120,170,0],//[0, 50, 150, 0.1],  // A bit transparent

      //axis colors
      GRID_COLOR           : "#CCCCCC",  // Grid basic color
      DARK_GRID_COLOR      : "#CCCCCC",  // Grid color if day has changed in intraday view
      GRID_BACKGROUND      : "#EAF7DF",  // Color used one out of two blocks


      LINE_STYLE           : "line",
      BARS_STYLE           : "bars",
      CANDLESTICKS_STYLE   : "candles",

      CROSSHAIR_FULL_STYLE  : "full",
      CROSSHAIR_SMALL_STYLE : "small",
      CROSSHAIR_NONE_STYLE  : "none"
  };
  // make sure our trading times are ok
  this.validateTradingTime();
},

validateTradingTime: function (){
  var timeRe = /(\d{1,2}):(\d{2})/;
      
  var tStart = timeRe.exec( this.tradingStart);
  var tEnd   = timeRe.exec( this.tradingEnd);

  // if ok return without the changes
  if(tStart && tEnd 
      && tStart.length == 3 && tEnd.length == 3  
      && tStart[1] < 24 && tStart[2] < 60
      && tEnd [1] < 24 && tEnd[2] < 60      
      && tStart[1] >= 0 && tStart[2] >=0
      && tEnd [1] >=0 && tEnd[2] >=0
      && new Date(0,0,0,tStart[1],tStart[2],0) < new Date(0,0,0,tEnd[1],tEnd[2],0)){        
    return;
  }
  // if dates are not ok, reset to null, push error to the console 
      console.warn('Wrong trading dates: ['+this.tradingStart+','+this.tradingEnd+']; will be reset to null');
   // use default trading hours
      this.tradingStart     = null;  
      this.tradingEnd       = null;     
}
});

dojo.declare("swx.inv.SmallLayout", swx.inv.CommonLayout, {
  constructor: function() {    
  this.graphWidth    = 240;
  this.graphHeight   = 120;
  this.chartWidth    = this.graphWidth + this.graphOutlineW;
  this.chartHeight   = this.graphHeight + this.graphOutlineH;
}});

dojo.declare("swx.inv.SmallerLayout", swx.inv.CommonLayout, {
  constructor: function() {    
  this.graphWidth    = 160;
  this.graphHeight   = 80;
  this.chartWidth    = this.graphWidth + this.graphOutlineW;
  this.chartHeight   = this.graphHeight + this.graphOutlineH;
}});

dojo.declare("swx.inv.VerySmallLayout", swx.inv.CommonLayout, {
  constructor: function() {    
  this.graphWidth    = 150;
  this.graphHeight   = 70;
  this.chartWidth    = this.graphWidth + this.graphOutlineW;
  this.chartHeight   = this.graphHeight + this.graphOutlineH;
}});

dojo.declare("swx.inv.MicroLayout", swx.inv.CommonLayout, {
  constructor: function() {    
  this.graphWidth    = 86;
  this.graphHeight   = 54;
  this.chartWidth    = this.graphWidth + this.graphOutlineW;
  this.chartHeight   = this.graphHeight + this.graphOutlineH;
}});

var siteChartConfig = {	
    // global parameters
    CHART_DATA_URL : "/ajax/fqs-invchartdata.json",
    UPDATE_GRAPH_PERIOD : 5000, // ms, update graph with new values from json object

    getSMALL_LAYOUT: function() {
      return new swx.inv.SmallLayout();
    },

    getSMALLER_LAYOUT: function() {
      return new swx.inv.SmallerLayout();
    },
    
    getVSMALL_LAYOUT: function() {
      return new swx.inv.VerySmallLayout();
    },
    getMICRO_LAYOUT: function() {
      return new swx.inv.MicroLayout();
    }
};
