topsUri = location.pathname.substring(1,location.pathname.length).replace(/\/+$/,'').toLowerCase()

var topsUriParts,topsAssetType,topsSection,topsTopLevelSection,topsAssetId

if(topsUri=='') {
	topsSection='homepage'
	topsTopLevelSection='homepage'
	topsAssetType='hubpage'
	topsAssetId=''
}
else {
	topsUriParts=topsUri.split('/')
	if(topsUriParts.length>=1){
		if (topsUriParts[topsUriParts.length-1].search(/^[0-9\-]+$/)>-1) {
			topsAssetId=topsUriParts.pop().replace(/-/g,'').replace(/^0+/,'')
			topsAssetType=topsUriParts.pop()
			if (!topsAssetType) topsAssetType='static'
		}
		else {
			topsAssetType='hubpage'
			topsAssetId=''
		}
		if(topsUriParts[0]=='guide') topsAssetType=topsUriParts.shift()
		topsTopLevelSection = topsUriParts[0]
		if (!topsTopLevelSection) topsTopLevelSection='general'
		topsSection=topsUriParts.join('/')
		if (!topsSection) topsSection='general'
	}
}

function topsClickTrack(obj,assetId,clickType) {
	if(typeof s_code != "undefined"){
		var linktype='o'
		s.eVar4 = topsGetListingName(assetId)
		if (clickType=='website') {
			linktype='e'
			s.events="event1"
			// turn off auto tracking
			s.trackExternalLinks=false
		}
		else if (clickType=='contact') s.events="event2"
		else if (clickType=='profile') s.events="event3"
		else if (clickType=='map') s.events="event4"
		else if (clickType=='moreinfo') s.events="event5"
		else if (clickType=='ypad') s.events="event7"
		else if (clickType=='reservation') s.events="event9"
		else if (clickType=='phone') s.events="event13"
		s.products=";"+assetId
		s.linkTrackVars='prop1,eVar1,eVar4,eVar6,events,products'
		s.linkTrackEvents=s.events
		s.tl(obj,linktype,clickType+' link')
	}
	return true
}

function topsGetListingUids() {
	var maxlength=1000
	var uids=[]
	var idcount=0
	var das=document.getElementsByTagName('a')
        var name;
	for(var i=0;i<das.length;i++){
		if ((das[i].getAttribute('class')=='ListingTracker')||(das[i].getAttribute('className')=='ListingTracker')) {
			name=das[i].id
			if (name.substring(0,3)=='UID') {
			    uids.push(name.substring(3,name.length))
			}
		}
	}
	return ';'+uids.join(',;');
}

function topsGetListingName(assetId) {
	var trackerEl=document.getElementById('UID'+assetId)
	return (trackerEl)?trackerEl.getAttribute('title'):''
}

if ((typeof topsSearchResultsPage != "undefined") && (topsSearchResultsPage==1)) {
	s.pageName="search"
	s.channel="search"
	s.prop1=s.getQueryParam('q')
	s.prop3=s.getQueryParam('type')
	s.prop4=document.title
	s.prop9=s.getQueryParam('r')
	s.eVar2=s.pageName
	s.eVar4=s.pageName +':'+ s.prop3 +':'+ s.prop9
	s.products = topsGetListingUids()
	s.events="event6"
	s.eVar1=s.prop1
	s.eVar6=s.prop1
	s.hier1=s.channel+"/"+s.prop3+"/"+s.prop1+"/"+s.prop9
	if ((typeof topsSearchFailed != "undefined") && (topsSearchFailed==1)) {
		s.prop2 = s.prop3 +':'+ s.prop9 +':'+ s.prop1
	}
}
else {
	s.pageName=Array(topsSection,topsAssetType,document.title).join(':')
	s.channel=topsTopLevelSection
	s.prop4=document.title
	s.prop5=topsSection
	s.prop6=topsAssetType
	s.prop7=topsAssetId
	s.eVar2=s.pageName
	s.eVar4=s.channel
	s.hier1=topsUri
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return "";
}

//omniture on finder results set omniture code based on fq 
var fq=getQueryVariable("fq"); //check for fq in querystring 
if (fq != "") { //if fq is found then set s.prop12
  s.prop12=document.title
}

