// FST namespace
var FST = window.FST || {};

// Constants
FST.DEBUG = false;

// Module: FST.Util
FST.Util = (function() {
	
	// Call a certain function on a certain page
	function callOnPage(page, fn, context, args) {
		
		var path = trimSlashRight(window.location.pathname);
		args = args || [];
		
		// String (single page)
		if (typeof page === 'string') {
			
			if (page == '*') {
				fn.apply(context || window, args);
			} else if (page == path) {
				fn.apply(context || window, args);
			}			
			
		// Regular expression (match pages)
		} else if (typeof page.test === 'function') {
			if (page.test(path)) {
				fn.apply(context || window, args);
			}	
			
		// Array of pages (list of pages)
		} else if (typeof page === 'object' && typeof page.length === 'number') {
			for (var i = 0; i < page.length; i++) {
				if (page[i] == path) {
					fn.apply(context || window, args);
				}			
			}
		}	
	}
	
	function ucFirst(string) {
		return string.charAt(0).toUpperCase() + string.slice(1);
	}
	
	// Wrapper for console.log / alert
	function dlog(m) {
		if (!FST.DEBUG) return;
		if (!window.console) {
			var log = window.opera ? window.opera.postError : alert;
			window.console = { log: function(str) { log(str) } };
		}		
		console.log(m);
	}
	
	// Trim right
	function trimSlashRight(string) {
		return string.replace(/\/\/*$/, '');
	}

	// Trim left
	function trimSlashLeft(string) {
		return string.replace(/^\/\/*/, '');
	}
	
	// Reveal public functions
	return {
		call: callOnPage,
		log: dlog,
		trimSlashRight: trimSlashRight,
		trimSlashLeft: trimSlashLeft
	};
	
}());

