
function isIE() {
	if(window.navigator.userAgent.toLowerCase().indexOf('msie') >= 1)
    	return true;
	else 
		return false;
} 

if(!isIE()) {
	HTMLElement.prototype.__defineGetter__('innerText',
	function() {
	    var anyString = '';
    	var childS = this.childNodes;
	    for(var i=0; i < childS.length; i++) {
		    if(childS[i].nodeType == 1)
		        anyString += childS[i].tagName == 'BR' ? '\n' : childS[i].innerText;
		    else if(childS[i].nodeType == 3)
        		anyString += childS[i].nodeValue;
	    }
	    return anyString;
	  } 
	);

	HTMLElement.prototype.__defineSetter__('innerText',
		function(sText) {
			this.textContent=sText;
		}
	);
}

function addEvent(e, event, func) {
	if(window.attachEvent)
		e.attachEvent('on' + event, func);
	else if(window.addEventListener)
		e.addEventListener(event, func, false);
}

var RD_DATA = {
	RD1 : 0, //买入
	RD2 : 0, //增持
	RD3 : 0, //中性
	RD4 : 0, //减持
	RD5 : 0 //卖出
};

var RD_CHART = {
	RD1 : {width:1},
	RD2 : {width:1},
	RD3 : {width:1},
	RD4 : {width:1},
	RD5 : {width:1}
};

var MaxRDChartLineLength = 240;

function initRD() {
	$('RD1Count').innerText = RD_DATA.RD1;
	$('RD2Count').innerText = RD_DATA.RD2;
	$('RD3Count').innerText = RD_DATA.RD3;
	$('RD4Count').innerText = RD_DATA.RD4;
	$('RD5Count').innerText = RD_DATA.RD5;

	var max = RD_DATA.RD1;
	if(RD_DATA.RD2 > max)
		max = RD_DATA.RD2;
	if(RD_DATA.RD3 > max)
		max = RD_DATA.RD3;
	if(RD_DATA.RD4 > max)
		max = RD_DATA.RD4;
	if(RD_DATA.RD5 > max)
		max = RD_DATA.RD5;
		
	var perValuePX = max / MaxRDChartLineLength;
	
	RD_CHART.RD1.width = RD_DATA.RD1 / perValuePX;
	RD_CHART.RD1.width = RD_CHART.RD1.width == 0 ? 1 : RD_CHART.RD1.width;
	RD_CHART.RD2.width = RD_DATA.RD2 / perValuePX;
	RD_CHART.RD2.width = RD_CHART.RD2.width == 0 ? 1 : RD_CHART.RD2.width;
	RD_CHART.RD3.width = RD_DATA.RD3 / perValuePX;
	RD_CHART.RD3.width = RD_CHART.RD3.width == 0 ? 1 : RD_CHART.RD3.width;
	RD_CHART.RD4.width = RD_DATA.RD4 / perValuePX;
	RD_CHART.RD4.width = RD_CHART.RD4.width == 0 ? 1 : RD_CHART.RD4.width;
	RD_CHART.RD5.width = RD_DATA.RD5 / perValuePX;
	RD_CHART.RD5.width = RD_CHART.RD5.width == 0 ? 1 : RD_CHART.RD5.width;
	
	$('RD1').style.width = RD_CHART.RD1.width + 'px';
	$('RD2').style.width = RD_CHART.RD2.width + 'px';
	$('RD3').style.width = RD_CHART.RD3.width + 'px';
	$('RD4').style.width = RD_CHART.RD4.width + 'px';
	$('RD5').style.width = RD_CHART.RD5.width + 'px';
}

function initElement() {
	var list = document.getElementsByName('jgld_more_link');
	for(var i = 0; i < list.length; i++) {
		var a = list[i];
		
		addEvent(a, 'mouseover', function() {
			if(this.event)
				this.event.srcElement.style.textDecoration = 'none';
			else
				this.style.textDecoration = 'none';
		});
		addEvent(a, 'mouseout', function() {
			if(this.event)
				this.event.srcElement.style.textDecoration = 'underline';
			else
				this.style.textDecoration = 'underline';
		});
	}
}

window.onload = function() {
	initElement();
	initRD();
	changeRDTab(1);
};

var curRDTabIndex = 0;
var curRDChartIndex = 0;

function changeRDTab(index) {
	if(curRDTabIndex != 0) {
		var curRDTab = $('RD' + curRDTabIndex + 'Tab');
		curRDTab.className = 'page2';
		var curRDTable = $('RD' + curRDTabIndex + 'Table');
		curRDTable.style.display = 'none';
	}
	
	curRDTabIndex = index;
	var curRDTab = $('RD' + curRDTabIndex + 'Tab');
	curRDTab.className = 'page1';
	var curRDTable = $('RD' + curRDTabIndex + 'Table');
	curRDTable.style.display = 'inline';
	
	changeRDChart(index);
}

function changeRDChart(index) {
	var shadow = $('RDChartShadow');
	shadow.style.display = 'none';

	if(curRDChartIndex != 0) {
		var rd = $('RD' + curRDChartIndex);
		rd.className = 'RDChartNoBorder';
	}
	
	curRDChartIndex = index;
	var rd = $('RD' + index);
	rd.className = 'RDChartBorder';
	
	shadow.style.width = parseInt(rd.style.width) + 2 + 'px';
	shadow.style.left = '2px';
	shadow.style.top = '-' + (156 - (index - 1) * 34.5) + 'px';
	shadow.style.display = 'block';
}