displayMostRecentlyViewedItems = function(mrvUrl){
	/*hide the Recently Viewed header if there are no list items present*/
	$('.recent').load(mrvUrl, function(){
		if( $(this).find('.list_item_small').length == 0 && $('.related').find('.list_item_small').length == 0){
			$('.related_products').hide();
		}
		else if( $(this).find('.list_item_small').length == 0){
			$('#mrvHeader').hide();
		}
		if($('.prod_img').length){
			$('.jqmWindow').jqmAddTrigger($('.prod_img'));
		}
	});
}
updateMostRecentlyViewedItems = function(storeId, catalogId, langId, pCategories, productId, useSEOUrl){
	var curItem = storeId + '_' + catalogId + '_' + langId + '_' + pCategories + '_' + productId + '_' + useSEOUrl;
	curItem = unescape(curItem);
	var mrvItems = readCookie('mostRecentlyViewedItems');
	if(mrvItems){
		/* prepend current item to cookie string*/
		mrvItems = curItem + '#' + mrvItems;
		/* remove any duplicate product ids and limit to max of 3 items */
		mrvItems = cleanMRVItemCookie(mrvItems);
	}else{
		mrvItems = curItem;
	}
	createCookie('mostRecentlyViewedItems',mrvItems, 30);
}
cleanMRVItemCookie = function(strCookie){
	var arrProductEntries = strCookie.split('#');// split cookie into string array
	var productIdMap = new Object();
	var newCookieArray = new Array();
	
	for(var r = 0; r < arrProductEntries.length; r++){
		var arrProductUrlParts = arrProductEntries[r].split('_');//split each item reference
		//filter out repeats of same productId
		if(productIdMap[arrProductUrlParts[4]]!= 1){
			newCookieArray = newCookieArray.concat(arrProductEntries[r]);
			productIdMap[arrProductUrlParts[4]] = 1;
		}
	}
	//maintain max of 3 product references in cookie
	if(newCookieArray.length > 3){
		newCookieArray.pop();
	}
	var newStrCookie = newCookieArray.join('#');//recreate cookie string with # delimeter

	return newStrCookie;
}
