/* 
	author: Pieter Kraakman
	date: 01/19/11
	
	This script replaces the iGoDigital version. All variables are scoped to stay within the _iGoDigital object
	_iGoDigital is the only symbol that should exist in the global scope. Should be a singleton

*/
var _iGoDigital = _iGoDigital || {
	elementRTA: document.createElement('DIV'),
	rtaCart:'',
	rtaTags:'',
	rtaProductSKU:'',
	rtaSort:'',
	rtaFilters:'',
	rtaCartAddSKU:'',
	rtaSessionID:'',
	rtaEmail:'',
	rtaConvertCart:'',
	rtaClearCart:'',
	rtaProductList:'',
	rtaOrderNum:'',
	rtaCartAmounts:'',
	rtaCartQuantities:'',
	rtaReportingSegment1:'',
	rtaReportingSegment2:'',
	rtaRating:'',
	rtaCartValues:'',
	
	//calls the image. sniffs for email parameter in URL (e)
	callRTA: function(){
		if(this.rtaCartValues != '') this.rtaCartAmounts = this.rtaCartValues;
		
		var email_variable = 'e';
		var vars = window.location.search.substring(1).split('&');
		
		for (var i=0;i<vars.length;i++) {
		    var pair = vars[i].split("="); 
		    if (pair[0] == email_variable) { 
		        this.rtaEmail = pair[1] 
		    }   
		}
		
		var outstr = '<img src="//party.collect.igodigital.com/collect/recordWithImage?u=' + escape(window.location.href) + '&r=' + escape(document.referrer) + '&t=' + escape(document.title) + '&c=' + escape(this.rtaCart) + '&w=' + escape(this.rtaTags) + '&p=' + escape(this.rtaProductSKU) + '&s=' + escape(this.rtaSort) + '&f=' + escape(this.rtaFilters) + '&a=' + escape(this.rtaCartAddSKU) + '&e=' + escape(this.rtaSessionID)+ '&l=' + escape(this.rtaProductList) + '&m=' + escape(this.rtaEmail) + '&o=' + escape(this.rtaOrderNum) + '&x=' + escape(this.rtaConvertCart) + '&b=' + escape(this.rtaCartAmounts) + '&z=' + escape(this.rtaClearCart) + '&q=' + escape(this.rtaCartQuantities) + '&j=' + escape(this.rtaReportingSegment1) + '&k=' + escape(this.rtaReportingSegment2) + '&d=' + escape(this.rtaRating) + '">' ;
		
		// I don't think we use this but igo might
		if (window.location.href.indexOf("igo_env=stage") >= 0) outstr+='<script language="javascript" src="http://admin2.igodigital.com/igo_facebook/univ.js.php">';
		
		this.elementRTA.innerHTML = outstr;
		
		document.getElementsByTagName("body").item(0).appendChild(this.elementRTA);
	},
	
	// Do the 3 card monty in case we already have a window.onload
	addLoadEvent: function(func) {
		var oldonload = window.onload;
		window.onload = function() {
			if(typeof oldonload == 'function'){ oldonload() };
			func();
		}
	}
};

