var libraryImageBase="";
var linkURLBase="";
var catelogImageBase="";

var quickviewlink = "";
var picker = null;
var miniCart = null;
var tipImg = "";
var qvOpen = false;
	
addLoadEvent(function() {
	minicartConstants.easyViewerAddToBag = false;

	quickviewlink = $('quickViewURL').href;
	linkURLBase = quickviewlink.replace("Product-ShowQuickView","");
	libraryImageBase = $('defaultImgURL').src.replace("images/spacer.gif","");
	catelogImageBase = libraryImageBase.replace('Library', 'catalog');
	tipImg='<img src="'+libraryImageBase+'images/nw_icon_quickView.gif" alt="" align="top" />';

var jsonImages = $('editorialJSON').value;
objImages.init(jsonImages, libraryImageBase, 12, 8,  false);
});
   
Effect.OpenUp = function(element) {
     element = $(element);
     $('slider').className="normal";
    
     new Effect.BlindDown(element, { duration: .4, afterFinish: function(effect) 
		{$('tabLink').className="opened"; 
		}});
     
 }

 Effect.CloseDown = function(element, mainImg) {

     element = $(element);
     if (mainImg != null)
     {
	objImages.setLargeImage(mainImg);
	}
	//	$('mainImage').src=mainImg;
     new Effect.BlindUp(element, { duration: .4, afterFinish: function(effect) 
		{$('slider').className="scrunched";
		
		$('tabLink').className="closed";
		
		}});
 }

Effect.Combo = function(element, mainImg, x) {
var z = arguments;
     element = $(element);
     if(element.style.display == 'none') { 
          new Effect.OpenUp(element, arguments[2] || {}); 
     }else { 
          new Effect.CloseDown(element, x, arguments[2] || {}); 
     }
 }
 
		function setMousePos(event){
			mXPos = Event.pointerX(event);
			mYPos = Event.pointerY(event);
		}

		function getProductContent(productID)
		{
			//productID = 22957176;
			if(qvOpen)
				cleanqv();
			if (BrowserDetect.browser == "Safari" && BrowserDetect.version < 500)
			{
				var url = linkURLBase+'Product-Show?pid=' + productID;
				window.open(url, "windowName", "width=800, height=650, resizable=yes, status=no, scrollbars=yes");
				//window.open("browse/product.s?productId="+productID,"windowName", "width=800,height=650, resizable=yes, status=yes,location=no, scrollbars=yes");
				return;
			}

			currentProdLink = linkURLBase+'Product-Show?pid=' + productID;
			 var url = quickviewlink+'?pid='+productID;
			var result  ='';
			$('ajax_loading').style.display     = "block";
			$('productContent').style.display     = "none";
			var request = new Ajax.Updater('productContent', url, 
			{ 
			  method:'get',
			  evalScripts:false,
			  onSuccess: function(transport)
			  {
				if(transport.responseText.indexOf('<input type="hidden" value="errorPage"/>') != -1)
				{
					setTimeout("showSoldOutMsg()",1000);
				} 
				if(transport.responseText.indexOf('We are sorry!') != -1)
				{
					setTimeout("showSoldOutMsg()",1000);
				}
				else
				{
					setTimeout("initSkuPicker()",1000);
				}
			  },
			  onFailure: function()
			  {
			   // do nothing for now
			  }
			}
		  );
		 }
		function closeQuickview() {
			cleanqv();
		}

		function cleanqv() {
			$('productContent').innerHTML = "";
			$('productContent').style.display = "none";
			
			miniCart = null;
			
			picker = null;
			closeDiv = null;
			closeAnchor = null;
			graphicDiv = null;
			graphicAnchor = null;

			qvOpen = false;
		}
		function initSkuPicker()
		{
			$('quickViewRight').insertBefore($('quickViewDesc'),$('cartControls'));
			try{
				picker = new skuPicker(eval($('lookupTable').value)[0],'','quickView',eval($('imagesLookupTable').value)[0], true);
				picker.init();
				miniCart.initialize();
			} catch(e) {
				alert("Problem Creating Skupicker and Minicart. Problem: "+e.description);
			}

			qvOpen = true;
			var closeDiv = $('quickViewClose');
			var closeAnchor = closeDiv.getElementsByTagName('a');
			if(closeAnchor[0])
				closeAnchor[0].href = "javascript:closeQuickview();"

			var graphicDiv = $('quickViewImgHolder');
			var graphicAnchor = graphicDiv.getElementsByTagName('a');
			if(graphicAnchor[0])
				graphicAnchor[0].href = currentProdLink;
			$('ajax_loading').style.display = "none";
			$('productContent').style.display = "block";
		}
		function showSoldOutMsg()
		{
			$('productContent').innerHTML = '<div style="float:left;background-color:#FAF6EB;border:8px solid #EFE7DA;width:300px;"><div style="padding:20px;float:left;font-size:14pt;">So Hot, It&#39;s Sold Out</div><div id="quickViewClose"><a href="javascript:closeQuickview();" class="evQuickViewCloseHandle"><img alt="Close" src="/on/demandware.static/Sites-jonesny-Site/-/default/v1221223098384/images/cart/close_icon.gif"/></a></div></div>';
			$('ajax_loading').style.display = "none";
			$('productContent').style.display = "block";
		}
