function onloader()  
{  
moveDivThumbs();  
moveDiv();  

} 
$(function () {
		moveDiv();
		window.onresize = moveDiv;
			
		var searchLabel = ' Search';
		$('#FinraSearch').val(searchLabel).focus(function() {
			if (this.value == searchLabel) {
				$(this).val('');
			};
		}).blur(function () {
			if (this.value == '') {
				$(this).val(searchLabel);
			};
		});
		$('#search').submit(function() {
			if ($('#FinraSearch').val() == searchLabel) {
				$('#FinraSearch').val('');
			}
		});
	});	
	
	$().ready(function () {
		moveDivThumbs();
		window.onresize = moveDivThumbs;
	});	
	
	 $(function() {
	onloader();
	window.onresize = onloader; });
	 
	var colnames = [];
	var colnamesThumbs = [];
	
	function largeDiv() {
		var col1 = $('#col1cont').height()
		var col2 = $('#col2cont').height()
		var col3 = $('#col3cont').height()
		var col4 = $('#col4cont').height()
		var cols = [col1,col2,col3,col4];
		var lastcol = cols.length-1;
		cols.sort( function (a,b) { return a-b });
		function compare(a,b) {
			if (a < b) { return -1; }
			if (a > b) { return 1; }
			if (a == b) { return 0; }
		}
		if (cols[lastcol] < 335) {
			return 335
		}
		else {
			return cols[lastcol];
		}
	}
		
		function largeDivThumbs() {
		var col1Thumbs = $('#g1').height()
		var col2Thumbs = $('#g2').height()
		var col3Thumbs = $('#g3').height()
		var colsThumbs = [col1Thumbs,col2Thumbs,col3Thumbs];
		var lastcolThumbs = colsThumbs.length-1;
		colsThumbs.sort( function (a,b) { return a-b });
		function compare(a,b) {
			if (a < b) { return -1; }
			if (a > b) { return 1; }
			if (a == b) { return 0; }
		}
		if (colsThumbs[lastcolThumbs] < 10) {
			return 50
		}
		else {
			return colsThumbs[lastcolThumbs] + 17;
			// 
		}
	}
		function colNameThumbs() {
		var col1Thumbs = $('#g1').height()
		var col2Thumbs = $('#g2').height()
		var col3Thumbs = $('#g3').height()
		var lastcolThumbs = colnamesThumbs.length-1;
		var largeThumbs = largeDivThumbs();
		var name1Thumbs;
		if (col1Thumbs == largeThumbs) { colnamesThumbs.push("g1cont") }
		else if (col2Thumbs == largeThumbs) { colnamesThumbs.push("g2cont") }
		else if (col3Thumbs == largeThumbs) { colnamesThumbs.push("g3cont") }
		else { colnamesThumbs.push("toosmall") }
		return colnamesThumbs[lastcolThumbs];
	}
		function moveDivThumbs() {  
		var largeThumbs = largeDivThumbs();
		var targetDivThumbs = colNameThumbs();
		theDiv1Thumbs = document.getElementById('g1cont').style;
		theDiv2Thumbs = document.getElementById('g2cont').style;
		theDiv3Thumbs = document.getElementById('g3cont').style;

		 if (targetDivThumbs = "g3c") {
			theDiv1Thumbs.height = largeThumbs + "px";
			theDiv2Thumbs.height = largeThumbs + "px";
			theDiv3Thumbs.height = largeThumbs + "px";
		}	
		else if (targetDivThumbs = "g1cont") {
			theDiv2Thumbs.height = largeThumbs + "px";
			theDiv3Thumbs.height = largeThumbs + "px";
		//	theDiv4Thumbs.height = largeThumbs + "px";		
		}
		else if (targetDivThumbs = "g2cont") {
			theDiv1Thumbs.height = largeThumbs + "px";
			theDiv3Thumbs.height = largeThumbs + "px";
		//	theDiv4Thumbs.height = largeThumbs + "px";
		}
		else if (targetDivThumbs = "g3cont") {
			theDiv1Thumbs.height = largeThumbs + "px";
			theDiv2Thumbs.height = largeThumbs + "px";
		//	theDiv3Thumbs.height = largeThumbs + "px";
		}
//		else if (targetDivThumbs = "toosmall") {
//			theDiv1Thumbs.height = largeThumbs + "px";
//			theDiv2Thumbs.height = largeThumbs + "px";
//			theDiv3Thumbs.height = largeThumbs + "px";
//			theDiv4Thumbs.height = largeThumbs + "px";	
//		}	
				//alert(headerHeight);
		//theDiv5.left = (breadcrumbLeft) + "px";
	}
	function colName() {
		var col1 = $('#col1cont').height()
		var col2 = $('#col2cont').height()
		var col3 = $('#col3cont').height()
		var col4 = $('#col4cont').height()
		var lastcol = colnames.length-1;
		var large = largeDiv();
		var name1;
		if (col1 == large) { colnames.push("column1") }
		else if (col2 == large) { colnames.push("column2") }
		else if (col3 == large) { colnames.push("column3") }
		else if (col4 == large) { colnames.push("column4") }
		else { colnames.push("toosmall") }
		return colnames[lastcol];
	}
	
	function moveDiv() { 
		document.search.FinraSearch.value = ' Search'
		var contentWidth = document.getElementById('finra-banner').offsetWidth;
		var headerHeight = document.getElementById('finra-header').offsetHeight;
		//var breadcrumbLeft= document.getElementById('column1').offsetLeft - 0 + "px";
		var breadcrumbHeight = document.getElementById('breadcrumb').offsetHeight; 
		var large = largeDiv();
		var targetDiv = colName();
		theDiv = document.getElementById('finra-footer').style;
		theDiv1 = document.getElementById('column1').style;
		theDiv2 = document.getElementById('column2').style;
		theDiv3 = document.getElementById('column3').style;
		theDiv4 = document.getElementById('column4').style;
		theDiv5 = document.getElementById('breadcrumb').style;
		theDiv.width = contentWidth + "px";
		theDiv.visibility = "visible";
		theDiv.top = (large + headerHeight + breadcrumbHeight + 8) + "px"; 
		 if (targetDiv = "column3") {
			theDiv1.height = large + "px";
			theDiv2.height = large + "px";
			theDiv4.height = large + "px";
		}	
		else if (targetDiv = "column2") {
			theDiv1.height = large + "px";
			theDiv3.height = large + "px";
			theDiv4.height = large + "px";
		}
	else if (targetDiv = "column1") {
			theDiv2.height = large + "px";
			theDiv3.height = large + "px";
			theDiv4.height = large + "px";		
		}
		else if (targetDiv = "column4") {
			theDiv1.height = large + "px";
			theDiv2.height = large + "px";
			theDiv3.height = large + "px";
		}
		else if (targetDiv = "toosmall") {
			theDiv1.height = large + "px";
			theDiv2.height = large + "px";
			theDiv3.height = large + "px";
			theDiv4.height = large + "px";	
		}	
				//alert(headerHeight);
		//theDiv5.left = (breadcrumbLeft) + "px";
	}

