/* ========================================================================================
	OMNITURE CUSTOM CODE
	Primary Author: Mike Liu (mliu@acumensolutions.com)
	Last update: 02/23/2010 - RD

	This code is included on all TravelChannel.com pages.
   ======================================================================================== */


/*
	====================== BEGIN VARIABLE FUNCTIONS =========================
	buildPageName - builds s.pageName.  This logic is specific to travelchannel.com
	========================================================================
*/

/*
	FUNCTION rebuilds the s.pageName variable which is a friendlier reverse path of the sections,
	sub-sections and article name.  Can only be used once all other variables are set.
*/
var buildPageName = function () {
	// last used to avoid double-printing article/section
	var last = pName = "Home";
	try{
		// if there's only a domain, the page is "Home"
		if (urlVars.length <= 3) {
			return pName;
		}
		// check for a top channel
		if (s.prop15 && s.prop15 != "") {
			// append top channel
			last = s.prop15;
			pName = pName + ":" + s.prop15;

			// if this is a places/trips page, append destination data
			if (s.prop15 == "Travel_Guides") {
				if (s.prop40 && s.prop40 != "") {
					last = s.prop40;
					pName = pName + ":" + s.prop40;
				}
				if (s.prop41 && s.prop41 != "") {
					last = s.prop41;
					pName = pName + ":" + s.prop41;
				}
				if (s.prop42 && s.prop42 != "") {
					last = s.prop42;
					pName = pName + ":" + s.prop42;
				}
				if (s.prop43 && s.prop43 != "") {
					last = s.prop43;
					pName = pName + ":" + s.prop43;
				}
				// append destination subcategory if applicable
				if (s.prop21 && s.prop21 != "") {
					last = s.prop21;
					pName = pName + ":" + s.prop21;
				}
			} else if (s.prop15 == "Travel_Ideas") {
				// append sub-section 1 if applicable
				if (s.prop16 && s.prop16 != "" && urlVars.length > 5) {
					last = s.prop16;
					pName = pName + ":" + s.prop16;
				}
				// append sub-section 2 if applicable
				if (s.prop23 && s.prop23 != "") {
					last = s.prop23;
					pName = pName + ":" + s.prop23;
				}
				// append sub-section 3 if applicable
				if (s.prop24 && s.prop24 != "") {
					last = s.prop24
					pName = pName + ":" + s.prop24;
				}
			} else {
				// append sub-section 1 if applicable
				if (s.prop16 && s.prop16 != "" && urlVars.length > 5) {
					last = s.prop16;
					pName = pName + ":" + s.prop16;
				}
				// append sub-section 2 if applicable
				if (s.prop23 && s.prop23 != "") {
					last = s.prop23;
					pName = pName + ":" + s.prop23;
				}
				// append sub-section 3 if applicable
				if (s.prop24 && s.prop24 != "") {
					last = s.prop24;
					pName = pName + ":" + s.prop24;
				}
			}
		}

		// append articlename if not the same as prop21
		if (s.prop17 && s.prop17 != "" && s.prop17 != last) {
			pName = pName + ":" + s.prop17;
		}
	} catch(e) {

	}
	// strip underscores
	return removeUnderscores(pName);
}




/* ========================================================================================== */
/* ========================= START TRAVELCHANNEL.COM VARIABLES ============================== */
/* ========================================================================================== */

