var domain ='';
var domainRef ='';
function init(d, dr) {
	domain = d;
	domainRef = dr;
	$(document).ready(function(){
		initAccordion();
		// fix breadcrumbs
		$("#breadcrumbs li:last").removeAttr('class');
		$("#breadcrumbs li").each(function(){
			if ($(this).attr('class')) {
				$(this).wrapInner('<a href="'+$(this).attr('class')+'"></a>');
			}
		});
		stripeTable()
	});
}
jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", domainRef+arguments[i]);
  }
}
function stripeTable() {
	$("table.stripe tr:even").addClass("even");
	$("table.stripe tr:odd").addClass("odd");
}

// requires jquery.hoverIntent.js plugin
// requires jquery.cookie.js plugin
function initAccordion() {
	var openIndex = $.cookie("accordion-open") ? $.cookie("accordion-open") : "0";
	
	$('#menu ul').not('#' + openIndex).hide();
	if (openIndex == "0") {
//		$('#menu ul:first').show().prev().addClass("selected"); //commented out to prevent the menu opening to a default onload
	} else {
		$('#menu ul[id=' + openIndex + ']').show().prev().addClass("selected");
	}
	
	$('#menu li:has(ul)').addClass('with-sub');
	
	$('#menu li a').hoverIntent(function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$.cookie("accordion-open", checkElement.attr('id'), { path: '/'})
			$('#menu ul:visible').slideUp('normal').prev().removeClass("selected");
			checkElement.slideDown('normal').prev().addClass("selected");
			return false;
		}
	}, function(){});
}