// Main Tracking Script
/*---------------------------------------------
Setup _gaq variable for Async tracking and Config properties
---------------------------------------------*/
var _gaq = _gaq || [];
gaConfig = {
	staging: (location.host == "www.jaguar.com" || location.host == "rules.config.jaguar.com") ? 0 : 1,
	page: {
		url: location.pathname,
		sreferrer: null,
		campaignid: null,
		market: location.pathname.substr(1,2),
		language: location.pathname.substr(4,2),
		domain: null,
		configurator: 0,
		configPages : []
	},
	gaCampaign: {
		content: null,
		medium: null,
		campaign: null,
		term: null,
		source: null
	},
	gaCookie: {
		utma: null,
		utmb: null,
		utmc: null,
		utmk: null,
		utmv: null,
		utmx: null,
		utmz: null
	},
	gaTracking: {
		enabled: 1
	},
	accounts: {
		globalAccount: null,
		marketAccount: null
	},
	script: {
		url: null,
		domload: 0
	},
	config: {
		events: 0
	}
};

marketmap = {
	qa: {
		markets: [
			{
				market: 'gb',
				languages: [
					{
						language: 'en',
						value: 'UA-22391928-2'
					}
				]
			},
			{
				market: 'gl',
				languages: [
					{
						language: 'en',
						value: 'UA-22391928-3'
					}
				]
			}
		],
		defaults: {
			globalAccount: 'UA-22391928-1',
			defaultAccount: 'UA-22391928-3'
		}
	},
	live: {
		markets: [
			{
				market: 'at',
				languages: [
					{
						language: 'de',
						value: 'UA-7771287-1'
					}
				]
			},
			{
				market: 'au',
				languages: [
					{
						language: 'en',
						value: 'UA-7771474-1'
					}
				]
			},
			{
				market: 'be',
				languages: [
					{
						language: 'fr',
						value: 'UA-7771318-1'
					},
					{
						language: 'nl',
						value: 'UA-7771318-1'
					}
				]
			},
			{
				market: 'ca',
				languages: [
					{
						language: 'en',
						value: 'UA-7771338-1'
					},
					{
						language: 'fr',
						value: 'UA-7771338-1'
					}
				]
			},
			{
				market: 'ch',
				languages: [
					{
						language: 'de',
						value: 'UA-7771414-1'
					},
					{
						language: 'fr',
						value: 'UA-7771414-1'
					}
				]
			},
			{
				market: 'cn',
				languages: [
					{
						language: 'zh',
						value: 'UA-11079399-1'
					}
				]
			},
			{
				market: 'cz',
				languages: [
					{
						language: 'cs',
						value: 'UA-18926527-1'
					}
				]
			},
			{
				market: 'de',
				languages: [
					{
						language: 'de',
						value: 'UA-7771493-1'
					}
				]
			},
			{
				market: 'es',
				languages: [
					{
						language: 'es',
						value: 'UA-7771526-1'
					}
				]
			},
			{
				market: 'fr',
				languages: [
					{
						language: 'fr',
						value: 'UA-7771535-1'
					}
				]
			},
			{
				market: 'hk',
				languages: [
					{
						language: 'en',
						value: 'UA-27392217-1'
					}
				]
			},
			{
				market: 'ie',
				languages: [
					{
						language: 'en',
						value: 'UA-7771542-1'
					}
				]
			},
			{
				market: 'in',
				languages: [
					{
						language: 'en',
						value: 'UA-18928095-1'
					}
				]
			},
			{
				market: 'gl',
				languages: [
					{
						language: 'en',
						value: 'UA-7771467-1'
					}
				]
			},
			{
				market: 'it',
				languages: [
					{
						language: 'it',
						value: 'UA-7771551-1'
					}
				]
			},
			{
				market: 'jp',
				languages: [
					{
						language: 'ja',
						value: 'UA-7771428-1'
					}
				]
			},
			{
				market: 'lu',
				languages: [
					{
						language: 'fr',
						value: 'UA-7771566-1'
					}
				]
			},
			{
				market: 'me',
				languages: [
					{
						language: 'ar',
						value: 'UA-10656548-1'
					},
					{
						language: 'en',
						value: 'UA-10656548-1'
					}
				]
			},
			{
				market: 'nl',
				languages: [
					{
						language: 'nl',
						value: 'UA-7771580-1'
					}
				]
			},
			{
				market: 'nz',
				languages: [
					{
						language: 'en',
						value: 'UA-7771439-1'
					}
				]
			},
			{
				market: 'pt',
				languages: [
					{
						language: 'pt',
						value: 'UA-7771592-1'
					}
				]
			},
			{
				market: 'ru',
				languages: [
					{
						language: 'ru',
						value: 'UA-7771601-1'
					}
				]
			},
			{
				market: 'se',
				languages: [
					{
						language: 'sv',
						value: 'UA-7771640-1'
					}
				]
			},
			{
				market: 'gb',
				languages: [
					{
						language: 'en',
						value: 'UA-7713784-1'
					}
				]
			},
			{
				market: 'us',
				languages: [
					{
						language: 'en',
						value: 'UA-7771652-1'
					}
				]
			},
			{
				market: 'za',
				languages: [
					{
						language: 'en',
						value: 'UA-7771454-1'
					}
				]
			}
		],
		defaults: {
			globalAccount: 'UA-13088238-1',
			defaultAccount: 'UA-13088238-3'
		}
	}
};

