/* Mag 200901: Omniture Site Catalyst
 * This function sets variables for Site Catalyst from Omniture
 * The file /includes/sitecatalyst.jsp uses these variables
 */
var omnitureRSID = "whichlocaldev"; //Default value if none is set on the third party page
if (window.omnitureAccount) {var omnitureRSID = omnitureAccount();}//Available in /includes/siteCatalyst.jsp
var s=s_gi(omnitureRSID);

//This function tracks carousel link clicks and is called from pages with carousels. 
//selectedLink is the selector for the selected link
function omnitureCarouselTracker(selectedLink)
{
	var arrOmniture=setOmnitureVariables(omniturePageName);
	/*var selectedLink = $(selectedLink);
	//Carousel Custom Links
	//----------------------
	var carouselLinkText = "";
	var carouselSection = "";
	var buttonText = "";
	var buttonPosition = "";
	//Setting custom link capture for image carousels. Note this relies on html format from: https://whichonline.onjira.com/browse/OD-1213
	if (arrOmniture["section"]!="") {carouselSection = ": " + arrOmniture["section"];}
	else {carouselSection = ": " + document.location;}
	if (selectedLink.parent("li").attr("class")!="") {buttonPosition = ": " + selectedLink.parent("li").attr("class").toLowerCase() + " button"}
	if (selectedLink.html()!="") {buttonText = ": " + selectedLink.html();} 
	carouselLinkText = "carousel" + carouselSection + buttonPosition + buttonText;
	carouselLinkText = carouselLinkText.toLowerCase();
	s.tl(this,'o',carouselLinkText);    */  
}

//Sets custom links on navigation items
function setOmnitureCustomLinks(arrOmniture)
{
	/*
	//Top Nav Custom Links
	//--------------------
	$("#user-controls")
	
	//Setting custom link capture for login on top navigation
	.find("#om-login-tn").click(function (){s.tl(this,'o','log in: top navigation: button');}).end()
	
	//Setting custom link capture for signup on top navigation
	.find("#om-signup-tn").click(function (){s.tl(this,'o','sign up: top navigation');}).end()
	
	
	//Setting custom link capture for search on top navigation
	.find("#om-search-tn").click(function (){ 
		s.tl(this,'o','search: top navigation');
		arrOmniture["events"] += ",event1";     
    }).end()
	
	//Setting custom link capture for log out on top navigation
	.find("#om-logout-tn").click(function (){s.tl(this,'o','log out: top navigation: button');}).end()
	
	//Promo Signup/Login Custom Links
	//--------------------------------
	var promoText = "";
	$("div.subscription-panel").find("a.om-signup-promo").click(function (){
		promoText = "signup: promo: right";
		if ($("div.subscription-panel h2").html()!=""){
			promoText = promoText + ": " + $("div.subscription-panel h2").html();
		}
		if ($(this).html()!=""){
			promoText = promoText + ": " + $(this).find("span").html();
		}
		promoText = promoText.toLowerCase();
		s.tl(this,'o',promoText);
	}).end()
	
	$("div.subscription-panel-b")
	.find("a.om-signup-promo").click(function (){
		promoText = "signup: promo: full";
		if ($("div.subscription-panel-b h2").html()!=""){
			promoText = promoText + ": " + $("div.subscription-panel-b h2").html();
			promoText = promoText.replace("<span>", "");
			promoText = promoText.replace("</span>", "");
		}
		if ($(this).html()!=""){
			promoText = promoText + ": " + $(this).find("span").html();
		}
		promoText = promoText.toLowerCase();
		s.tl(this,'o',promoText);
	}).end()
	.find("a.om-login-promo").click(function (){
		promoText = "login: promo: full";
		if ($("div.subscription-panel-b h2").html()!=""){
			promoText = promoText + ": " + $("div.subscription-panel-b h2").html();
			promoText = promoText.replace("<span>", "");
			promoText = promoText.replace("</span>", "");
		}
		if ($(this).html()!=""){
			promoText = promoText + ": " + $(this).find("span").html();
		}
		promoText = promoText.toLowerCase();
		s.tl(this,'o',promoText);
	}).end()
	*/
	return arrOmniture;
}

function setOmnitureVariables(omPageName)
{
	//Initialising variables array 
	var arrOmniture = new Array();
	arrOmniture["pageName"] = omPageName; 
	arrOmniture["server"] = "";
	arrOmniture["channel"] = "";
	arrOmniture["pageType"] = "";
	arrOmniture["state"] = "";
	arrOmniture["zip"] = "";
	arrOmniture["events"] = "";
	arrOmniture["products"] = "";
	arrOmniture["purchaseID"] = "";
	/*Some evars are reserved and do not appear here*/
	arrOmniture["hier1"] = "";
	
	if (omPageName!=""){
		
		var arrBreadcrumb = omPageName.split(":"); 
		var numChannelHierCount = arrBreadcrumb.length-2; 
		
		if (arrBreadcrumb.length > 0){
			//If the last array item of breadcrumbs has the value of "home" this means this page is a parent
			if ($.trim(arrBreadcrumb[arrBreadcrumb.length-1]) == "home"){
				arrOmniture["pageName"] = arrOmniture["pageName"].substring(0, omPageName.length-6); //Leave ": home" out of the page name as per http://whichonline.onjira.com/browse/TWO-13 to prevent continuity issues in the data
			}
			//Sets s.channel
			for (i=0;i<=numChannelHierCount;i++){
				arrOmniture["channel"] = arrOmniture["channel"] + arrBreadcrumb[i] + ":";
			}
			arrOmniture["channel"] = arrOmniture["channel"].slice(0,arrOmniture["channel"].length-1);
			
			//Sets s.hier1
			for (i=0;i<=numChannelHierCount;i++){
				arrOmniture["hier1"] = arrOmniture["hier1"] + arrBreadcrumb[i] + ",";
			}
			arrOmniture["hier1"] = arrOmniture["hier1"].replace(/, /g, ",");
			arrOmniture["hier1"] = arrOmniture["hier1"].slice(0,arrOmniture["hier1"].length-1);
			
			//Sets s.prop7 - s.prop9: sections and subsections
			for (i=1;i<=numChannelHierCount;i++){
				var iPos = "prop" + (i+6);
				arrOmniture[iPos] = arrBreadcrumb[i];
			}
		}
		
		arrOmniture["section"] = arrBreadcrumb[0];
	}
	arrOmniture = setOmnitureCustomLinks(arrOmniture);
	//Returns array of variable values needed by Site Catalyst
	return arrOmniture;
}
