var quoteProfiles = {
	//variables
	_object_info : 'make changes to quoteProflie.js first then compact to make this file',	
	cssText: '',
	flyoutHeight: 220,
	flyoutWidth: 175,
	hideSpeed: 200,
	id:'',
	linkCharts: '',
	linkNews: '',
	linkQuote: '',
	linkReasearch: '',
	loadingText : "<div class='loading'><img src='/resources/images/animatedLoader.gif' border='0' /><div>",	
	quote: '',	
	ric:'',
	showSpeed: 700,
	symbols: [],
	t: '',
	t2: '',	
	x: 0,
	y: 0,
	yParent: document.getElementById("resizeableText").offsetTop,
	//methods
	callback : function () {
		var quoteAjaxResponse = document.getElementById("quoteAjaxResponse");
		quoteProfiles.quote = eval(quoteAjaxResponse.innerHTML);
		var qpContents = document.getElementById("qpContents");
		var html = "<h3 class='quoteHeader' id='quoteHeader'><a href='"+quoteProfiles.linkQuote+"?symbol="+quoteProfiles.quote.ric+"'>"+quoteProfiles.quote.company+" ("+quoteProfiles.quote.ric+")</a></h3>";
		html += "<div class='quoteLinks'><a href='"+quoteProfiles.linkNews+"?symbol="+quoteProfiles.quote.ric+"'>News</a>, <a href='"+quoteProfiles.linkCharts+"?symbol="+quoteProfiles.quote.ric+"'>Chart</a>, <a href='"+quoteProfiles.linkReasearch+"?symbol="+quoteProfiles.quote.ric+"'>Research</a>, <a href='"+quoteProfiles.linkQuote+"?symbol="+quoteProfiles.quote.ric+"'>More...</a></div>";
		html += "<div class='quoteDetails'><span class='valueContent'>"+quoteProfiles.quote.quote+"<span class='currencyCode'>"+quoteProfiles.quote.currency+"</span></span><span class='valueContent'>";
		if(quoteProfiles.quote.positiveChange == 'true') {
		html+= "<span class='pos'>";
		} else {
		html+= "<span class='neg'>";
		}
		html+= quoteProfiles.quote.netChange+"</span></span></span><span class='valueContent'>";
		if(quoteProfiles.quote.positiveChange == 'true') {
		html+= "<span class='pos'>";
		} else {
		html+= "<span class='neg'>";
		}
		html+= quoteProfiles.quote.percentChange+"</span></span><span></div>";
		//html+= "<div id='smallChart' style='padding:5px 0;'><div class='imgLoaded' id='chartDiv'><img src='/charts/cr/?symbol="+quoteProfiles.quote.ric+"&display=mountain&width=175&height=142&frequency=1day&duration=1year' border='0' /></div></div><div class='pagestamp'>As of&nbsp;"+quoteProfiles.quote.timeFormattedForEdition+"</div><div class='dividerInlineH'>&nbsp;</div><iframe id='flyoutQuoteAd' src='/assets/sharedModuleLoader?view=RSM-Featured Broker For Quote Flyout' height='70' width='175' frameborder='0' scrolling='no'></iframe>";		
		html+= "<div id='smallChart'><div class='imgLoaded' id='chartDiv'>"+document.getElementById("quoteChartLoader").innerHTML+"</div></div><div class='pagestamp'>As of&nbsp;"+quoteProfiles.quote.timeFormattedForEdition+"</div>";		
		qpContents.innerHTML = html;
		quoteProfiles.setDimensions();
	},
	clearSpanStyle: function () {
		var len = this.symbols.length;
		for(var i=0;i<len;i++) {
			document.getElementById(this.symbols[i].id).style.cssText = "background-color:#FFFFF;";
		}
	},
	getAjaxQuoteData : function () {		
		com.reuters.rcom.utils.replaceContent("quoteAjaxResponse", "/do/marketDataAjax?type=quote&symbol="+this.ric, null, quoteProfiles.callback);
	},
	getEditionLinks : function () {
		switch(strLocalization) {
		case 'US':
			this.linkCharts = '/finance/stocks/chart';
			this.linkNews = '/finance/stocks/companyNews';
			this.linkQuote = '/finance/stocks/overview';
			this.linkReasearch = '/finance/stocks/analystResearch';
			break;
		case 'UK':
			this.linkCharts = '/business/quotes/chart';
			this.linkNews = '/business/quotes/companyNews';
			this.linkQuote = '/business/quotes/quote';
			this.linkReasearch = 'https://commerce.uk.reuters.com/purchase/advancedSearch.do';
			break;
		case 'JP':
			this.linkCharts = '/investing/quotes/chart';
			this.linkNews = '/investing/quotes/companyNews';
			this.linkQuote = '/investing/quotes/quote';
			this.linkReasearch = 'https://commerce.jp.reuters.com/purchase/advancedSearch.do';
			break;
		case 'IN':
			this.linkCharts = '/money/quotes/chart';
			this.linkNews = '/money/quotes/companyNews';
			this.linkQuote = '/money/quotes/quote';
			this.linkReasearch = '#';
			break;
		}
	},
	hideFlyout : function () {
		var quoteFlyout = document.getElementById("quoteFlyout");
		var quoteAjaxResponse = document.getElementById("quoteAjaxResponse");
		quoteFlyout.style.cssText = "display:none;";
		document.getElementById("qpContents").innerHTML = this.loadingText;
		quoteAjaxResponse.innerHTML = "";
		quoteAjaxResponse.style.cssText = "display:none;";
		this.cssText = "";
	},
	init : function () {
		var quoteFlyout = document.createElement("div");
		var quoteChartLoader = document.createElement("div");
		var quoteAjaxResponse = document.createElement("div");
		var quoteAjaxResponseContainer = document.createElement("div");
		var resizeableText = document.getElementById("resizeableText");
		var spans = document.getElementsByTagName("span");
		this.getEditionLinks();
		quoteFlyout.setAttribute("id", "quoteFlyout");
		quoteFlyout.style.cssText = "display:none;";
		quoteFlyout.innerHTML = "<div class='qpTip' id='qpTip'><div class='qpTab' id='qpTab'></div><div class='qpShadow'><div class='qpContents' id='qpContents' style='width:"+this.flyoutWidth+"px; height:"+this.flyoutHeight+"px'>"+this.loadingText+"</div></div></div>";
		quoteChartLoader.setAttribute("id", "quoteChartLoader");
		quoteChartLoader.style.cssText = "display:none;";
		quoteAjaxResponse.setAttribute("id", "quoteAjaxResponse");
		quoteAjaxResponse.style.cssText = "display:none;";
		quoteAjaxResponseContainer.style.cssText = "display:none;";		
		resizeableText.appendChild(quoteFlyout);
		resizeableText.appendChild(quoteAjaxResponseContainer);
		quoteAjaxResponseContainer.appendChild(quoteAjaxResponse);
		resizeableText.appendChild(quoteChartLoader);		
		for(var i=0;i<spans.length;i++) {			
			if(spans[i].getAttribute('id') != null) {
				if(spans[i].getAttribute('id').search(/symbol_/) != -1) {
					var sId = spans[i].getAttribute('id');
					var ric = document.getElementById(sId).innerHTML;
					var currentSpan = document.getElementById(sId);
					currentSpan.innerHTML = "<a href=\""+this.linkQuote+"?symbol="+ric+"	\">"+currentSpan.innerHTML+"</a>";
					currentSpan.style.cssText = "cursor:pointer;";
					this.symbols.push({"id": sId});
					this.regEvents(sId);
				}
			}
		}
	},
	mouseOutEvent : function (e) {		
		if (typeof(quoteProfiles.t) != 'undefined') {
				clearTimeout(quoteProfiles.t);
		}
		quoteProfiles.clearSpanStyle();
		quoteProfiles.t2 = setTimeout ("quoteProfiles.hideFlyout();", quoteProfiles.hideSpeed );	
	},
	mouseOutEventContainer : function (e) {
		if (typeof(quoteProfiles.t) != 'undefined') {
				clearTimeout(quoteProfiles.t);
		}
		quoteProfiles.clearSpanStyle();
		quoteProfiles.t2 = setTimeout ( "quoteProfiles.hideFlyout();", quoteProfiles.hideSpeed );
	},	
	mouseOverEvent : function (e) {
		if (quoteProfiles.quote.id != this.id) {
			quoteProfiles.hideFlyout();	
		}		
		if (typeof(quoteProfiles.t2) != 'undefined') {
				clearTimeout (quoteProfiles.t2);
		}
		if (typeof(quoteProfiles.t) != 'undefined') {
				clearTimeout (quoteProfiles.t);
		}
		var symbolSpan = document.getElementById(this.id);
		symbolSpan.style.cssText = "background-color:#E5EEF3;";
		quoteProfiles.x = symbolSpan.offsetLeft;
		quoteProfiles.y = symbolSpan.offsetTop;
		quoteProfiles.id = this.id;
		quoteProfiles.ric = symbolSpan.firstChild.innerHTML;
		document.getElementById("quoteChartLoader").innerHTML = "<img src='/charts/cr/?symbol="+quoteProfiles.ric+"&display=mountain&width=175&height=142&frequency=1day&duration=1year' border='0' />";
		quoteProfiles.t = setTimeout ( "quoteProfiles.showFlyout();", quoteProfiles.showSpeed);
	},
	mouseOverEventContainer : function (e) {
		if (typeof(quoteProfiles.t2) != 'undefined') {
				clearTimeout (quoteProfiles.t2);
		}
		document.getElementById(quoteProfiles.id).style.cssText = "background-color:#E5EEF3;";
	},	
	regEvents : function (sId) {
		document.getElementById(sId).onmouseover = this.mouseOverEvent;
		document.getElementById(sId).onmouseout = this.mouseOutEvent;
	},
	setDimensions : function () {
		var quoteHeader = document.getElementById("quoteHeader");
		var qpContents = document.getElementById("qpContents");
		var h = this.flyoutHeight+quoteHeader.offsetHeight;
	    var w = this.flyoutWidth;	    
		qpContents.style.cssText= qpContents.style.cssText+"height:"+h+"px;width:"+w+"px;";
	},
	setFlyoutLocation : function (x,y) {
		var resizeabletextDiv =  document.getElementById("resizeableText");
		var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
		if(ie7) {
			quoteProfiles.cssText += "display:inline;left:"+x+"px;top:"+(y+quoteProfiles.yParent)+"px;";
		} else {
			quoteProfiles.cssText += "display:inline;left:"+x+"px;top:"+y+"px;";
		}		
	},
	setOrientation : function (x) {
		var tip = document.getElementById("qpTip");
		var tab = document.getElementById("qpTab");
		if(x < 270) {
				tab.className = "qpTab";
				tip.className = "qpTip";
		} else {				
				tab.className = "qpTab2";
				tip.className = "qpTip2";	
		}
	},
	showFlyout : function () {
		var flyout = document.getElementById("quoteFlyout");
		var tip =  document.getElementById("qpTip");
		this.setOrientation(this.x);
		this.setFlyoutLocation(this.x,this.y);
		flyout.style.cssText = this.cssText;
		tip.onmouseover = this.mouseOverEventContainer;
		tip.onmouseout = this.mouseOutEventContainer;
		this.getAjaxQuoteData();					
	}
};
quoteProfiles.init();
