function SummitMediaTracking(address,clientID)
{
	this._address = address;
	this._clientID = clientID;
	
	if (!this._defined)
	{
		SummitMediaTracking.prototype._defined = true;

	////////////////////////////////////////////////
	//PageInfo:Object

		function PageInfo()
		{
			this._customParams = new Array();
		}
		
		PageInfo.prototype._clientIDName = "SummitMediaClientID";
		PageInfo.prototype._sessionIDName = "SummitMediaSessionID";
		PageInfo.prototype._reffererMarkerName = "SummitMediaRefferer";
		PageInfo.prototype._classCode = "pi";
		
		PageInfo.prototype._getRandomChars = function(fromStr, length)
		{
			fromStr += (new Date()).getMilliseconds().toString();
			var retVal = "", counter = 0, curChar;
			while(counter < length)
			{
				curChar = fromStr.charAt(Math.round(Math.random() * (fromStr.length - 1)));
				if (curChar == " ") continue;
				retVal += curChar;
				fromStr += (new Date()).getMilliseconds().toString();
				counter++;
			}
			return retVal;
		}

		
		PageInfo.prototype._generateID = function()
		{
			return this._getRandomChars(navigator.userAgent, 15) + this._getRandomChars(location, 15);
		}
		
		PageInfo.prototype._getCookie = function(cookieName)
		{
			cookieName += "=";
			var retVal = "";
			if (document.cookie.length > 0)
			{
				var cookieArray = document.cookie.split(";")
				for (var counter = 0;counter < cookieArray.length; counter++)
				{
					if (cookieArray[counter].indexOf(cookieName) > -1)
					{
						retVal = unescape(cookieArray[counter].split("=")[1]);
						break;
					}
				}
			}
			return retVal;
		}

		PageInfo.prototype._setCookie = function(cookieName,uniqueID,expDays)
		{
			var expDate = expDays?(";expires=" + (new Date((new Date).getTime() + expDays * 1000 * 60 * 60 * 24 )).toGMTString()):"";
			var cookieVal = cookieName + "=" + escape(uniqueID) +	expDate + ";path=/";
			document.cookie = cookieVal;
		}
		
		 
		PageInfo.prototype._isOriginal = function()
		{
				if (!document.referrer || document.referrer.split("?")[0].indexOf(document.location.hostname,0) > -1 || document.location == this._getReferrerMarker())
					return 0;
				this._setReferrerMarker(document.location);
				return 1;
		}
		
		
		PageInfo.prototype._getClientID = function()
		{
			var id = this._getCookie(this._clientIDName);
			if (!id)
			{
				id = this._generateID();
				this._setCookie(this._clientIDName,id,360);
			}
			return id;
		}
		
		
		PageInfo.prototype._getSessionID = function()
		{
			var id = this._getCookie(this._sessionIDName);
			if (!id)
			{
				id = this._generateID();
				this._setCookie(this._sessionIDName,id);
			}
			return id;
		}

		PageInfo.prototype._getReferrerMarker = function()
		{
			return this._getCookie(this._reffererMarkerName);
		}
		
    	PageInfo.prototype._setReferrerMarker = function(refferer)
		{
		    this._setCookie(this._reffererMarkerName,refferer);
		}


		PageInfo.prototype.addCustomParam = function(propCode,propValue)
		{
			this._customParams.push({"propCode":propCode,"propValue":propValue});
			return this;
		}
				

		PageInfo.prototype.serializeProp = function(propCode,propValue)
		{
			return propValue?(propCode + "=" + escape(propValue) + "&"):"";
		}
		
		PageInfo.prototype.serializeToURL = function()
		{
			var serVals ="";
			for (var counter = 0; counter < this._customParams.length; counter++)
			{
				serVals += this.serializeProp("picp" + this._customParams[counter].propCode, this._customParams[counter].propValue);
			}
			return serVals + this.serializeProp("picc",this._classCode) + this.serializeProp("piio",this._isOriginal()) + this.serializeProp("pirf",document.referrer) +  this.serializeProp("pisid",this._getSessionID()) + this.serializeProp("picid",this._getClientID());
		}

	//END PageInfo:Object
	////////////////////////////////////////////////

	////////////////////////////////////////////////
	//PageView:PageInfo 

		function PageView(pageID, categoryID)
		{
			this._pageID = pageID;
			this._categoryID = categoryID;
		}
		
		PageView.prototype = new PageInfo;
		PageView.prototype._classCode = "pav";
		
		PageView.prototype.serializeToURL = function()
		{	
			return this.serializeProp("pavref",location) + this.serializeProp("pavpid",this._pageID) + this.serializeProp("pavcid",this._categoryID) + PageInfo.prototype.serializeToURL.call(this);
		}

	//END PageView:PageInfo 
	////////////////////////////////////////////////


	////////////////////////////////////////////////
	//ProductView:PageView 

		function ProductView(pageID, categoryID,productID, productName)
		{
			PageView.call(this,pageID, categoryID)
			this._productID = productID;
			this._productName = productName;
		}
		
		ProductView.prototype = new PageView;
		ProductView.prototype._classCode = "prv";
		
		ProductView.prototype.serializeToURL = function()
		{	
			return this.serializeProp("prvpid",this._productID) + this.serializeProp("prvpn",this._productName) + PageView.prototype.serializeToURL.call(this);
		}
		

	//END ProductView:PageView 
	////////////////////////////////////////////////


	////////////////////////////////////////////////
	//ShopingCart:PageInfo 

		function ShopingCart(currency)
		{
			this._cartItems = new Array();
			this._currency = currency;
		}
		
		ShopingCart.prototype = new PageInfo;
		ShopingCart.prototype._classCode = "shc";
		
		ShopingCart.prototype.addItem = function(productID,productName,quantity,unitPrice,categoryID,itemDiscount)
		{
			this._cartItems.push({"productID":productID,"productName":productName,"quantity":quantity,"unitPrice":unitPrice,"categoryID":categoryID,"itemDiscount":itemDiscount});
			return this;
		}
		
		
		ShopingCart.prototype.serializeToURL = function()
		{
			var serVals ="";
			
			for (var counter = 0; counter < this._cartItems.length; counter++)
			{
				serVals += this.serializeProp("shcpid" + counter, this._cartItems[counter].productID);
				serVals += this.serializeProp("shcpna" + counter, this._cartItems[counter].productName);
				serVals += this.serializeProp("shcpqu" + counter, this._cartItems[counter].quantity);
				serVals += this.serializeProp("shcpup" + counter, this._cartItems[counter].unitPrice);
				serVals += this.serializeProp("shcpci" + counter, this._cartItems[counter].categoryID);
				serVals += this.serializeProp("shcitd" + counter, this._cartItems[counter].itemDiscount);
				
			}
			return this.serializeProp("shccur",this._currency) + serVals + PageInfo.prototype.serializeToURL.call(this);
		}
		
	//END ShopingCart:PageInfo 
	////////////////////////////////////////////////


	////////////////////////////////////////////////
	//CheckOut:ShopingCart

		function CheckOut(currency,orderID,shippingCost,totalPrice,totalDiscount)
		{
			ShopingCart.call(this,currency)
			this._orderID = orderID;
			this._shippingCost = shippingCost;
			this._totalPrice = totalPrice;
			this._totalDiscount = totalDiscount;
		}
		
		CheckOut.prototype = new ShopingCart;
		CheckOut.prototype._classCode = "cho";
		
		CheckOut.prototype.serializeToURL = function()
		{	
			return this.serializeProp("chooid",this._orderID) + this.serializeProp("choshc",this._shippingCost) + this.serializeProp("chotp",this._totalPrice) + this.serializeProp("chotd",this._totalDiscount) + ShopingCart.prototype.serializeToURL.call(this);
		}
		
	//END CheckOut:ShopingCart
	////////////////////////////////////////////////


		SummitMediaTracking.prototype.getPageView = function(pageID, categoryID)
		{
			return new PageView(pageID, categoryID);
		}
		
		SummitMediaTracking.prototype.getProductView = function(pageID, categoryID,productID, productName)
		{
			return new ProductView(pageID, categoryID,productID, productName);
		}

		SummitMediaTracking.prototype.getShopingCart = function(currency)
		{
			return new ShopingCart(currency);
		}

		SummitMediaTracking.prototype.getCheckOut = function(currency,orderID,shippingCost,totalPrice,totalDiscount)
		{
			return new CheckOut(currency,orderID,shippingCost,totalPrice,totalDiscount);
		}

		SummitMediaTracking.prototype.sendInfo = function(pageInfo)
		{
			var src = this._address + this._serializeProp("ver",this._version) + this._serializeProp("clid",this._clientID) + pageInfo.serializeToURL() + "smdt=" + (new Date()).getTime();
			document.write("<img src='" + src + "' style='display: none' />"); 
			return src;
		}
		
		SummitMediaTracking.prototype._serializeProp = function(propCode,propValue)
		{
			return propValue?(this._classCode + propCode + "=" + escape(propValue) + "&"):"";
		}
		
		SummitMediaTracking.prototype._version = "1.1";
		SummitMediaTracking.prototype._classCode = "same";
		
	}
}

