
jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
}


jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback); 
};


$(document).ready(function() {
	// A necessary evil for the IE6 devil
	$('.top_nav ul li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	// var logoSrc      = parentThemeBase + 'images/logo.gif'
	// var logoHoverSrc = parentThemeBase + 'images/logo-hover.gif';
	// $.preloadImages(parentThemeBase + 'images/logo-hover.gif');
	// $('.logo').hover(function() { $(this).attr('src', logoHoverSrc); },function() { $(this).attr('src', logoSrc); });

	// Fix the png graphics on the subnavigation rollovers for IE < 7
	//$('.top_nav ul li:hover ul').pngFix();

	// Preload main navigation images
	$('.top_nav ul.menu-2 > li > a').each(function() {
		bgImage = parse_background_image($(this).css('background-image'));
		bgImage = bgImage.replace(/\-(off|active)\.gif/, '-hover.gif');
		$.preloadImages(bgImage);
	});
	$.preloadImages(parentThemeBase + 'images/nav/primary_nav_l2_bg-01.png', parentThemeBase + 'images/nav/primary_nav_l2_bg-02.png');

	// Main navigation hover classes
	$('.top_nav ul.menu > li > ul').hover(function() {
		$(this).parent().children('a').addClass('hover');
	},function() {
		$(this).parent().children('a').removeClass('hover');
	});

	// "Activate" the 1st dyanmic widget in the left column
	$('.left_column .widget-dynamic:first').addClass('first');

	// Set the height of the right sidebar
	//$('.right_column').css('height', $('.content_column').height());
});


function toggle_dynamic_widget(arrowElement) {
	// Switch from the 'right' to the 'down' arrow
	var currentArrow = parse_background_image(arrowElement.css('background-image'));
	var newArrow     = parentThemeBase + 'images/blocks/dynamic-arrow-'
	                 + ((currentArrow.indexOf('-down') > 0) ? 'right' : 'down')
	                 + '.gif'
	arrowElement.css('background-image', 'url(' + newArrow + ')');

	// Slide the content area down
	var sliderBlock = arrowElement.siblings('.slider');
	sliderBlock.slideFadeToggle('fast');

	return false;
}


function parse_background_image(imgSrc) {
	return imgSrc.replace(/^url\(('|")?/, '').replace(/\)$/, '');
}

