$j(document).ready(function() {
		

	// THE FOLLOWING VARIABLES ARE DECLARED OUTSIDE OF THIS FILE:
	// ---------------------------------------------------------
	// ' baseUrl ' (String) is set in app/design/frontend/default/truckerdeluxe/template/page/html/head.phtml
	// ' backgrounds ' (Array) is set in the CMS, under the static block ' bg_graphics '
	// ---------------------------------------------------------
		
	var bgChoiceUrl = window.location.href;

	// iterate through each category in the array, searching for the regular expression that matches the current window location.
	// if a hit is found, look up the corresponding background image and hero graphic, then render it to screen
	if(backgrounds && backgrounds.length > 0) {
		for (var bg in backgrounds) {
			var regExpA = backgrounds[bg][0]; // category name
			var regExpB = backgrounds[bg][1]; // category ID (if available)
			if ((bgChoiceUrl.search(regExpA) != -1) || (regExpB != /____/i && bgChoiceUrl.search(regExpB) != -1)){
				//Fix for Ticket #3: Fix Broken Image Issue on IE 7, 8 and Chrome 
				var bbg=backgrounds[bg][2];
				var cbg=backgrounds[bg][3];
				if(bbg && cbg){
					$j('body').css('background-image', function(){ return "url(" + baseUrl + baseFolder + currentFolder + bbg + ")" });
					$j('.category-image').find('img').attr('src', function(){ return baseUrl + baseFolder + currentFolder + cbg });
					centerWhiteBG();
				}
			}
		}
	}
	
	// set homepage background
	if (bgChoiceUrl == baseUrl) {
		$j('body').css('background-image', function(){ return "url(" + baseUrl + baseFolder + currentFolder + hp_backgrounds[0] + ")" });
		centerWhiteBG();
	}


});

function centerWhiteBG(){
	$j('body').css({backgroundPosition:'top center'});
	$j('body').css({backgroundColor:'#fff'});
}


function trace(message){
	$j('#debug_console').css('background-color','#ffffaa');
	$j('#debug_console').append(message + '<br/>');
}
