$(document).ready(function() {
	
	// help span prepare for  hover effect
	function switch_help() {
		$('span.help').each(function() {
			var this_help = $(this).text();
			$(this).removeClass('help');
			$(this).addClass('help_js');
			$(this).attr('title',this_help);
			$(this).text('Help');
		});
	}
	// add javascript to switch images and spans within table cell from after text to prior to text
	
	$('table td img').each(function () {$(this).parent('td').prepend($(this));});
	$('.search table td span.new').each(function () {$(this).parent('td').prepend($(this));});
	
	switch_help();
	$('span.help_js').qtip({
		position: {
			corner: {
				target: 'bottomRight',
				tooltip: 'topLeft'
			}
		},
		show: { 
			when: 'mouseover'
		},
		hide: {
			when: 'mouseout'
		},
		style: {
			title: { 
				'background-color': '#D6E8F7',
				border: {
					width: 1,
					radius: 5,
					color: '#262261'
				}
			},
			'background-color': '#fff',
			'color': '#262261'
		}		
	});
	$('.payment h1.toggle').each(function() {
		$(this).parent('div').addClass('payment-js');
		$(this).wrapInner('<a href=""></a>');
		var toggle_ht = $(this).height();
		$(this).next('table').hide();
		$(this).children('a').toggle(function() {
				$(this).parents('div').addClass('shown').children('table').show();
				return false;
			},function() {
				$(this).parents('div').removeClass('shown').children('table').hide();
				return false;
			});
		// }
	});
	$('.payment table').each(function() {
		$('tbody td:empty').addClass('empty'); 
		if ($.browser.msie && $.browser.version < 8 && $.browser.version >= 6) {
			var $table = $(this);
			var colGroupCount = $($table).children('colgroup').children('col').size();
			var colGroupCol = new Array(colGroupCount);
			// apply left-hand borders to colgroups in IE6/7
			var z = 0;
			$($table).children('colgroup').each(function(i) {
				var colCount = $($(this)).children('col').size();
				var j = z;
				z += colCount;
				$($table).children().children().children().each(function() {
					if ($(this).attr('colspan') > 1) {
						var y = z - ($(this).attr('colspan')+1);
						$(this).parents('tr').not('.buttons').children(':gt(0)').eq(y).css('borderLeft','1px solid #ffffff');
					} else {
						$(this).parents('tr').not('.buttons').children().eq(z).css('borderLeft','1px solid #ffffff');
					}
					// (':gt(0)').eq(z).css('borderLeft','2px solid white');
				});
			});
			// apply background colours to colgroups in IE6/7
			$($table).children('colgroup').children('col').each(function(i) {
				var $tempCol = $(this).css('backgroundColor');
				$($table).children('tbody, tfoot').children('tr').not('.buttons').each(function() {
					$(this).children('td, th').eq(i).each(function(i) {
						$(this).css('backgroundColor',$tempCol);					});
				});
				$($table).children('thead').children('tr').not('.buttons').each(function() {
					$(this).children('td').eq(i).each(function(i) {
						$(this).css('backgroundColor',$tempCol);					
					});
				});
			});			
		}	
		
	});			
});