/*
	************** travelchannel.com url-based variables **************
	This section pertains only to the main www.travelchannel.com site.  Some variables are also set in off-site
	pages (s.prop16 subsection, s.prop17 article name) but the logic is different.
	*******************************************************************
*/
try {

	/* START PROP15 - top channel GLOBAL */
	if (urlVars.length > 4) {
		if (urlVars[3] == "Places_Trips") {
			// remove this element
			urlVars.splice(3,1);
		}
		s.prop15 = urlVars[3];
	} else if (urlVars.length == 4) {
		// Add other custom top-channel level variables here
		switch (urlVars[3]) {
			case "Video":
				s.prop15 = "Videos_and_Photos";
				break;
			case "Schedule":
				s.prop15 = "tv_schedule";
				break;
		}
	} else if (urlVars.length <= 3) {
		// TC.com home level, no top channel
		s.prop15 = "Home";
	}
	/* END PROP15 */

	/* PROP15 DETERMINES WHICH OTHER URL VARS ARE SET */
	var tempProp16, tempProp21, tempProp43;
	if (s.prop15 == "Destinations") {
		// set s.prop16 sub-section
		s.prop15 = "Travel_Guides";

		/* START PROP40 - DESTINATION Continent */
		tempProp16 = s.prop40 = urlVars[4];
		/* END PROP40 */

		/* START PROP41 - DESTINATION Country */
		s.prop41 = urlVars[5];
		/* END PROP41 */

		/* START tempPROP21, PROP42, PROP43 - DESTINATION sub-category, State, City */
		// Determine STATE only if Country = US/CAN
		if (s.prop41 == "United_States" || s.prop41 == "Canada") {
			if (urlVars.length > 8) {
				// subcategory after the city name
				tempProp21 = strip(urlVars[8]);
			}
			s.prop42 = urlVars[6];
			tempProp43 = strip(urlVars[7]);
		} else {
			// checks if there is another level of depth
			if (urlVars.length > 7) {
				// subcategory after the city name
				tempProp21 = strip(urlVars[7]);
			}
			// State does not apply, s.prop42 is not defined
			tempProp43 = strip(urlVars[6]);
		}
		s.prop43 = tempProp43;
		/* END tempPROP21, PROP42, PROP43 */
	} else if (s.prop15 == "Travel_Ideas") {
		// set s.prop16 sub-section
		tempProp16 = urlVars[4];

		/* START PROP31 - Destination Content type */
		s.prop31 = urlVars[4];
		/* END PROP31 */
	} else if (s.prop15 == "TV_Shows") {
	/* THIS SECTION PERTAINS TO TV_SHOWS */
		if (urlVars.length >= 5) {
			// set s.prop16 sub-section
			tempProp16 = urlVars[4];

			/* START PROP20 - content area subsection */
			s.prop20 = strip(urlVars[5]);
			/* END PROP20 */
		}
		/* START PROP18 - content area (=tv show) */
		s.prop18 = tempProp16; // equal to s.prop16 which hasn't been set yet
		/* END PROP18 */
	}

	/* START PROP16 - subsection 1 */
	s.prop16 = tempProp16;
	/* END PROP16 */

	/* START PROP21 - destination content type */
	s.prop21 = tempProp21;
	/* END PROP21 */

	/* START PROP23, PROP24 - sub-section 2 and 3 */
	if (urlVars.length > 6) {
		s.prop23 = urlVars[5];
	}

	if (urlVars.length > 7) {
		s.prop24 = urlVars[6];
	}
	/* END PROP23 and PROP24 */

	/* START PROP17 - article name GLOBAL */
	// getting last index of urlVars accounts for extra sub-directories
	// if urlVars.length <= 3, it is the homepage of the domain
	if (urlVars.length > 3) {
		s.prop17 = strip(urlVars[urlVars.length -1]);
	}
	/* END PROP17 */

	/* START PAGENAME */
	s.pageName = buildPageName();
	/* END PAGENAME */



	/*
		****************** NON-URL-based variables ******************
			s.prop19 - search parameters
			s.prop28-30, 32-39 - Video/VCM properties
		*************************************************************
	*/

	/* START PROP12 - Business unit */
	if (!s.prop12) {
		s.prop12 = "TRV";
	}
	/* END PROP12 */

	/* START PROP13 - reserved/unused */
		// RESERVED/UNUSED
	/* END PROP13 */

	/* START PROP28-30 - video properties */
		// Comes automatically from video player
	/* END PROP28-30 */

	/* START PROP32-39 - video properties pulled from TMC */
		// Comes automatically from video player

	/* Set pageVCMID */
	if (typeof(pageVCMID) != "undefined") {
		if (pageVCMID != "") {
			s.prop39 = pageVCMID;
		}
	}
	/* END PROP32-39 */
} catch(e) {

}
/* ========================================================================================== */
/* =========================== END TRAVELCHANNEL.COM VARIABLES ============================== */
/* ========================================================================================== */