$(function() {
	resizePanels(); 
	resizeWrap(); 
	newWindows(); 
	homePanels(); 
	homeColumns(); 
	memberColumns(); 
	linksColumns(); 
	rollovers(); 
}); 

function newWindows() {
	//	NEW WINDOW LINKS
	var anchor_array = document.getElementsByTagName('a'); 
	
	for (var i = 0; i < anchor_array.length; i++) {
		if (anchor_array[i].className == 'newWindow') {
			anchor_array[i].onclick = openNewWindow; 
		}
	}
	
	function openNewWindow() {
		window.open(this.href); 
		return false; 
	}
}

function homePanels() {
//	PANELS: GET A QUOTE (HOME PAGE)
	if (document.getElementById('panel_liabilityInsurance')) {
		var panel_array = new Array(); 
		var tallestPanel = null; 
		var tallestPanelHeight = 0; 

		panel_array.push(document.getElementById('panel_liabilityInsurance'))
		panel_array.push(document.getElementById('panel_motorInsurance'))
		panel_array.push(document.getElementById('panel_trailerInsurance'))

		for (var i = 0; i < panel_array.length; i++) {
			if (panel_array[i].offsetHeight > tallestPanelHeight) {
				tallestPanel = panel_array[i]; 
				tallestPanelHeight = panel_array[i].offsetHeight; 
			}
		}

		for (var i = 0; i < panel_array.length; i++) {
			if (panel_array[i] != tallestPanel) {
				var margin = tallestPanelHeight - panel_array[i].offsetHeight; 
				panel_array[i].style.height = tallestPanelHeight + 'px'; 
				panel_array[i].getElementsByTagName('img')[0].style.marginTop = margin + 'px'; 
			}
		}
	}
}

function homeColumns() {
	//	COLUMNS (HOME PAGE)
	if (document.getElementById('index_col_right')) {
		var col_left_1 = document.getElementById('col_left_1'); 
		var col_left_2 = document.getElementById('col_left_2'); 
		var col_left_3 = document.getElementById('col_left_3'); 
		var col_right = document.getElementById('index_col_right'); 

		//	alert(col_left_3.offsetHeight); 

		if (col_left_1.offsetHeight + col_left_2.offsetHeight + col_left_3.offsetHeight > col_right.offsetHeight) {
			col_right.style.height = col_left_1.offsetHeight + col_left_2.offsetHeight + col_left_3.offsetHeight + 'px'; 
		} else {
			var para = document.getElementsByTagName('p'); 
			
			for (var i = 0; i < para.length; i++) {
				if (para[i].className == 'more_info') {
					para[i].style.paddingBottom = col_right.offsetHeight - col_left_1.offsetHeight - col_left_2.offsetHeight - col_left_3.offsetHeight -18 + 'px'; 
				}
			}
		}
	}
}

function memberColumns() {
	//	BECOME A MEMBER
	if (document.getElementById('member_col_left') && document.getElementById('member_conditions')) {
		var member_col_left = document.getElementById('member_col_left'); 
		var member_conditions = document.getElementById('member_conditions'); 

		if (member_col_left.offsetHeight > member_conditions.offsetHeight) {
			member_conditions.style.height = member_col_left.offsetHeight - 9 + 'px'; 
		}
	}
}

// LEVEL SILVER/GOLD PANELS ON BENEFITS PAGE
function resizePanels() {
	var height_silver = $('#benefit_panel_silver').height();
	var height_gold = $('#benefit_panel_gold').height();

	if (height_silver > height_gold) {
		$('#benefit_panel_gold>p:last').css('paddingTop', height_silver - height_gold); 
	} else {
		$('#benefit_panel_silver>p:last').css('paddingTop', height_gold - height_silver); 
	}
}

// CONTINUE WRAP TO BOTTOM OF WINDOW
function resizeWrap() {
	var height_wrap = $('#wrap').height();
	var height_window = $(window).height();
//	alert (height_window); 

	if (height_window > height_wrap) {
		$('#wrap').height(height_window - 40); 
	}
}

function linksColumns() {
	var colLeftHeight = $('.page_links .col_1-2_left').height(); 
	var colRightHeight = $('.page_links .col_1-2_right').height(); 
	
//	alert(colRightHeight); 

	if (colLeftHeight > colRightHeight) {
		$('.page_links .col_1-2_right li').css('marginBottom', (colLeftHeight - colRightHeight) / 3); 
	} else if (colRightHeight > colLeftHeight) {
		$('.page_links .col_1-2_left li').css('marginBottom', 10); 
	}
}

function rollovers() {
	$('.rollover').mouseover(function() {
		var bn_src = this.src; 
		var bn_src_mo = bn_src.substring(0, bn_src.length - 4); 
		this.src = bn_src_mo + '_mo.png'; 
	}).mouseout(function() {
		var bn_src_mo = this.src; 
		var bn_src = bn_src_mo.substring(0, bn_src_mo.length - 7); 
		this.src = bn_src + '.png'; 
	}); 
}