jQuery(document).ready(function(){ 
  jQuery('td.product-top').each(function(i) {        
    tdID = jQuery(this).attr("id").substring(11,16);    
    jQuery('#div_producttop_'+tdID).append("<a href='javascript:updateOverlay("+tdID+")' id='link_quickview_"+tdID+"' class='link_quickview'>Quick View</a>");   
  });
  
  if(addToCartOptions["hero"]){
    tdID = jQuery('#product-hero-top').attr("title");
    jQuery('#div_producttop_'+tdID).append("<a href='javascript:updateOverlay("+tdID+")' id='link_quickview_"+tdID+"' class='link_quickview'>Quick View</a>");
    //console.log(' Hero :'+ tdID);
  }

  if (browserIsIE6) {
    jQuery('td.productrangesCell').bind("mouseenter", function(){
      ID = jQuery(this).attr("id").substring(11,16);
      jQuery('#link_quickview_'+ID).css('display','block');
    }).bind("mouseleave", function(){
      jQuery('#link_quickview_'+ID).css('display','none');
    });
  }

});      

function closeQuickView(speed){
  jQuery('#draggable').fadeOut(speed);
}

function updateOverlay(product_id){  
  jQuery('#draggable').load('/shop/page-product_ajax/action-product.show_quickview/product_id-'+product_id,{},reBindSwatches());         
  jQuery('#draggable').fadeIn("slow");
  
  // Since psoition:fixed doesnt work in IE6
  if (browserIsIE6) {
    var newOffset = jQuery('#div_producttop_' + product_id).offset();
    jQuery('#draggable').css("top", newOffset.top + 'px');
  }
  
}

/**
 * Select Swatch
 */
function selectId(value){
  if (value > 1) {
    resetAllSwatches();
    jQuery('#variation_swatch_box_' + value).addClass('selected');
  }else{
    // code to alert the user that they are trying to select a sold-out variety
  }  
}

/**
 * Reset Swatches
 */
  function resetAllSwatches(){
    jQuery('#variation_swatches ul li').removeClass('selected');    
  }
  
/**
 * Product Size Swatches
 */  
  function reBindSwatches(){
  
  jQuery(this).oneTime(500, "reBind", function(){                

    if (jQuery('#variation_swatches').hasClass('active')) {
    
      var lowestPrice = jQuery('#variation_display_price').text();
      
      jQuery('#variation_swatches ul li').hover(function(){
        var thisValue = jQuery(this).children("label").attr("title");
        var thisPrice = jQuery(this).children("label").children("span.price").text();
        jQuery('#variation_swatches_label_current').text(thisValue);
        jQuery('#variation_display_price').text(thisPrice);
      }, function(){
        selectedCell = jQuery('#variation_swatches ul li.selected label').attr("title");
        if (selectedCell != null) {
          jQuery('#variation_swatches_label_current').text(selectedCell);
          selectedPrice = jQuery('#variation_swatches ul li.selected label span.price').text();
          jQuery('#variation_display_price').text(selectedPrice);
        }
        else {
          jQuery('#variation_swatches_label_current').text('');
          jQuery('#variation_display_price').text(lowestPrice);
        }
      });
    };
  });
 
  }
  
