	var requestFrom;
	var popup_wish;
	var popup_cart;
	var tabDef = "";
	var currProdId = "";
	var currOper = "";
	
	function tabButs(){
		this.tabImageClass = "";	//set this variable for the tab image 		
		this.styName = "";		//set the styles to adjust the padding if any
		this.classIn = "";
		this.classAdd = "";
	}

	var arrButs = new Array();

	var Cart8020 = new tabButs();
	Cart8020.tabImageClass = "tabOrange";	
	Cart8020.classIn = "act_btns btn_8920 in_cart_8920";
	Cart8020.classAdd = "act_btns btn_8920 add_to_cart_8920";
	Cart8020.styName = "mTop5";

	arrButs["Cart8020Images"] = Cart8020;

	var Cart4616 = new tabButs(); 
	Cart4616.tabImageClass = "tabOrange5628";	
	Cart4616.classIn = "act_btns btn_4616 in_cart_4616";
	Cart4616.classAdd = "act_btns btn_4616 add_to_cart_4616";
	Cart4616.styName = "mTop5";

	arrButs["Cart4616Images"] = Cart4616;
	
	var Wish8020 = new tabButs();
	Wish8020.tabImageClass = "tabGreen";	
	Wish8020.classIn = "act_btns btn_8920 in_wish_8920";
	Wish8020.classAdd = "act_btns btn_8920 add_to_wish_8920";
	Wish8020.styName = "mTop5";

	arrButs["Wish8020Images"] = Wish8020;

	var Wish4616 = new tabButs();
	Wish4616.tabImageClass = "tabGreen5628";	
	Wish4616.classIn = "act_btns btn_4616 in_wish_4616";
	Wish4616.classAdd = "act_btns btn_4616 add_to_wish_4616";
	Wish4616.styName = "mTop5";

	arrButs["Wish4616Images"] = Wish4616;
	
	
	
	var popupHTML = "<div class=\"conConfirm green\" name=\"greenTabbedPopup\" id=\"greenTabbedPopup\">" + 
				"<div class=\"popupTab thGreen\">" + 
					"<div id=\"greenPopupTabContent\" name=\"greenPopupTabContent\" class=\"popupTabContent tabGreen\">" + 
					"</div>" + 
				"</div>" + 
				"<div class=\"container thGreen\">" + 
					"<div class=\"conConfirmTitle\" id=\"GreentempTitle\" name=\"GreentempTitle\">" + 
						"<span id=\"greenPopupTabClose\" class=\"popUpClose\">" + 
							"<img src=\"/images/everest/layout/audible_newstyle/16x13_static_close.png\"/>" + 
						"</span>" + 
					"</div>" + 
					"<div id=\"greenPopupBodyContent\" name=\"greenPopupBodyContent\" class=\"popupBodyContent\">" + 
					"</div>" + 
				"</div>" + 
			"</div>" + 			
			"<div class=\"conConfirm orange\" name=\"orangeTabbedPopup\" id=\"orangeTabbedPopup\">" + 
				"<div class=\"popupTab thOrange\">" + 
					"<div id=\"orangePopupTabContent\" name=\"orangePopupTabContent\" class=\"popupTabContent\">" + 
					"</div>" + 
				"</div>" + 
				"<div class=\"container thOrange\">" + 
					"<div class=\"conConfirmTitle\" id=\"OrangetempTitle\" name=\"OrangetempTitle\">" + 
						"<span id=\"orangePopupTabClose\" class=\"popUpClose\">" + 
							"<img src=\"/images/everest/layout/audible_newstyle/16x13_static_close_orange.png\"/>" + 
						"</span>" + 
					"</div>" + 
					"<div id=\"orangePopupBodyContent\" name=\"orangePopupBodyContent\" class=\"popupBodyContent\">" + 
					"</div>" + 
				"</div>" + 
			"</div>";			
			
	var doc_body = (document.getElementsByTagName ? document.getElementsByTagName("body")[0] : (document.body || null));			
	if(doc_body.insertAdjacentHTML){//IE				
		doc_body.insertAdjacentHTML("afterBegin", popupHTML);				
	}else if(typeof doc_body.innerHTML != "undefined" && document.createElement && doc_body.appendChild){//mozilla
		var el = document.createElement("div");
		if(el)
			el.id = "popupSamples";
		doc_body.appendChild(el);
		document.getElementById("popupSamples").innerHTML = popupHTML;
	}
	function popup(anchorname, type, xOffset, yOffset) {
		var closeBtnId = null;
		var popupName = "";
		if(type == "WISH_LIST"){
			anchorname += "_wish";
			closeBtnId = "greenPopupTabClose";			
			popupName = "popup_wish";
		}else if(type == "CART"){
			anchorname += "_cart";
			closeBtnId = "orangePopupTabClose";			
			popupName = "popup_cart";
		}
		
		eval(popupName).customizePopUp();		
		var coordinates = getAnchorPosition(anchorname);
		var xPos = coordinates.x;
		var yPos = coordinates.y;			
		
		var btnWidth = document.getElementById(anchorname).offsetWidth;
		var popUpWidth = document.getElementById("greenTabbedPopup").offsetWidth;
							
		eval(popupName).offsetY = yOffset;
		eval(popupName).offsetX = - ((popUpWidth - btnWidth) / 2) + xOffset;
		eval(popupName).autoHide();		
		if(type == "WISH_LIST"){			
			eval(popupName).populateCustomized("greenPopupTabContent", "", "GreentempTitle", "", "greenPopupBodyContent", "<div class=\"conConfirmMsg\">Adding...</div>");
		}else if(type == "CART"){			
			eval(popupName).populateCustomized("orangePopupTabContent", "", "OrangetempTitle", "", "orangePopupBodyContent", "<div class=\"conConfirmMsg\">Adding...</div>");
		}
		eval(popupName).showPopup(anchorname);		
		document.getElementById(closeBtnId).onclick = new Function(popupName + ".hidePopup();return false;");
	}
	
	function addBookToWishList(prodId, oid, extraParams, size){
		currProdId = prodId;
		currOper = "WISH";
		
		if(extraParams != null && extraParams != "" && extraParams == "recom=yes&loomia_rx=1"){
			extraParams = "&" + extraParams;
			var loomiapid = prodId.substring(4,prodId.length);
			L_VARS.guid= loomiapid;
			loomiaclicklink = loomiaclicklink.replace('item_guid', loomiapid);
			recordLoomia(prodId);
		}else{
			extraParams = "";
		}
		
		var realProdId = prodId;
		var prefix = "";
		if(prodId.indexOf("-") >= 0){
			realProdId = prodId.substring(prodId.indexOf("-")+1, prodId.length);
			prefix = prodId.substring(0, prodId.indexOf("-"));
		}
		
		var addUrl = wishLIstUrl;
		if(addUrl.indexOf("?")>0){
			addUrl += "&chkProduct=" + realProdId + "&addToList=" + oid + "&action=addToWishList" + "&pre=" + prefix + "&t=" + new Date();
		}else{ 
			addUrl =+ "?addToList=" + oid + "&chkProduct=" + realProdId + "&action=addToWishList" + "&pre=" + prefix + "&t=" + new Date();
		}		
		setNewTabStyle(prodId, "WISH", size);
		popup_wish = new PopupWindow("greenTabbedPopup");
		popup(prodId, "WISH_LIST", 1, -5);		
		sendRequest(addUrl,parseMessages);
	}
	
	function parseMessages(req){
		if(req.responseXML.getElementsByTagName("products")[0] != null){
			updatePopup(req.responseXML);
		}else{
			alert("failed to update wishlist.");
		}		
	}
	
	function updatePopup(responseXML){
		var rootElement = responseXML.getElementsByTagName("products")[0];					
		var testProdRoot = rootElement.getElementsByTagName("test_product")[0];									
		var isPresent = testProdRoot.getElementsByTagName("isPresent")[0].firstChild.nodeValue;
		var prodId = testProdRoot.getElementsByTagName("product_id")[0].firstChild.nodeValue;		
		var message = testProdRoot.getElementsByTagName("message")[0].firstChild.nodeValue;
				
		var tabContentNew = "<img src=\"/clear.gif\" class=\"" + arrButs[tabDef+"Images"].classIn + " " + arrButs[tabDef+"Images"].styName + "\"  />";
		var tabContentOld = "<img src=\"/clear.gif\" class=\"" + arrButs[tabDef+"Images"].classAdd + " " + arrButs[tabDef+"Images"].styName + "\"  />";
		var tabContent = tabContentNew;
		var titleContent = "";
		var bodyContent = "";
		var strMsg = "";
		var flag = false;
		
		if(currProdId == prodId && currOper == "WISH"){		
			if(message == "IN_LIBRARY"){
				strMsg = "This title has already been purchased."
			}else if(isPresent == "false" && message == "success"){
				strMsg = "The title has been successfully added to your wishlist.";
				flag = true;
			}else if(isPresent == "true"){
				strMsg = "This title has already been added to your wishlist."
				flag = true;
			}else{
				strMsg = "Unable to add product to your wishlist.";
			}
			
			bodyContent += "<div id=\"greenConfirmMsg\" class=\"conConfirmMsg\">" + strMsg + "</div>";		
			
			if(flag){				
				document.getElementById(prodId + "_wish").className = arrButs[tabDef+"Images"].classIn;
			}else{
				tabContent = tabContentOld;
			}
						
			if(rootElement.getElementsByTagName("product")){
				var recAddedProducts = rootElement.getElementsByTagName("product");
				bodyContent += "<div class=\"conConfirmVall\"><a href=\"" + viewAllWishlist + "\">Go to Wish List</a></div>";
				bodyContent += "<div class=\"hrline\"><hr /></div>";				
				for(var j=0; j < recAddedProducts.length; j++){
					if ( j == 0)
						bodyContent += "<div class=\"otherTxt\">Other recently added titles:</div>";
					var recAddedProdId = recAddedProducts[j].getElementsByTagName("product_id")[0].firstChild.nodeValue;
					var recAddedTitle = recAddedProducts[j].getElementsByTagName("title")[0].firstChild.nodeValue;							
					bodyContent += "<div class=\"recAddedTitle\"><a href=\"" + prodDetailUrl + "&productID=" + recAddedProdId + "\">" + recAddedTitle + "</a></div>";
					bodyContent += "<div class=\"recAddCart\">" + "<a class=\"cart4914\" src=\"/clear.gif\" onclick=\"javascript:addBookToCart('"+ recAddedProdId +"','','FROM_WISH_LIST','');return false;\" href=#>Add To Cart</a>" + "</div>";
					bodyContent += "<div style=\"clear:both\"></div>";
				}				
			}
			
			eval("popup_wish").populateCustomized("greenPopupTabContent", tabContent, "GreentempTitle", titleContent, "greenPopupBodyContent", bodyContent);
			eval("popup_wish").refreshCustomizedPopUp();	
		}	
	}
	
	
	function addBookToCart(prodId, extraParams, from, size){
		
		currProdId = prodId;
		currOper = "CART";
		if(extraParams != null && extraParams != "" && extraParams == "recom=yes&loomia_rx=1"){
			extraParams = "&" + extraParams;
			var loomiapid = prodId.substring(4,prodId.length);
			L_VARS.guid= loomiapid;
			loomiaclicklink = loomiaclicklink.replace('item_guid', loomiapid);
			recordLoomia(loomiapid);
		}else{
			extraParams = "";
		}
		
		var realProdId = prodId;
		var prefix = "";
		if(prodId.indexOf("-") >= 0){
			realProdId = prodId.substring(prodId.indexOf("-")+1, prodId.length);
			prefix = prodId.substring(0, prodId.indexOf("-"));
		}		
			
		var tempAddToCartUrl = addToCartUrl;
		if(tempAddToCartUrl.indexOf("?")>0){
			tempAddToCartUrl += "&productID=" + realProdId + "&pre=" + prefix + "&t=" + new Date();;
		}else{
			tempAddToCartUrl += "?productID=" + realProdId + "&pre=" + prefix + "&t=" + new Date();;
		}
		if(from == "FROM_WISH_LIST"){
			requestFrom = "WISH_LIST_POPUP";
			document.getElementById("greenConfirmMsg").innerHTML = "Adding...";			
		}else{
			popup_cart = new PopupWindow("orangeTabbedPopup");			
			popup(prodId, "CART", 1, -5);
			requestFrom = "";
			setNewTabStyle(prodId, "CART", size);
		}			
		
		sendRequest(tempAddToCartUrl,ajaxCartResponseHandler);			
	}

	/* function to record the loomia click on recommendation*/
		
		function recordLoomia(loomia_pid){			
			try{
			//alert(loomiaclicklink);
			var loomia_date=new Date();			
			var loomia_value = loomia_date.getMonth()+ 1 + "/" + loomia_date.getDate() + "/" +  loomia_date.getFullYear() + " " + loomia_date.getHours() + ":" + loomia_date.getMinutes();
			createCookie(loomia_pid,loomia_value,2);
			sendRequest(loomiaclicklink);			
			
			}catch(err){
				//alert("loomia error:" + err);
			}

		}
	/* ends */

	function ajaxCartResponseHandler(req){		
	    	if(req.responseXML){		    
	    		updateModularCart(req.responseXML);
	    		if(requestFrom == "WISH_LIST_POPUP")
	    			updateWishCartPopUp(req.responseXML);
	    		else
	    			updateCartPopUp(req.responseXML);
		}		
	}
	
	function updateCartPopUp(responseXML){		
		var rootElement = responseXML.getElementsByTagName("cart")[0];		    		
		var prodId = rootElement.getElementsByTagName("test_product")[0].firstChild.nodeValue;    
		var message = rootElement.getElementsByTagName("message")[0].firstChild.nodeValue; 
		
		var tabContentNew = "<img src=\"/clear.gif\" class=\"" + arrButs[tabDef+"Images"].classIn + " " + arrButs[tabDef+"Images"].styName + "\" />";
		var tabContentOld = "<img src=\"/clear.gif\" class=\"" + arrButs[tabDef+"Images"].classAdd + " " + arrButs[tabDef+"Images"].styName + "\" />";
		var tabContent = tabContentNew;
		var titleContent = "";
		var bodyContent = "";
		if(currProdId == prodId && currOper == "CART"){
			if(message == "IN_CART"){
				bodyContent += "<div class=\"conConfirmMsg\">This title has already been added to your cart.</div>";				
				document.getElementById(prodId + "_cart").className = arrButs[tabDef+"Images"].classIn;				
			}else if(message == "IN_LIBRARY"){
				bodyContent += "<div class=\"conConfirmMsg\">This title has already been purchased.</div>";
				tabContent = tabContentOld;
			}else if(message == "GEO_RIGHTS_ERROR"){
				bodyContent += "<div class=\"conConfirmMsg\">We are not authorized to sell this item to your geographic location.</div>";
				tabContent = tabContentOld;
			}else if(message == "ADDED_TO_CART"){
				bodyContent += "<div class=\"conConfirmMsg\">This title has been added to your cart.</div>";				
				document.getElementById(prodId + "_cart").className = arrButs[tabDef+"Images"].classIn;
			}else if(message == "BASKET_ERROR_DUPLICATE_PURCHASE"){
				bodyContent += "<div class=\"conConfirmMsg\">This title has already been Purchased.</div>";			
				tabContent = tabContentOld;
			}else{			
				bodyContent += "<div class=\"conConfirmMsg\">Unknown Error.</div>";			
				tabContent = tabContentOld;
			}		
			bodyContent += "<div class=\"conConfirmVall\"><a href=\"" + checkoutUrl + "\">View Cart</a></div>";
			eval("popup_cart").populateCustomized("orangePopupTabContent", tabContent, "OrangetempTitle", titleContent, "orangePopupBodyContent", bodyContent);
			eval("popup_cart").refreshCustomizedPopUp();
		}	
	}
	function updateWishCartPopUp(responseXML){
		var rootElement = responseXML.getElementsByTagName("cart")[0];		    		
		var prodId = rootElement.getElementsByTagName("test_product")[0].firstChild.nodeValue;    
		var message = rootElement.getElementsByTagName("message")[0].firstChild.nodeValue; 
		if(currProdId == prodId && currOper == "CART"){
			if(message == "IN_CART"){
				document.getElementById("greenConfirmMsg").innerHTML = "This title has already been added to your Cart.";
			}else if(message == "IN_LIBRARY"){
				document.getElementById("greenConfirmMsg").innerHTML = "This title has already been Purchased.";
			}else if(message == "ADDED_TO_CART"){
				document.getElementById("greenConfirmMsg").innerHTML = "This title has been added to your Cart.";
			}else if(message == "BASKET_ERROR_DUPLICATE_PURCHASE"){
				document.getElementById("greenConfirmMsg").innerHTML = "This title has already been Purchased.";
			}else{
				document.getElementById("greenConfirmMsg").innerHTML = "Unknown Error.";
			}	
		}	
	}
	
	function updateModularCart(responseXML){
		var rootElement = responseXML.getElementsByTagName("cart")[0];		    		
/*    		var prodNames = rootElement.getElementsByTagName("name");
    		var x=0;    		
    		if(prodNames.length > 0){
    			document.getElementById("div_shopCartItems").innerHTML = "";
	    		for(; x < prodNames.length; x++){
	    			var prodName = prodNames[x].firstChild.nodeValue;
	    			document.getElementById("div_shopCartItems").innerHTML += "<span class=\"cartItem\">" + prodName + "</span><br />";		    			
	    		}
	    		if(x == 0)
	    			x = "empty"
	    		document.getElementById("div_shopCartTitle").innerHTML = "<img width=\"58\" height=\"22\" alt=\"Cart\" src=\"/images/everest/layout/hdr_cart_" + (x) + ".gif\"/>"; 

	    		if(!document.getElementById("div_ShopCartCheckOut"))
				document.getElementById("div_shopCart").innerHTML += "<div id=\"div_ShopCartCheckOut\"><a href=\"" + checkoutUrl + "\"><img width=\"157\" height=\"10\" src=\"/images/everest/btn/btn_checkout.gif\"/></a></div>";
*/				
				var itemCount = rootElement.getElementsByTagName("item_count")[0].firstChild.nodeValue;
				if(document.getElementById("div_shopCartItems")){
					if(itemCount == 1){
						document.getElementById("div_shopCartItems").innerHTML = "(" + itemCount + " item)" ;
					}else{
						document.getElementById("div_shopCartItems").innerHTML = "(" + itemCount + " items)";
					}
				}
		/*}*/
	}
	
	function setNewTabStyle(prodId, type, size){		
		if(type == "CART"){
			if(size == "89x20"){
				tabDef = "Cart8020";
			}else if(size == "46x16"){
				tabDef = "Cart4616";
			}
			document.getElementById("orangePopupTabContent").className = "popupTabContent " + arrButs[tabDef+"Images"].tabImageClass; 
		}else if(type == "WISH"){
			if(size == "89x20"){
				tabDef = "Wish8020";
			}else if(size == "46x16"){
				tabDef = "Wish4616";
			}
			document.getElementById("greenPopupTabContent").className = "popupTabContent " + arrButs[tabDef+"Images"].tabImageClass;
		}
		
	}	
	
	//other js funcns	 
	
	function myTip(popUpid){		
		TagToTip(popUpid, FADEIN,200, BORDERWIDTH,'0',PADDING ,'0', BGIMG, '/images/everest/layout/audible_newstyle/1x550_gradientbg.jpg');
	}	
	
	//sample player funcns
	var ap_instances = new Array();
	function ap_stopAll(playerID) {
		for(var i = 0;i<ap_instances.length;i++) {
			try {
				if(ap_instances[i] != playerID) {
				  document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
				} else {
				  document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
				}
			} catch( errorObject ) {
				// stop any errors
			}
		}
	}

	function ap_registerPlayers() {
		var objectID;
		var objectTags = document.getElementsByTagName("object");
		for(var i=0;i<objectTags.length;i++) {
			objectID = objectTags[i].id;
			if(objectID.indexOf("audioplayer") == 0) {
				ap_instances[i] = objectID.substring(11, objectID.length);
			}
		}
	}

	var ap_clearID = setInterval( ap_registerPlayers, 1000 );
	//end sample player funcns
	
	
	
	//AJAX UTILITIES
	
	function sendRequest(url,callback,postData) {
		var req = createXMLHTTPObject();
		if (!req) return;
		var method = (postData) ? "POST" : "GET";
		req.open(method,url,true);
		req.setRequestHeader('User-Agent','XMLHTTP/1.0');
		if (postData)
			req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		req.onreadystatechange = function () {
			if (req.readyState != 4) return;
			if (req.status != 200 && req.status != 304) {
				//alert('HTTP error ' + req.status);
				return;
			}
			callback(req);
		}
		if (req.readyState == 4) return;
		req.send(postData);
	}
	
	var XMLHttpFactories = [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];
	
	function createXMLHTTPObject() {
		var xmlhttp = false;
		for (var i=0;i<XMLHttpFactories.length;i++) {
			try {
				xmlhttp = XMLHttpFactories[i]();
			}
			catch (e) {
				continue;
			}
			break;
		}
		return xmlhttp;
	}
	
	//cookie utilities
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

	