// Fix background image flickering in IE
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(e) { }

// Convert on-tabbed display into tabbed display and activate tabs
$(document).ready(function() {
	var $tabs = $('#ContentChannel div.tabs');
	var $tabnav = $tabs.find('ul.tabNav');
	if ($tabnav.length == 0) {
		$tabnav = $tabs.prepend('<ul class="tabNav selfclear"></li>').find('> ul');
		$tabs	.find('> div')
			.each( function(i) {
				var id = this.id;
				var $h2 = $(this).find('h2');
				var title = $h2.html();
				$tabnav.append('<li><a href="#' + id + '"><span>' + title + '</span></a></li>');
				$h2.remove();
			});
			// Need delay for browsers to get their DOM in order
			setTimeout(function() { $tabs.tabs(); }, 500);
	}
});

var HomepageBanner = {
	init: function() {
		var hi_config = {
			sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			interval: 20, // number = milliseconds for onMouseOver polling interval    
			over: HomepageBanner.mouseover, // function = onMouseOver callback (REQUIRED)    
			timeout: 500, // number = milliseconds delay before onMouseOut    
			out: HomepageBanner.mouseout // function = onMouseOut callback (REQUIRED)    
		};
		$('#Banner li h3 a').hoverIntent(hi_config)
												.click(function(e) {
													e.stopPropagation();
													e.preventDefault();
													document.location.href = this.href;
												});
		$('#Banner').click(function(e) {
			var theClass =  $(this).attr('class');
			$('#Banner').find('a[rel="' + theClass + '"]').click();
		});
		// preload images
		$("<img>").attr("src", "../images/hp/banner1.jpg");
		$("<img>").attr("src", "../images/hp/banner2.jpg");
		$("<img>").attr("src", "../images/hp/banner3.jpg");
	},
	mouseover: function(e) {
		$('#Banner')	.removeClass('banner1')
									.removeClass('banner2')
									.removeClass('banner3')
									.addClass($(this).attr('rel'));		
	},
	mouseout: function(e) {
		// do nothing
	}
};
$(document).ready(HomepageBanner.init);