jQuery(function () {
  initGallery();
});
jQuery(window).bind('load', function(){
  initPageHeight();
});

function initGallery(){
  jQuery('div#productImage a:not([href*=#]), div#recipeImage a').ivPrepare();
  var noImage = jQuery('div#productImage a[href*=#]').css('cursor', 'default').click(function(){
  return false;
  });
  if(noImage[0]){
    jQuery('div#productImage .enlargeIcon').remove();
  }
}

function initPageHeight(){
  var midCon = jQuery('#MidCon'),
      innerleft = jQuery('#innerleft'),
      lastBox = jQuery('#right_Body_Pannel .box:last, #listItems div.listItem:last');

  if(midCon[0] || innerleft[0]){
    var leftHeight = innerleft.height(),
        midPadding = midCon[0] ? midCon.css('paddingTop').parseToInt(10) + midCon.css('paddingBottom').parseToInt(10) : 0,
        midHeight = midCon[0] ? midCon.height() : 0,
        midFullHeight = midHeight + midPadding,
        rightHeight = lastBox[0] ? lastBox.position().top + lastBox.outerHeight() - 2 : 0,
        theHeight = midFullHeight; //Mid is higher

    if(leftHeight > midFullHeight && leftHeight > rightHeight){//Left is higher
      theHeight = leftHeight;
    }else if(rightHeight > midFullHeight && rightHeight > leftHeight){//Right is higher
      theHeight = rightHeight;
    }
    midCon.height(theHeight - midPadding);
    innerleft.height(theHeight);
  }
}

jQuery('#listItems .listItem').live('click', function(){
  var productGroup = jQuery(this),
      link = productGroup.find('a').attr('href');
  window.location.href = link;
});

jQuery('img.enlargeIcon').live('click', function(){
  jQuery(this).parent().find('a').click();
});

/* SEARCH */
/*function initSearch(){
  jQuery('div#searchBox input#searchBtn').live('click', function(){
    search(jQuery(this).closest('#searchBox').find('input#searchField').val());
    return false;
  });
  jQuery('div#searchBox input#searchField').live('keypress', function(e){

    if(e.which === 13){
      search(jQuery(this).val());
      return false;
    }
  });
}
initSearch();
function search(word){
  window.location.href = '/da/soeg.aspx?q=' + escape(word);
}*/



