// cdz_setup.js
//
//      Author:  Aaron Fischer (aaron.a.fischer@intel.com)
//     Created:  2004.10.08
// Description:  Expands the wa_setup.js API with additional methods for programmatically
//               accessing a web page's metadata.

if (location.pathname.indexOf(".")>-1) {
	var pathObj = ParseURLPathName( location.pathname.toLowerCase());
}
else {
	var pathObj = ParseURLPathName( location.pathname.toLowerCase() +"/" );
}



// ParseURLPath()
//        input:  string - the URL path name of the web page in question
//       output:  object - pathObject { dir[], fullDir, fileName }
//  description:  parses the URL path into its component directories and file name.
//                e.g. "/a/b/foo.htm" becomes pathObject.dir[0] = "a",
//			      pathObject.dir[1] = "b", pathObject.fullDir = "/a/b/",
//				  pathObject.fileName = "foo.htm"
//
function ParseURLPathName(strURL)
{
	var pathObject = new Object();
	pathObject.dir = new Array();

	// Assumed input string format:
	// <URL_path><file_name> i.e. <dir1><dir2>...<dirN><file_name>
	//
	// /^             // match at beginning of string
	//   (.+?)        // non-greedily match and capture all.  Targets <dir1>
	//   (?:\/)+      // match zero or more "/" without capture
	//   (.*)         // greedily match all.  Targets <dir2>...<dirN><file_name>
	// /
	//
	// Note:  This is a much more complicated approach than strURL.split("/"),
	// but I thought it necessary for the rare case when multiple forward-slashes
	// are included in the URL path, e.g. a/b//c/d//foo.htm
	//
	i = 0;
	pathObject.fullDir = "/";
	strURL = strURL.replace(/^\//,"");  // Remove any beginning / in our URL
	while ((node = strURL.match(/^(.+?)(?:\/)+(.*)/)) && node[0].length)
	{
		pathObject.dir[i++] = node[1];
		pathObject.fullDir += node[1] + "/";
		strURL = node[2];
	}
	pathObject.fileName = strURL;
	return pathObject;
}

//defines the mapping for the content category code for each uri
var contentCategoriesByUri = {
	"/learn/":"ssc:nav",
	"/learn":"ssc:nav",
	"/learn/practical-advice":"ssc:nav",
	"/learn/practical-advice/":"ssc:nav",
	"/learn/practical-advice/before-you-buy/":"ssc:nav",
	"/learn/practical-advice/before-you-buy":"ssc:nav",
	"/learn/practical-advice/entertainment/":"ssc:nav",
	"/learn/practical-advice/entertainment":"ssc:nav",
	"/learn/practical-advice/security/":"ssc:nav",
	"/learn/practical-advice/security":"ssc:nav",
	"/learn/practical-advice/email/":"ssc:nav",
	"/learn/practical-advice/email":"ssc:nav",
	"/learn/practical-advice/wireless/":"ssc:nav",
	"/learn/practical-advice/wireless":"ssc:nav",
	"/learn/practical-advice/computer-maintenance/":"ssc:nav",
	"/learn/practical-advice/computer-maintenance":"ssc:nav",
	"/learn/buying-guides/":"ssc:nav",
	"/learn/buying-guides":"ssc:nav",
	"/learn/buying-guides/index/":"ssc:nav",
	"/learn/buying-guides/index":"ssc:nav",
	"/learn/buying-guides/tech-newcomer":"ssc:benefit",
	"/learn/buying-guides/family-coordinator":"ssc:benefit",
	"/learn/buying-guides/student":"ssc:benefit",
	"/learn/buying-guides/digital-media-fan":"ssc:benefit",
	"/learn/buying-guides/always-connected":"ssc:benefit",
	"/learn/glossary":"ssc:intro",
	"/learn/see-inside-your-computer":"ssc:overview",
	"/shop/":"ssc:nav",
	"/shop":"ssc:nav"
};
if (contentCategoriesByUri[location.pathname]) {
	window.p_contentcat = contentCategoriesByUri[location.pathname];
} else if (location.pathname.search(/\/learn\/practical-advice\/[\w-]+\/[\w-]+/) != -1) {
	window.p_contentcat = "ssc:learn";
} else if (location.pathname.search(/\/shop\/[\w-]+/) != -1) {
	window.p_contentcat = "shop:browse";
}