/*---------------------------------------------
Map Javascript function to jQuery function
---------------------------------------------*/
var pageTracker = {
	_trackPageview: function(url) {
		_gaq.push(
			['g._trackPageview', url.split('?')[0]],
			['m._trackPageview', url.split('?')[0]]);
	}
}

var tPath = (location.host == 'rules.config.jaguar.com' || location.host == 'rules-staging.configureconnect.com' || location.host == 'rules.configureconnect.com') ? (location.host == 'rules.config.jaguar.com' || location.host == 'rules.configureconnect.com') ? 'http://www.jaguar.com/system/logging' : 'https://preview01.jaguar.com/system/logging' : (typeof tPath == 'undefined') ? '/system/logging' : tPath;
(function($) {
	/*---------------------------------------------
	1. Load Configuration file
	---------------------------------------------*/
	$.fn.loadConfig = function() {
		$.fn.initGA();
		if(!gaConfig.page.configurator) {
			$.fn.ExchangeSoMeLinks();
			$(document).ajaxComplete(function() {
				$.fn.addEvents();
			});
		};
	};
	
	/*---------------------------------------------
	2. Set Accounts
	---------------------------------------------*/
	$.fn.setAccounts = function() {
		var data = (gaConfig.staging) ? 'marketmap.qa.markets' : 'marketmap.live.markets';
		gaConfig.accounts.globalAccount = (gaConfig.staging) ? marketmap.qa.defaults.globalAccount : marketmap.live.defaults.globalAccount;
		var dAcc = (gaConfig.staging) ? marketmap.qa.defaults.defaultAccount : marketmap.live.defaults.defaultAccount;
		var mAcc = null;
		if(gaConfig.staging) {
			for(var a=0; a < marketmap.qa.markets.length; a++) {
				if(gaConfig.page.market == marketmap.qa.markets[a].market) {
					for(var b=0; b < marketmap.qa.markets[a].languages.length; b++) {
						if(gaConfig.page.language == marketmap.qa.markets[a].languages[b].language) {
							mAcc = marketmap.qa.markets[a].languages[b].value;
						};
					};
				};
			};
		} else {
			for(var a=0; a < marketmap.live.markets.length; a++) {
				if(gaConfig.page.market == marketmap.live.markets[a].market) {
					for(var b=0; b < marketmap.live.markets[a].languages.length; b++) {
						if(gaConfig.page.language == marketmap.live.markets[a].languages[b].language) {
							mAcc = marketmap.live.markets[a].languages[b].value;
						};
					};
				};
			};
		};
		
		if(mAcc == null) {
			gaConfig.accounts.marketAccount = dAcc;
		} else {
			gaConfig.accounts.marketAccount = mAcc;
		};
		
		gaConfig.page.domain = (gaConfig.page.market == 'us' || gaConfig.page.market == 'gb' || gaConfig.page.market == 'ru') ? 'none' : '.jaguar.com';
		_gaq.push(
			['g._setAccount', gaConfig.accounts.globalAccount],
			['g._setDomainName', gaConfig.page.domain],
			['g._setAllowLinker', true],
			['g._setAllowHash', false],
			['m._setAccount', gaConfig.accounts.marketAccount],
			['m._setDomainName', gaConfig.page.domain],
			['m._setAllowLinker', true],
			['m._setAllowHash', false]);
	};
	
	/*---------------------------------------------
	3. Get URL Variable
	---------------------------------------------*/
	$.fn.getUrlVars = function(variable) {
		var u = location.href.replace(location.protocol + '//', '').replace(location.host, '');
		var result = null;
		var name = variable.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+variable+"=([^&]*)";
		var regex = new RegExp(regexS,"i");
		var results = regex.exec(u);
		if(results == null) {
			return result;
		} else {
			return results[1];
		};
	};
	
	/*---------------------------------------------
	4. Cookie Plugin
	---------------------------------------------*/
	jQuery.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			// CAUTION: Needed to parenthesize options.path and options.domain
			// in the following expressions, otherwise they evaluate to undefined
			// in the packed version for some reason...
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	};
	
	/*---------------------------------------------
	5. Setup Campaign
	---------------------------------------------*/
	$.fn.setupCampaign = function() {
		if($.fn.getUrlVars('campaignid') != null) {
			gaConfig.page.campaignid = $.fn.getUrlVars('campaignid');
			$.cookie('campaignid', gaConfig.page.campaignid);
		} else {
			gaConfig.page.campaignid = $.cookie('campaignid');
		};
		
		if($.fn.getUrlVars('sreferrer') != null) {
			gaConfig.page.sreferrer = $.fn.getUrlVars('sreferrer');
			$.cookie('sreferrer', gaConfig.page.sreferrer);
		} else {
			gaConfig.page.sreferrer = $.cookie('sreferrer');
		};
		
		gaConfig.gaCampaign.campaign = $.fn.getUrlVars('utm_campaign');
		gaConfig.gaCampaign.content = $.fn.getUrlVars('utm_content');
		gaConfig.gaCampaign.medium = $.fn.getUrlVars('utm_medium');
		gaConfig.gaCampaign.source = $.fn.getUrlVars('utm_source');
		gaConfig.gaCampaign.term = $.fn.getUrlVars('utm_term');
		gaConfig.gaCookie.utma = $.fn.getUrlVars('__utma');
		gaConfig.gaCookie.utmb = $.fn.getUrlVars('__utmb');
		gaConfig.gaCookie.utmc = $.fn.getUrlVars('__utmc');
		gaConfig.gaCookie.utmk = $.fn.getUrlVars('__utmk');
		gaConfig.gaCookie.utmv = $.fn.getUrlVars('__utmv');
		gaConfig.gaCookie.utmx = $.fn.getUrlVars('__utmx');
		gaConfig.gaCookie.utmz = $.fn.getUrlVars('__utmz');
	};
	
	/*---------------------------------------------
	6. Setup Page URL
	---------------------------------------------*/
	$.fn.setupPageUrl = function() {
		(gaConfig.gaCampaign.campaign != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + 'utm_campaign=' + gaConfig.gaCampaign.campaign : null;
		(gaConfig.gaCampaign.content != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + 'utm_content=' + gaConfig.gaCampaign.content : null;
		(gaConfig.gaCampaign.medium != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + 'utm_medium=' + gaConfig.gaCampaign.medium : null;
		(gaConfig.gaCampaign.source != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + 'utm_source=' + gaConfig.gaCampaign.source : null;
		(gaConfig.gaCampaign.term != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + 'utm_term=' + gaConfig.gaCampaign.term : null;
		(gaConfig.gaCookie.utma != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utma=' + gaConfig.gaCookie.utma : null;
		(gaConfig.gaCookie.utmb != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utmb=' + gaConfig.gaCookie.utmb : null;
		(gaConfig.gaCookie.utmc != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utmc=' + gaConfig.gaCookie.utmc : null;
		(gaConfig.gaCookie.utmk != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utmk=' + gaConfig.gaCookie.utmk : null;
		(gaConfig.gaCookie.utmv != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utmv=' + gaConfig.gaCookie.utmv : null;
		(gaConfig.gaCookie.utmx != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utmx=' + gaConfig.gaCookie.utmx : null;
		(gaConfig.gaCookie.utmz != null) ? gaConfig.page.url += ((gaConfig.page.url.indexOf('?') != -1) ? '&' : '?') + '__utmz=' + gaConfig.gaCookie.utmz : null;
	};
	
	/*---------------------------------------------
	7. Append Form Tracking
	---------------------------------------------*/
	$.fn.appendFormTracking = function() {
		$.ajax({
			url: tPath + '/jquery.google.forms.js',
			type: 'GET',
			dataType: 'script',
			cache: true,
			async:false,
			success: function() {
				$('a,form[id="sendtodealer"]').each(function() {
					var host = document.createElement('a');
					var result = 0;
					var defaultcode = null;
					var formcode = null;
					if($(this).attr('id') == 'sendtodealer') {
						host.href = $(this).attr('action');
					} else {
						host.href = $(this).attr('href');
					};
					for(var c=0; c < forms.formHosts.length; c++) {
						(host.hostname == forms.formHosts[c].hostname) ? result = 1 : null;
					};
					
					if(result) {
						for(var d=0; d < forms.defaultCodes.length; d++) {
							if(forms.defaultCodes[d].market == gaConfig.page.market) {
								for(var e=0; e < forms.defaultCodes[d].languages.length; e++) {
									if(forms.defaultCodes[d].languages[e].language == gaConfig.page.language) {
										defaultcode = forms.defaultCodes[d].languages[e].defaultCode;
										for(var f=0; f < forms.defaultCodes[d].languages[e].forms.length; f++) {
											if(host.href.toLowerCase().indexOf(forms.defaultCodes[d].languages[e].forms[f].form) != -1) {
												formcode = forms.defaultCodes[d].languages[e].forms[f].code;
											};
										};
									};
									
									if(host.href.toLowerCase().indexOf('campaignid') == -1) {
										if(gaConfig.page.campaignid != null) {
											host.href += ((host.href.indexOf('?') == -1) ? '?' : '&') + 'campaignid=' + gaConfig.page.campaignid;
										} else if (defaultcode != null && formcode == null && gaConfig.page.campaignid == null) {
											host.href += ((host.href.indexOf('?') == -1) ? '?' : '&') + 'campaignid=' + defaultcode;
										} else if (formcode != null && gaConfig.page.campaignid == null) {
											host.href += ((host.href.indexOf('?') == -1) ? '?' : '&') + 'campaignid=' + formcode;
										};
									};
									
									if(host.href.toLowerCase().indexOf('sreferrer') == -1) {
										if(gaConfig.page.sreferrer != null) {
											host.href += ((host.href.indexOf('?') == -1) ? '?' : '&') + 'sreferrer=' + gaConfig.page.sreferrer;
										} else if (defaultcode != null && formcode == null && gaConfig.page.sreferrer == null) {
											host.href += ((host.href.indexOf('?') == -1) ? '?' : '&') + 'sreferrer=' + defaultcode;
										} else if (formcode != null && gaConfig.page.sreferrer == null) {
											host.href += ((host.href.indexOf('?') == -1) ? '?' : '&') + 'sreferrer=' + formcode;
										};
									};
									
								};
							};
						};
						if($(this).attr('id') == 'sendtodealer') {
							$(this).attr('action', host.href);
						} else {
							$(this).attr('href', host.href);
						};
					};
				});
			}
		});
	};
	
	/*---------------------------------------------
	8. Append Cookie Information
	---------------------------------------------*/
	$.fn.addCookieInfo = function() {
		_gaq.push(function() {
			$('a,form[id="sendtodealer"]').each(function() {
				var u = document.createElement('a');
				var result = 0;
				if($(this).attr('id') == 'sendtodealer') {
					u.href = $(this).attr('action');
				} else {
					u.href = $(this).attr('href');
				};
				for(var g=0; g < forms.linkHosts.length; g++) {
					(u.hostname == forms.linkHosts[g].hostname) ? result = 1 : null;
				};
			
				if(result) {
					var tracker = _gaq._getAsyncTracker('g');
					u.href = tracker._getLinkerUrl(u.href);
					if($(this).attr('id') == 'sendtodealer') {
						$(this).attr('action', u.href);
					} else {
						$(this).attr('href', u.href);
					};
					tracker = null;
				};
			});
		});
	};
	
	/*---------------------------------------------
	9. Add Events on AJAX Success
	---------------------------------------------*/
	$.fn.addEvents = function() {
		if(!gaConfig.config.events) {
			$.ajax({
				url: tPath + '/jquery.google.events.js',
				type: 'GET',
				dataType: 'script',
				cache: true,
				async: false,
				success: function() {
					gaConfig.config.events = 1;
				}
			});
		}
		
		for(var h=0; h < events.length; h++) {
			cat = events[h].category;
			text = events[h].text;
			sec = events[h].section;
			$.fn.addEvent(events[h].className,cat,sec,text);
			cat = text = sec = null;
		};
	};
	
	/*---------------------------------------------
	10. Add Click Event
	---------------------------------------------*/	
	$.fn.addEvent = function(d,c,s,t) {
		if(d.indexOf('form:submit') == -1) {
			txt = null;
			$(d).unbind('click.gaevent');
			$(d).bind('click.gaevent', function(e) {
				(t == 'this.text') ? txt = $(this).text() : null;
				(t == 'this.h5.text') ? txt = $(this).find('h5').text() : null;
				(t == 'this.h3.text') ? txt = $(this).find('h3').text() : null;
				(t == 'this.alt') ? txt = $(this).find('img').attr('alt') : null;
				(t != 'this.text' && txt == null) ? txt = t : null;
				_gaq.push(
					['g._trackEvent',c,s,txt],
					['m._trackEvent',c,s,txt]);
				if($(this).attr('rel') == "dialog") {
					e.preventDefault();
					var coordinates = $(this).attr('coords').split(",");
					var overlayWidth = (coordinates[0]) ? parseInt(coordinates[0], 10) : undefined; // Radix 10
					var overlayHeight = (coordinates[1]) ? parseInt(coordinates[1], 10) : undefined;
					$('div#dialog').formOverlay($(this).attr('href'), overlayWidth, overlayHeight);
					return false;	
				};
			});
		} else if (d.indexOf('form:submit') != -1) {
			$(d.replace(':submit', '')).unbind('submit.gaevent');
			$(d.replace(':submit', '')).bind('submit.gaevent', function() {
				(t == 'this.text') ? txt = $(this).text() : null;
				(t == 'this.h5.text') ? txt = $(this).find('h5').text() : null;
				(t == 'this.h3.text') ? txt = $(this).find('h3').text() : null;
				(t == 'this.alt') ? txt = $(this).find('img').attr('alt') : null;
				(t != 'this.text' && txt == null) ? txt = t : null;
				_gaq.push(
					['g._trackEvent',c,s,txt],
					['m._trackEvent',c,s,txt]);
			});
		};
		/*if($(d).attr('rel') == 'dialog') {
			$(d).unbind('click.gaoverlay');
			$(d).bind('click.gaoverlay', function(e) {
				$('div#dialog').formOverlay($(this).attr('href'), parseCoords($(this).attr('coords')));
				e.preventDefault();
				return false;
			});
		};*/
	};
	
	/*---------------------------------------------
	11. Exchange Social Media links
	---------------------------------------------*/
	$.fn.ExchangeSoMeLinks = function() {
		$('ul.share-links li a').each(function() {
			var u = $(this).attr('href');
			if(u.indexOf('##pageUrl##') != -1) {
				u = u.replace('##pageUrl##', escape(location.href));
				$(this).attr('href', u);
			};
			if(u.indexOf('##pageTitle##') != -1) {
				u = u.replace('##pageTitle##', document.title);
				$(this).attr('href', u);
			};
		});
	};
	
	
	/*---------------------------------------------
	13. Setup Market/Language for Configurator
	---------------------------------------------*/
	$.fn.setMarkLang = function() {
		var c = location.pathname.split('/')[3];
		var m = c.split('_')[1];
		var l = c.split('_')[0];
		m = (m == 'xi' || m == 'xm') ? (m == 'xi') ? 'gl' : 'me' : m;
		gaConfig.page.market = m;
		gaConfig.page.language = l;
	};
	
	/*---------------------------------------------
	14. Check configurator pages
	---------------------------------------------*/
	$.fn.checkConfigPages = function() {
		$(gaConfig.page.configPages).each(function() {
			_gaq.push(this);
		});
		if(gaConfig.page.configPages.length > 0) {
			gaConfig.page.configPages = [];
		};
		window.setTimeout('$.fn.checkConfigPages();', 500);
	};

	/*---------------------------------------------
	15. Apply Overlay CSS function
	---------------------------------------------*/
	$.fn.applyOverlay = function() {
		$('a.lnk-more[rel="dialog"]').unbind('click.gaoverlay');
		$('a.lnk-more[rel="dialog"]').bind('click.gaoverlay', function(e) {
			$('div#dialog').formOverlay($(this).attr('href'), parseCoords($(this).attr('coords')));
			e.preventDefault();
			
			return false;
		});
	};
	
	/*---------------------------------------------
	16. Script initiation
	---------------------------------------------*/
	$.fn.initGA = function() {
		(location.host == 'rules.config.jaguar.com' || location.host == 'rules-staging.configureconnect.com' || location.host == 'rules.configureconnect.com') ? gaConfig.page.configurator = 1 : null;
		if(gaConfig.page.configurator) {
			$.fn.setMarkLang();
		};
		$.fn.setAccounts();
		$.fn.setupCampaign();
		$.fn.setupPageUrl();
		gaConfig.gaTracking.enabled = ($.fn.getUrlVars('searchType') != null || gaConfig.page.configurator) ? 0 : 1;
		$.fn.applyOverlay();
	
		
		try {	
			if(gaConfig.gaTracking.enabled) {
				_gaq.push(
					['g._trackPageview', gaConfig.page.url],
					['m._trackPageview', gaConfig.page.url]);
			};
			gaConfig.script.url = ((location.protocol == 'http:') ? 'http://www.' : 'https://ssl.') + 'google-analytics.com/ga.js';
			
			$.ajax({
				url: gaConfig.script.url,
				type: 'GET',
				dataType: 'script',
				cache: true,
				async:false,
				success: function() {
					$.fn.appendFormTracking();
					$.fn.addCookieInfo();
				}
			});
		} catch(err) {};
		if(gaConfig.page.configurator) {
			$.fn.appendFormTracking();
			$.fn.addCookieInfo();
			$.fn.checkConfigPages();
		};
	};	

	$(document).ready(function() {
		$.fn.loadConfig();
	});
})(jQuery);

/*---------------------------------------------
15. Obselete Functions
---------------------------------------------*/
function trackShoppingpop( url, market, description ) {
	description = description.replace(/\%20/g,' ');
	_gaq.push(
		['g._trackEvent', market,'ShoppingTools',description],
		['m._trackEvent', market,'ShoppingTools',description]);
	var height= 600;
	var width= 816;
	var top= ( screen.height / 2 ) - ( height / 2 );
	var left= ( screen.width / 2 ) - ( width / 2 );
	if (url.indexOf("jaguarusaforms.aplicor.net") || url.indexOf("jaguarukforms.aplicor.net") || url.indexOf("forms.jaguar.com") != -1) {
		switch( 'forms' ){
		case 'forms':
			if(url.indexOf("jaguarusaforms.aplicor.net") != -1) {
				$("div#dialog").formOverlay(url);
				$('div#dialog').css('width', '1042px');
				$('div[role="dialog"]').css('width', '1035px');
				$('div[role="dialog"] img#background').css('width', '1042px');
				$('div#dialog #iframe-container').css({
					'width': '980px',
					'padding-left': '10px'
				});
				$('div#dialog iframe').css('overflow-x', 'hidden');
				break;
			} else {
				$("div#dialog").formOverlay(url,width,height);
				break;
			}
		}
	} else {
		var newwindow=window.open(url,"", "scrollbars=yes,height=" + height + ",width=" + width + ",top=" + top + ",left=" + left );
	}

}

function trackShopping( market, description, URL ) {
	_gaq.push(
		['g._trackEvent', market,'ShoppingTools',description],
		['m._trackEvent', market,'ShoppingTools',description]);
	location.href = URL;
}

function trackShoppingNew( market, description, URL ) {
	_gaq.push(
		['g._trackEvent', market,'ShoppingTools',description],
		['m._trackEvent', market,'ShoppingTools',description]);
	var newWindow = window.open(URL, '_blank');
    newWindow.focus();
}

function form (url) {
	$("div#dialog").formOverlay(url);
	$('div#dialog').css('width', '1042px');
		$('div[role="dialog"]').css('width', '1035px');
		$('div[role="dialog"] img#background').css('width', '1042px');
		$('div#dialog #iframe-container').css({
			'width': '980px',
			'padding-left': '10px'
		});
		$('div#dialog iframe').css('overflow-x', 'hidden');
};
