/* ========================================================================================
	OMNITURE CUSTOM CODE
	Primary Author: Mike Liu (mliu@acumensolutions.com)
	Last update: 02/03/2010 - Rob DeHart

	This code is included on third-party Travel Channel sites
   ======================================================================================== */

/*
	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.  This version
	is specific to third-party sites and will not work properly with travelchannel.com code.
*/
var buildThirdPartyPageName = function () {
	// last used to avoid double-printing article/section
	var last=pName = "";
	try{
		if (s.prop15 && s.prop15 != "") {
			// append top channel
			last = s.prop15;
			pName = s.prop15;
		}

		// Prepend "Home" for static pages and ManVFoodLIVE
		// using specific strings to avoid false positives
		if (url.indexOf("trv/hd/html") >= 0 || url.indexOf("travelchannel.com/Man_v_Food_LIVE") >= 0) {
			pName = "Home";
		}

		// append sub-section 1 if applicable
		if (s.prop16 && s.prop16 != "") {
			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 articlename if not the same as prop21
		if (s.prop17 && s.prop17 != "") {
			if (s.prop17 != last) {
				pName = pName + ":" + s.prop17;
			}
		}
	} catch(e) {

	}
	// strip underscores
	return removeUnderscores(pName);
}

var removeHyphens = function (string) {
	if (string) {
		return string.replace(/\-/g, ' ');
	}
}

/* logic for WorldHum blog */
var doWorldHum = function () {
	if (urlVars.length >= 4) {s.prop16 = urlVars[3];}
	if (urlVars.length >= 5) {s.prop23 = urlVars[4];}
	if (urlVars.length == 6) 
	{
		var l5 = urlVars[5].length;
		var isArticle = urlVars[5].substring((l5-8),(l5-6));
		if (isArticle = "20") {s.prop17 = urlVars[5];}
		else {s.prop24 = urlVars[5];}	
	}
	if (urlVars.length >= 7) 
	{
		if (urlVars[4] == "tags") {s.prop24 = urlVars[6];} 
	
	}
}

/* logic for Sweepstakes */
var doSweeps = function () {
	if (urlVars.length > 4) {
		if (urlVars[3] == "sweeps") {
			if (urlVars.length > 5) {
				tempprop23 = urlVars[4];
			}
		} else {
			tempprop23 = urlVars[3];
		}
	}
	// pull article name from querystring parameter
	if (tempprop16 == "Travel_Bug_Sweepstakes") {
		try {
			if (qsParams["method"]) {
				tempprop17 = qsParams["method"];
			} else if (qsParams["page"]) {
				tempprop17 = qsParams["page"];
			}
		} catch (e) {

		}
	}
}

/* logic for discussion forums */
var doForum = function () {
	// Adds /f/##### forum ID to the end of prop16
	if (url.indexOf("/a/frm/") >= 0) {
		tempprop16 = stripForum(document.title);
		tempprop16 += " [TopicID: " + url.substring(url.indexOf("/a/frm/f/")+9, url.length) + "]";
	}
	// If at the thread level, set prop23 to the message ID
	if (url.indexOf("/a/tpc/") >= 0) {
		tempprop16 = stripForum(document.title);
		tempprop16 += " [TopicID: " + url.substring(url.indexOf("/a/tpc/f/")+9, url.indexOf("/m/")) + "]";
		tempprop23 = " [MessageID: " + url.substring(url.indexOf("/m/")+3, url.length) + "]";
	}
	// if this is at a forum level, capture forum id
	if (url.indexOf("/a/cfrm/f/") >= 0) {
		tempprop16 = "[ForumID: " + url.substring(url.indexOf("/a/cfrm/f/")+10, url.length) + "]";
	}
}

/* logic for TravelChannel Academy */
var doAcademy = function () {
	// remove duplicate "academy" level directory
	if (urlVars[3] == "Academy") {
		urlVars.splice(3,1);
	}

	if (urlVars.length > 4) {
		tempprop16 = urlVars[3];
	}
}

/* helper function for forum titles to remove " - powered by ____" */
var stripForum = function (string) {
	var temptitle = string.split(" -");
	return temptitle[0];
}

/* ========================================================================================== */
/* ========================== START THIRD-PARTY SITE VARIABLES ============================== */
/* ========================================================================================== */

var tempprop15, tempprop16, tempprop17, tempprop23;

/*
	Set up hostname-dependent top channels.  Switch-case block doesn't include podcasts, show site blogs
	or worldhum since the hostname may vary
*/
try {
	switch (urlVars[2]) {
		case "f.chtah.com":
			tempprop15 = "Newsletter";
			break;
		case "ebm.cheetahmail.com":
			tempprop15 = "Newsletter";
			break;
		case "travelchannel.sidestep.com":
			tempprop15 = "Book_a_Trip";
			break;
		case "travelchannel.fogglight.com":
			tempprop15 = "Book_a_Trip";
			break;
		case "go.travelchannel.com":
			tempprop15 = "Mobile";
			tempprop16 = "Travel_Channel_GO";
			// check for FAQ page
			if (fullURL.indexOf("partners/go/faq.html") > 0) {
				tempprop17 = s.prop23 = "Travel Channel GO FAQ";
			}
			break;
		case "goblog.travelchannel.com":
			tempprop15 = "Mobile";
			tempprop16 = "Travel_Channel_GO";
			tempprop17 = "Travel_Channel_GO_Blog";
			break;
		case "travelchannel.promo.eprize.com":
			tempprop15 = "Sweepstakes";
			tempprop16 = "Travel_Bug_Sweepstakes";
			doSweeps();
			break;
		case "win.travelchannel.com":
			tempprop15 = "Sweepstakes";
			tempprop16 = "Travel_Bug_Sweepstakes";
			doSweeps();
			break;
		case "singapore-sweeps.travelchannel.com":
			tempprop15 = "Sweepstakes";
			tempprop16 = "Samantha_Brown_Singapore_Sweeps";
			doSweeps();
			break;
		case "discussions.travelchannel.com":
			tempprop15 = "Discussions";
			doForum();
			break;
		case "www.travelchannelacademy.com":
			tempprop15 = "Academy";
			doAcademy();
			break;
	}

	/* account for variable podcasts */
	if (urlVars[2].indexOf("podcast.travelchannel.com") >= 0) {
		temp = urlVars[2].substring(0, urlVars[2].indexOf("podcast")-1);
		tempprop15 = "Podcasts";
		tempprop16 = temp;
	}
		
	
	
	/* account for static TravelChannel HD pages */
	if (url.indexOf("trv/hd/html") >= 0) {
	}

	/* account for Man_v_Food_LIVE event */
	if (url.indexOf("travelchannel.com/Man_v_Food_LIVE") >= 0) {
		tempprop15 = "TV_Shows";
		tempprop16 = "Man_v_Food_LIVE";
		tempprop18=s.prop18 = "Man_V_Food_LIVE";

		// set subcategory if there is one
		if (urlVars.length > 4) {
			tempprop23 = urlVars[4];
		}
	}

	/* START PROP12 - Business unit */
	if (!s.prop12) {
		s.prop12 = "TRV";
	}
	/* END PROP12 */

	/* START PROP15 - top channel, different based on hostname */
	s.prop15 = tempprop15;
	/* END PROP15 */

	/* START PROP16 - sub-section 1 */
	s.prop16 = tempprop16;
	/* END PROP16 */

	/* START PROP23 - sub-section 2 */
	s.prop23 = tempprop23;
	/* END PROP23 */

	/* START PROP17 - article name */
	// only set article if it wasn't previously
	if (!tempprop17 || tempprop17 == "") {
		tempprop17 = urlVars[urlVars.length-1];
	}
	if (urlVars.length > 3) {
		s.prop17 = strip(tempprop17);
	}
	/* END PROP17 */
	
	

/* blogs */
	if (urlVars[2].indexOf("blog.travelchannel.com") >= 0) {
		s.channel = "travel_blog";
		s.prop15 = "Travel_Blog";
		s.prop20 = "Blog";
		
		if (archive_exists == "1") {
			s.prop17 = the_archive.replace(/\s/g,"-");
		}
		else {
			s.prop17 = the_title;
		}
		
		s.prop16=urlVars[3];
		temp18=urlVars[3];
		
		if (temp18.indexOf("no-reservations") >= 0 || temp18.indexOf("anthony-bourdain") >= 0) {
			s.prop18 = "Anthony_Bourdain";
		}
		else if (temp18.indexOf("bizarre") >= 0) {
			s.prop18 = "Bizarre_Foods";
		}
		else if (temp18.indexOf("dhani") >= 0) {
			s.prop18 = "Dhani_Jones";
		}
		else if (temp18.indexOf("samantha-brown") >= 0) {
			s.prop18 = "Samantha_Brown";
		}
		else if (temp18.indexOf("americas-worst-driver") >= 0) {
			s.prop18 = "Americas_Worst_Driver";
		}
		else if (temp18.indexOf("food-wars") >= 0) {
			s.prop18 = "Food_Wars";
		}
		else if (temp18.indexOf("the-traveling-type") >= 0) {
			s.prop18 = "";
		}
		else {
			s.prop18 = temp18;
		}
		
		var blhref = location.href;
		if (blhref.indexOf("#comment") !=-1  || blhref.indexOf("#respond") !=-1) {
			s.events="event1,event31";  //post a comment
		}
		
		s.prop47 = the_tags;
		//s.pageName = "travel blog:" + s.prop16 + ":" + s.prop17;
	}
	
	
/* World Hum */
	if (urlVars[2].indexOf("www.worldhum.com") >=0) {
		s.channel = "World Hum";
		s.prop15 = "World Hum";
		doWorldHum();
	}

	s.pageName = removeHyphens(buildThirdPartyPageName());
} catch (e) {

}


