/**
##############################################################################################
#
#		Title: Ouch! Homepage Script
#
#		Description: Registers homepage image banner functions with ACP to switch banner images per-theme
#
##############################################################################################
*/
Home = {
	
	/**
	 * Function: init
	 * 
	 * Description: Performs initialisation of behaviour once AccessWidget has initialised
	 */
	init : function(){
		AccessWidget.registerChangeThemeCallback(Home.onChangeTheme);
		Home.onChangeTheme(AccessWidget.currentTheme.split('-')[1], true);
	},
	
	/**
	 * Function: onChangeTheme
	 * 
	 * Description: Handles theme changing in homepage. Swaps banner images to match the new theme.
	 * 
	 * @param {String} name - new theme name
	 * @param {Boolean} initialising - true if the function is being called during initialisation
	 */
	onChangeTheme : function(name, initialising){
		var imgSuffix;
		if (name == "blue"){
			imgSuffix = "_blue.jpg";
		}else if (name == "hiviz"){
			imgSuffix = "_hiviz.jpg";
		}
		else if (name == "soft"){
			imgSuffix = "_soft.jpg";
		}
		else{
			imgSuffix = ".jpg";
		} 
		
		var bannerImgs = bbcjs.dom.getElementsByClassName('home-banner-img');
		for (var i=0; i<bannerImgs.length; i++){
			bannerImgs[i].src = bannerImgs[i].src.replace(/(_blue|_hiviz|_soft)*\.jpg/,imgSuffix);
			if (initialising){
				bannerImgs[i].style.visibility = 'visible';
			}
		}
		
	}
};


/**
 * Compile-time executed code
 */
if (typeof(InstanceInits) == "undefined") {
	InstanceInits = [];
};
InstanceInits.push(Home.init);
/**
  * END
  */
