﻿jQuery(document).ready(function () {
	var topnavIndex = 1;
	var footerIndex = 1;
	var headerIndex = 1;
	var leftnavIndex = 1;
	var dagensrecIndex = 1;
	var contentIndex = 1;
	var rightnavIndex = 1;
	var quicksearchIndex = 1;

	jQuery(".HeaderLinks a:not([href^=java])").each(function () {
		this.href = setTrackingString(this.href, 'header_', headerIndex);
		headerIndex++;
	});

	jQuery(".ExternalLinks select option").each(function () {
		if (this.value != "") {
			this.value = setTrackingString(this.value, 'header_', headerIndex);
			headerIndex++;
		}
	});

	jQuery("#QuickSearch select option").each(function () {
		if (this.value != "") {
			this.value = setTrackingString(this.value, 'quicksearch_', quicksearchIndex);
			quicksearchIndex++;
		}
	});

	jQuery(".FooterLinks a:not([href^=java])").each(function () {
		this.href = setTrackingString(this.href, 'footer_', footerIndex);
		footerIndex++;
	});

	jQuery("#PageHeader a:not([href^=java])").not("a.Button").each(function () {
		this.href = setTrackingString(this.href, 'topnav_', topnavIndex);
		topnavIndex++;
	});

	jQuery("#Left a:not([href^=java])").each(function () {
		this.href = setTrackingString(this.href, 'leftnav_', leftnavIndex);
		leftnavIndex++;
	});

	jQuery(".RecipeToday a.EmLink:not([href^=java])").each(function () {
		this.href = setTrackingString(this.href, 'dagensrec_', dagensrecIndex);
		dagensrecIndex++;
	});

	jQuery("#Content a:not([href^=java])").not(".RecipeToday a").each(function () {
		this.href = setTrackingString(this.href, 'content_', contentIndex);
		contentIndex++;
	});

	jQuery("#Right a:not([href^=java])").each(function () {
		this.href = setTrackingString(this.href, 'rightnav_', rightnavIndex);
		rightnavIndex++;
	});

});

function setTrackingString(url, name, index) {
		if (url.indexOf('?', 0) != -1) {
		    return url;  //+ '&startlink=' + name + index;
		}
		else {
			return url + '?startlink=' + name + index;
		}
}


