$(document).ready(function () {
	
	chooseSearchBarToShow();
	
	pageClassConfigurator();
	//sidebarModulesConfigurator();
	
	$(".chzn-select").chosen();
});


function sidebarModulesConfigurator() {
	/*
		This function reads the data attributes of 
		a blank div with id sidebarClassConfigurator and 
		accordingly hides modules from 
		the mall sidebar.
		
		This allows the page design to control
		the appearance of the header.
	*/
	var columnLeft = $("#column_left");
	if(columnLeft.length) {
		var hideModules = $("#sidebarModulesConfigurator").attr("data-hideModules").split(" ");
		while(hideModules.length > 0) {
			var c = "#" + hideModules.pop();
			$(c).addClass("hidden");
		}
	}
}

function pageClassConfigurator() {
	/*
		This function reads the data attributes of 
		a blank div with id pageClassConfigurator and 
		accordingly applies or removes classes from 
		the .page div.
		
		It is needed to apply the right classes, i.e
		withRSidebar, withLSidebar, hasSearchBar, to the 
		.page div. This allows the page design to control
		the appearance of the header.
	*/
	var p = $("#pageClassConfigurator");
	var page = $(".page");
	if(p.length && page.length) {
		var applyClasses = $("#pageClassConfigurator").attr("data-applyClasses").split(" ");
		var removeClasses = $("#pageClassConfigurator").attr("data-removeClasses").split(" ");
		
		while(applyClasses.length > 0) {
			var c = applyClasses.pop();
			$(page).addClass(c);
		}
		while(removeClasses.length > 0) {
			var c = removeClasses.pop();
			$(page).removeClass(c);
		}
	}
}

function chooseSearchBarToShow() {
	var p = $(".page");
	if(p.length) {
		if($(p).hasClass("hasSearchBar")) {
			$(".searchBar").removeClass("hidden");
			$(".searchBarLite").addClass("hidden");
		} else {
			$(".searchBarLite").removeClass("hidden");
			$(".searchBar").addClass("hidden");
		}
	}
}
