//***********************************************************************************
// Copyright 2009 Citricle. All rights reserved.
// This script is released under the LGPL license which means you can use it or adapt it
// to your needs, improve it and distribute it freely across the web as long as you don't remove
// this copyright notice. For technical support go to www.citricle.com.
//***********************************************************************************

//***********************************************************************************
// preconditions:
//   * the following javascript libraries are already loaded:
//     - jquery.js		<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
//     - ga.js			<script type="text/javascript">
//							var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
//							document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//						</script>
//	* the following javascript variable has already been declared:
//		- ga			=> declared in the <head> tag using NetSuite getAttribute() methods.
//						   note: these variables are only available on the order confirmation page (ie: /thankyou).
//						   note: these variables are only used when the document.url matches the order confirmation page (ie: /thankyou).
//						   ex:
//						var ga = {"address":"", "orderNumber":"", "siteName":"", "cofirmationTotal":"", "tax":"", "shipping":""};
//						try {
//							ga.address = "<%=getCurrentAttribute('customer','defaultaddress')%>";
//							ga.orderNumber = "<%=getCurrentAttribute('confirmation','ordernumber')%>";
//							ga.siteName = "<%=getCurrentAttribute('site','name')%>";
//							ga.cofirmationTotal = "<%=getCurrentAttribute('confirmation','total')%>";
//							ga.tax = "<%=getCurrentAttribute('confirmation','tax')%>";
//							ga.shipping = "<%=getCurrentAttribute('confirmation','shipping')%>";
//						}
//						catch(e) {};
//***********************************************************************************

$(document).ready(function(){
	var public_domain = "serenaandlily.com";
	var secure_domain = "checkout.netsuite.com";
	var pageID = document.referrer;

	try {
		var pageTracker = _gat._createTracker("UA-3620862-1", "serenaandlily");

		if(document.URL.indexOf(public_domain) != -1) {													// url is in our domain
			pageTracker._setDomainName("none");
			pageTracker._setAllowHash(false);
			pageTracker._setAllowLinker(true);
			pageTracker._setCustomVar( 3, "Pageview - Page Level", pageID, 3 );   
			pageTracker._setCustomVar( 4, "Pageview - Session Level", pageID, 2 );   
			pageTracker._trackPageview();

			if((document.referrer.indexOf(public_domain) == -1)  && (document.referrer != "")) {		// referrer is known, and the user came from an external domain (ie: new/returning visitor)
				var iframeElement = document.createElement("iframe");
				var proxyAddress = "https://checkout.netsuite.com/c.668979/site/analytics_trackers/google_analytics/domains/checkout.netsuite.com/ga_proxy.html";
				iframeElement.setAttribute("src", pageTracker._getLinkerUrl(proxyAddress));
				document.getElementById("div__header").appendChild(iframeElement);
				iframeElement.style.display = "none";
			}
		}

		if(document.URL.indexOf(secure_domain) != -1) {													// url is in NetSuite's checkout area. note: this script isn't used by our proxy html file.
			var scriptAddress = 'https://checkout.netsuite.com/c.668979/site/analytics_trackers/google_analytics/domains/checkout.netsuite.com/ga_netsuite_logic.js';
			$.getScript(scriptAddress, function(){
				pageTracker._setDomainName("none");
				pageTracker._setAllowHash(false);
				pageTracker._setAllowLinker(true);
				pageTracker._trackPageview();
				if (typeof ga != 'object') {
					ga = {"address":"", "orderNumber":"", "siteName":"", "cofirmationTotal":"", "tax":"", "shipping":""};
				}
				setGATracking(pageTracker, ga.address, ga.orderNumber, ga.siteName, ga.cofirmationTotal, ga.tax, ga.shipping);
			});
		}
	}
	catch(e) {};
});
