	var chart_navprem;
    $(document).ready(function(){
		var options_navprem = {
			chart: {
				renderTo: 'chart-container-navprem',
				defaultSeriesType: 'line',
				height: location.href.indexOf('/about/page/research/') != -1 ? 400 : 200,
				style: {
					fontFamily: '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif',
					fontSize: '10px'
				},
				backgroundColor: 'rgba(0,0,0,0)',
				spacingLeft: 5,
				spacingRight: 5,
				zoomType: 'x',
				animation: false //need to disable animation for IE if you want zoom function
			},
			title: {
				text: '',
				align: 'left',
				style: {
					fontFamily: 'CallunaSans, Arial',
					fontSize: '12px',
					color: '#000000'
				}
			},
			xAxis: {
				labels: {
					style: {
						fontSize: '10px'
					}
				},
				startOnTick: false,
				endOnTick: false,
				tickInterval: 63072000000, //2 years
				tickLength: 0,
				lineWidth: 0,
				type: 'datetime',
				dateTimeLabelFormats: {
					year: '\'%y'   
				}
			},
			yAxis: {
				title: {
				   text: null
				},
				labels: {
					formatter: function() {
						return this.value + '%';
					},
					style: {
						fontSize: '10px'
					}
				},
				//max: 105,
				//min: 40,
				startOnTick: false,
				endOnTick: false,
				tickInterval: 10,
				gridLineColor: '#E8E8E8'
			},
			series: [
			],
			plotOptions: {
				series: {
					marker: {
						enabled: false
					}
				},
				line: {
					dataLabels: {
						enabled: false,
						formatter: function() {
							//return this.x;
							if (this.x == lastX) {
								return (Math.round(Math.pow(10,2)*this.y)/Math.pow(10,2)).toFixed(2) + '%';
							}
						}
					}
				}
			},
			legend: {
				enabled: true,
				borderWidth: 0,
				margin: 5,
				itemStyle: {
					fontSize: '10px'
				},
				labelFormatter: function() {
					if (this.name.indexOf('Avg') == -1) {
						return this.name + ': ' + (Math.round(Math.pow(10,1)*lastY)/Math.pow(10,1)).toFixed(1) + '%';//+ this.y.toFixed(2) + ' test'; 
					} else {
						return this.name;
					}
				}
			},
			tooltip: {
				enabled: false,
				formatter: function() {
					var s = '<b>' + Highcharts.dateFormat('%b-%Y', this.x) + '</b>: ' + (Math.round(Math.pow(10,1)*this.y)/Math.pow(10,1)).toFixed(1) + '%';
					return s;
				}
			},
			colors: [
				'rgba(85,155,35,0.8)', 
				'rgba(25,65,35,0.8)', 
				'#F2ECD8', 
				'#8B8D8E', 
				'#A4B3C9', 
				'#003F72', 
				'#A7193B'
			],
			exporting: {
				enabled: false
			},
			credits: {
				enabled: false
			}
		}
		var date = new Date();
		var lastY;
		var lastX;
		$.ajax({ //need to use this method instead of getJSON because of crappy IE
			url: '/index.php?module=data&action=psv&ID=nav_premiums_over_time&format=json&timestamp='+date.getTime(), //timestamping for IE caching issues 
			cache: false,
			dataType: 'json',
			contentType: 'application/json', //need to specify explicitly for IE
			success: function(returnData) {
				for(var j=0; j<returnData.length;j++) {
					var series = {
						name: returnData[j].name,
						data: [],
						lineWidth: 2
					};
					for(var i=0; i< returnData[j].items.length;i++) {
						var sDate;
						sDate = parseDate(returnData[j].items[i].date, 'yyyy-mm-dd').getTime();
						series.data.push([sDate, parseFloat(returnData[j].items[i].data)]);   
						if (i == returnData[j].items.length-1 && j == 0) { 
							lastY = parseFloat(returnData[j].items[i].data);
							lastX = sDate;
						}
					}
					options_navprem.series.push(series);
				}
				var chart = new Highcharts.Chart(options_navprem);
			},
			error: function(xhr, status, error) {
				alert(xhr.status);
			}
		});
    });
	
	
	var lightboxNavPremChart = function(e, url, html_text, html_footer) {
		if(Ext._lightBoxWindow) {
            Ext._lightBoxWindow.close();
		}
		var date = new Date();
		var lastY;
		var lastYavg;
        var windowOptions = {
            layout      : 'anchor'
        //				,width       : 700 	//commenting out width will make it auto fit
            ,width	 : 700
            ,maxHeight	 : 600
        //				,height      : 500  //use autoheight=true
            ,closeAction :'hide'
            ,plain       : true
            ,title		 : 'Average Premium to NAV'
            ,resizable   : false
			//,y			 : 10
            ,items       : [
				{ 
					html: ((url !== null) ? '<img src="' + url + '" />' : '') + ((html_text !== null) ? html_text.innerHTML : '') ,
					border: false
				},
				{ 
					xtype: 'highchart',
					store: new Ext.data.JsonStore({
						root: 'items',
						remoteSort: true,
						fields: [{name: 'date', type:'string'},{name:'premnav', type: 'float'},{name:'avg', type: 'float'}],
						proxy: new Ext.data.HttpProxy({
							method: 'POST',
							url: '/index.php?module=data&action=psv&ID=nav_premiums_over_time&format=json_extjs&timestamp='+date.getTime() //timestamping for IE caching issues 
						}), 
						autoLoad: true,
						baseParams: {
							//f_dateformat: 'UTC'
						},
						listeners: {
							load: {
								fn: function(store, records, options){
									//window.alert("load success, records:" + store.getCount());
									//convert priceHistory into JSON object
									for (var i=0; i<store.getCount(); i++) {
										var record = store.getAt(i);
										var aryPrice = [];
										sDate = parseDate(record.get('date'), 'yyyy-mm-dd').getTime();
										record.set('date',sDate);
										if (i == store.getCount()-1) { 
											lastY = parseFloat(record.get('premnav'));
											lastYavg = parseFloat(record.get('avg'));
										}
									}
								}
							}
						}
					}),
					//xField: 'date',
					series: [{
						name: 'NAV Premium (All REITs)',
						dataIndex: 'premnav',
						xField: 'date',
						lineWidth: 3
					},{
						name: 'Avg',
						dataIndex: 'avg',
						xField: 'date',
						lineWidth: 3
					}
					],
					chartConfig: {
						chart: {
							defaultSeriesType: 'line',
							backgroundColor: 'rgba(0,0,0,0)', //'transparent' doesn't work for IE so use rgba code 
							width: 650,
							zoomType: 'x',
							animation: false
						},
						title: {
							text: '',
							style: {
								fontFamily: 'CallunaSans, Arial',
								fontSize: '16px',
								color: '#000000'
							}
						},
						subtitle: {
							text: '',
							style: {
								fontSize: '14px',
								fontFamily: 'CallunaSans, Arial',
								color: '#000000'
							}
						},
						xAxis: {
							labels: {
								style: {
									fontSize: '12px'
								}
							},
							startOnTick: false,
							endOnTick: false,
							tickInterval: 63072000000, //2 years
							tickLength: 0,
							lineWidth: 0,
							type: 'datetime',
							dateTimeLabelFormats: {
								year: '\'%y'   
							}
						},
						yAxis: {
							title: {
							   text: null
							},
							labels: {
								formatter: function() {
									return this.value + '%';
								},
								style: {
									fontSize: '12px'
								}
							},
							startOnTick: false,
							endOnTick: false,
							tickInterval: 10,
							gridLineColor: '#E8E8E8'
						},
						legend: {
							enabled: true,
							borderWidth: 0,
							margin: 5,
							itemStyle: {
								fontSize: '12px'
							},
							labelFormatter: function() {
								if (this.name.indexOf('Avg') == -1) {
									return this.name + ': ' + (Math.round(Math.pow(10,1)*lastY)/Math.pow(10,1)).toFixed(1) + '%';
								} else {
									return this.name + ': ' + (Math.round(Math.pow(10,1)*lastYavg)/Math.pow(10,1)).toFixed(1) + '%';
								}
							}
						},
						tooltip: {
							enabled: false,
							formatter: function() {
								var s = '<b>' + Highcharts.dateFormat('%b-%Y', this.x) + '</b>: ' + (Math.round(Math.pow(10,1)*this.y)/Math.pow(10,1)).toFixed(1) + '%';
								return s;
							}
						},
						plotOptions: {
							series: {
								marker: {
									enabled: false
								}
							},
							line: {
								dataLabels: {
									enabled: false,
									formatter: function() {
										//return this.x;
										if (this.x == lastX) {
											return (Math.round(Math.pow(10,2)*this.y)/Math.pow(10,2)).toFixed(2) + '%';
										}
									}
								}
							}
						},
						colors: [
							'rgba(85,155,35,0.8)', 
							'rgba(25,65,35,0.8)', 
							'#F2ECD8', 
							'#8B8D8E', 
							'#A4B3C9', 
							'#003F72', 
							'#A7193B'
						],
						exporting: {
							enabled: false
						},
						credits: {
							enabled: false
						}
					}
				},
				{ 
					html: ((html_footer !== null) ? html_footer.innerHTML : '') ,
					border: false
				}
				]
            ,modal		 : true //dims background
            ,autoScroll  : true
            ,autoHeight  : true
        };

        if(Ext.isIE7) {
            windowOptions['width'] = 750;
        }

        Ext._lightBoxWindow = new Ext.Window(windowOptions);

		Ext._lightBoxWindow.show();
	
	}	
