if(!window.mmpa){
    window.mmpa={
		domain:'wiggle.co.uk',
		server: 'cg1.maxymiser.com/CG2/',
	    cookie_domain:'',
	    tpixel:false,
	    cprefix:'mm',

		SetPurchase:function(orderid, productid, count, amount, currency){this._purchases.push({order_id:orderid,product_id:productid,count:count,amount:amount,currency:currency});},
		SetRating:function(prod_or_attr, type_id, ratetype, rating){this._ratings.push({prod_or_attr:prod_or_attr,type_id:type_id,rate_type:ratetype,rating:rating});},
		SetRule:function(attr1, attr2, is_inclusion){this._filters.push({attr1:attr1,attr2:attr2,is_inclusion:is_inclusion?1:0});},
		SetMethod:function(method, num_recs, array, fields){this._methods.push({method:method,num_recs:num_recs,array:typeof array=='undefined'?'recommendation':array,fields:typeof fields=='undefined'?'id':fields});},
    	PARequest:function(callback){var _t=this;_t._callback[++_t._request_id]=callback;_t._Tag(_t._TagUri());_t._Clear();},
	    SetCookie:function(n,v,d){var exp=new Date(),_t=this,_h=_t._Host();exp.setTime(exp.getTime()+d*86400000);
		_t._d.cookie=escape(_t._PN(n))+'='+escape(v)+(_h.length?';domain='+_h:'')+';path=/'+(d>0?(';expires='+exp.toGMTString()):'')},
		GetCookie:function(n){var _t=this;return unescape(_t._ValByKey(_t._d.cookie,escape(_t._PN(n)),'=',';'))},
		// tools for ajax call
		CreateXmlRequest:function(){
			try{return new ActiveXObject('Msxml2.XMLHTTP');}catch(e){}
			try{return new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
			try{return new XMLHttpRequest();}catch(e){}
		    this.error+='Ajax is not supported by your browser.';
			return null;},
		GetAjaxContent:function(url){
			try {var xml_req = this.CreateXmlRequest();xml_req.open('GET',url,false);
			xml_req.send(null);if(xml_req.status<400)return xml_req.responseText;
			else return undefined;}catch(e){return undefined;}
			return undefined;},

		//PRIVATE:
		_jsver:'1.0',
		_fv:{},
		_methods:[],
		_purchases:[],_ratings:[],_filters:[],
		_callback:{},
		_request_id:0,
		_async:false,
		_debug:false,_d:document,_l:window.location,
		_ValByKey:function(str,key,f,r)/*f-field, r-array of record separators*/{
		    var s='',i2,i3,i1=str.indexOf(key);if(i1<0)return'';
		    if(i1<0||(i2=str.indexOf(f,i1+key.length))<0)return'';
		    i1=i2+f.length;i3=str.indexOf(r,i1);
		    return this._T(s=i3<0?str.substring(i1):str.slice(i1,i3))},
		_T:function(str){return str.replace(/^\s+/g,'').replace(/\s+$/g,'')},
	    _L:function(str){return str.toLowerCase()},
	    _TL:function(str){return this._L(this._T(str))},
	    _PN:function(str){return this._TL(this.cprefix+str)},
	    _Host:function(){
		    var _t=this,_h=_t._TL(_t._l.hostname),_d=_t._TL(_t.domain),_d2=_t._TL(_t.cookie_domain);
		    if (_h=='localhost')return '';if(_d2.length==0)_d2=_d;if(_d2[0]=='.')_d2=_d2.substring(1);if(_h.indexOf(_d2)>=0)_h=_d2;
		    return _h.replace('www.', '')},
		//PRIVATE:
		_SerializeArray:function(arr){
			var row,el,res='',col='',rec;
			for(row in arr){col='';
				for(el in arr[row]){rec=arr[row][el];if(typeof rec=='undefined')rec='';col+=escape(rec)+',';}
				if(col.length>0)col=col.slice(0,-1);res+=col+';';}
			return escape(res);},
	    _Tag:function(uri){var _t=this,_n,px=_t.tpixel,tp='text/javascript',d=_t._d,i,_a,id='_mmtag_'+Math.random();
		    if(_t._async){_n=d.createElement(px?'img':'script');_n.id=id;_n.src=uri;if(!px){_n.type=tp;_n.charset='utf-8'};
			_a=d.getElementsByTagName(px?'body':'head');if(_a&&_a.length)_a[0].appendChild(_n)
		    }else{_t._d.write(px?'<img id="'+id+'" src="'+uri+'"\/>':'<scr'+'ipt id="'+id+'" type="'+tp+'" charset="utf-8" src="'+uri+'"><\/scr'+'ipt>')}
		    return id },
    	_TagUri:function(){
		    var _t=this,_p=_t._l.protocol,s='',s1='',i,_v,_k;
			for(_k in _t._fv)s1+=_k+'='+_t._fv[_k]+';';s1.slice(0,-1)
		    s=_t.server+'?'+'fv='+escape(s1);
			s+='&pu='+_t._SerializeArray(_t._purchases)+'&rat='+_t._SerializeArray(_t._ratings)
		       +'&rul='+_t._SerializeArray(_t._filters)+'&rh='+escape(_t.GetCookie('rh'))
		       +'&met='+_t._SerializeArray(_t._methods)+'&ri='+_t._request_id;
		    s+=(_t.tpixel?'&tp=1':'')+'&jsver='+_t._jsver;
		    return s.indexOf('://')>0?s:((_p!=''?_p:'http:')+'//'+s)
		},
	    _Init:function(){this._Clear();var _t=this,_fv=_t._fv,_u=_t._l.href,_r=_t._d.referrer,_rnd=(''+Math.random()).substring(0,5),_id;
		    _fv.dmn=_t.domain;_t.SetCookie('tst',_rnd,10);_fv.cok=(_t.GetCookie('tst')==_rnd?1:0);
		    if(_r.length>256)_r=_r.substring(0,256);if(_u.length>1024)_u=_u.substring(0,1024);
		    _fv.ref=escape(_r);_fv.url=escape(_u);
		},
	    _Clear:function(){var _t=this;_t._methods=[];_t._purchases=[];_t._ratings=[];}
    }
    window.mmpa._Init()
}