TextResizeDetector = function() { 
    var el  = null;
	var iIntervalDelay  = 200;
	var iInterval = null;
	var iCurrSize = -1;
	var iBase = -1;
 	var aListeners = [];
 	var createControlElement = function() {
	 	el = document.createElement('span');
		el.id='textResizeControl';
		el.innerHTML='&nbsp;';
		el.style.position="absolute";
		el.style.left="-9999px";
		var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
		// insert before firstChild
		if (elC)
			elC.insertBefore(el,elC.firstChild);
		iBase = iCurrSize = TextResizeDetector.getSize();
 	};

 	function _stopDetector() {
		window.clearInterval(iInterval);
		iInterval=null;
	};
	function _startDetector() {
		if (!iInterval) {
			iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay);
		}
	};
 	
 	 function _detect() {
 		var iNewSize = TextResizeDetector.getSize();
		
 		if(iNewSize!== iCurrSize) {
			for (var 	i=0;i <aListeners.length;i++) {
				aListnr = aListeners[i];
				var oArgs = {  iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize};
				if (!aListnr.obj) {
					aListnr.fn('textSizeChanged',[oArgs]);
				}
				else  {
					aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]);
				}
			}

 		}
 		return iCurrSize;
 	};
	var onAvailable = function() {
		
		if (!TextResizeDetector.onAvailableCount_i ) {
			TextResizeDetector.onAvailableCount_i =0;
		}

		if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
			TextResizeDetector.init();
			if (TextResizeDetector.USER_INIT_FUNC){
				TextResizeDetector.USER_INIT_FUNC();
			}
			TextResizeDetector.onAvailableCount_i = null;
		}
		else {
			if (TextResizeDetector.onAvailableCount_i<600) {
	  	 	    TextResizeDetector.onAvailableCount_i++;
				setTimeout(onAvailable,200)
			}
		}
	};
	setTimeout(onAvailable,500);

 	return {
		 	/*
		 	 * Initializes the detector
		 	 * 
		 	 * @param {String} sId The id of the element in which to create the control element
		 	 */
		 	init: function() {
		 		
		 		createControlElement();		
				_startDetector();
 			},
			/**
			 * Adds listeners to the ontextsizechange event. 
			 * Returns the base font size
			 * 
			 */
 			addEventListener:function(fn,obj,bScope) {
				aListeners[aListeners.length] = {
					fn: fn,
					obj: obj
				}
				return iBase;
			},
			/**
			 * performs the detection and fires textSizeChanged event
			 * @return the current font size
			 * @type {integer}
			 */
 			detect:function() {
 				return _detect();
 			},
 			/**
 			 * Returns the height of the control element
 			 * 
			 * @return the current height of control element
			 * @type {integer}
 			 */
 			getSize:function() {
	 				var iSize;
			 		return el.offsetHeight;
		 		
		 		
 			},
 			/**
 			 * Stops the detector
 			 */
 			stopDetector:function() {
				return _stopDetector();
			},
			/*
			 * Starts the detector
			 */
 			startDetector:function() {
				return _startDetector();
			}
 	}
 }();

 function init() {
	var iBase = TextResizeDetector.addEventListener(onFontResize,null);
}
function onFontResize(e,args) {
	moveDiv();
}
TextResizeDetector.TARGET_ELEMENT_ID = 'finra-980';
TextResizeDetector.USER_INIT_FUNC = init;
